tooluniverse.tool_registry 模块

简化的工具注册表,用于自动工具发现和注册。

tooluniverse.tool_registry.mark_tool_unavailable(tool_name, error, module=None)[源代码]

记录工具故障。

tooluniverse.tool_registry.get_tool_errors()[源代码]

获取所有工具错误。

tooluniverse.tool_registry.register_tool(tool_type_name=None, config=None)[源代码]

用于自动注册工具类及其配置的装饰器。

用法:

@register_tool(‘CustomToolName’, config={…}) class 我的工具:

通过

tooluniverse.tool_registry.register_external_tool(tool_name, tool_class)[源代码]

允许外部注册工具类。

tooluniverse.tool_registry.register_config(tool_type_name, config)[源代码]

为工具类型注册配置。

tooluniverse.tool_registry.get_tool_registry()[源代码]

获取当前工具注册表的副本。

tooluniverse.tool_registry.get_config_registry()[源代码]

获取当前配置注册表的副本。

tooluniverse.tool_registry.register_tool_configs(configs)[源代码]

Register a list of tool configs from a sub-package (e.g. tooluniverse-circuit).

Sub-package __init__.py files call this to make their JSON configs discoverable by ToolUniverse.load_tools() without requiring any entries in default_config.py.

参数:

configs (list) – List of tool config dicts, each containing at least a name key.

tooluniverse.tool_registry.get_list_config_registry()[源代码]

Return the flat list of configs registered by sub-packages.

tooluniverse.tool_registry.clear_lazy_cache()[源代码]

Clear the module-level lazy import cache.

Built-in tool modules (in src/tooluniverse/tools/) are cached after their first import. Call this function in development environments when you have edited a built-in tool module and want the changes to take effect without restarting the process. After calling this, the next access to the tool will re-import its module from disk.

Note: this does NOT affect workspace user tool files; those are handled separately via mtime tracking in _import_user_python_tools().

Example:

from tooluniverse.tool_registry import clear_lazy_cache
clear_lazy_cache()
tu.refresh_tools()
tooluniverse.tool_registry.lazy_import_tool(tool_name)[源代码]

通过工具名称懒加载导入,而无需导入所有工具模块。仅导入包含所请求工具的特定模块。

tooluniverse.tool_registry.build_lazy_registry(package_name=None)[源代码]

Build a mapping of tool names to module names. Prioritizes pre-computed static registry (for bundles/frozen envs). Falls back to AST analysis if static registry is missing.

tooluniverse.tool_registry.reset_plugin_discovery()[源代码]

Clear the set of already-discovered plugin names.

Call this before build_lazy_registry() (or refresh_tools()) when a new plugin package has been installed in the current process and you want _discover_entry_point_plugins() to pick it up without restarting.

tooluniverse.tool_registry.auto_discover_tools(package_name=None, lazy=True)[源代码]

自动发现并导入所有工具模块。如果设置为 lazy=True,则仅构建映射而不导入任何模块。如果设置为 lazy=False,则会立即导入所有工具模块。

tooluniverse.tool_registry.get_tool_class_lazy(tool_name)[源代码]

通过名称获取工具类,尽可能使用延迟加载。仅导入所需的特定模块,而非所有模块。