跳转至

registry

feishu.agent.bundles.registry

BundleContext dataclass

构建工具 bundle 时可用的运行时服务与产品默认值。

源代码位于: feishu/agent/bundles/registry.py
Python
@dataclass(frozen=True)
class BundleContext:
    r"""构建工具 bundle 时可用的运行时服务与产品默认值。"""

    locale: str = "zh-CN"
    timezone: str = "Asia/Shanghai"
    describe_analyzer: Any | None = None
    text_summarizer: Any | None = None
    mail_summary_max_messages: int = 10
    mail_summary_max_body_chars: int = 4000
    mail_summary_max_chars: int = 2000
    extra: dict[str, Any] = field(default_factory=dict)

Bundle

Bases: Protocol

可把一组工具注册进 feishu.agent.tools.ToolRegistry 的命名 bundle。

源代码位于: feishu/agent/bundles/registry.py
Python
class Bundle(Protocol):
    r"""可把一组工具注册进 [feishu.agent.tools.ToolRegistry][] 的命名 bundle。"""

    def register(self, registry: ToolRegistry, context: BundleContext) -> None: ...

build_tool_registry

Python
build_tool_registry(bundles: Sequence[str], context: BundleContext | None = None, *, registry: ToolRegistry | None = None) -> ToolRegistry

按已注册 bundle 名称构建运行时 feishu.agent.tools.ToolRegistry

源代码位于: feishu/agent/bundles/registry.py
Python
def build_tool_registry(
    bundles: Sequence[str],
    context: BundleContext | None = None,
    *,
    registry: ToolRegistry | None = None,
) -> ToolRegistry:
    r"""按已注册 bundle 名称构建运行时 [feishu.agent.tools.ToolRegistry][]。"""
    target = registry or ToolRegistry()
    bundle_context = context or BundleContext()
    for name in bundles:
        try:
            bundle = BUNDLES.build(name)
        except ValueError as exc:
            available = ", ".join(_available_bundle_names()) or "<none>"
            raise ValueError(f"unknown bundle {name!r}; registered bundles: {available}") from exc
        register = getattr(bundle, "register", None)
        if register is None:
            raise TypeError(f"bundle {name!r} does not define register(registry, context)")
        register(target, bundle_context)
    return target