diff --git a/src/plugin_system/base/base_tool.py b/src/plugin_system/base/base_tool.py index e73562f18..dc6147b9f 100644 --- a/src/plugin_system/base/base_tool.py +++ b/src/plugin_system/base/base_tool.py @@ -1,7 +1,7 @@ from typing import List, Any, Optional, Type from src.common.logger import get_logger from rich.traceback import install -from src.plugin_system.base.component_types import ToolInfo +from src.plugin_system.base.component_types import ComponentType, ToolInfo install(extra_lines=3) logger = get_logger("base_tool") @@ -44,14 +44,15 @@ class BaseTool: raise NotImplementedError(f"工具类 {cls.__name__} 必须定义 name 和 description 属性") return ToolInfo( - tool_name=cls.name, + name=cls.name, tool_description=cls.description, available_for_llm=cls.available_for_llm, - tool_parameters=cls.parameters + tool_parameters=cls.parameters, + component_type=ComponentType.TOOL, ) # 工具参数定义,子类必须重写 - async def execute(self, **function_args: dict[str, Any]) -> dict[str, Any]: + async def execute(self, function_args: dict[str, Any]) -> dict[str, Any]: """执行工具函数 Args: diff --git a/src/plugin_system/base/component_types.py b/src/plugin_system/base/component_types.py index e8cd109b7..cbbe959fa 100644 --- a/src/plugin_system/base/component_types.py +++ b/src/plugin_system/base/component_types.py @@ -150,7 +150,6 @@ class CommandInfo(ComponentInfo): class ToolInfo(ComponentInfo): """工具组件信息""" - tool_name: str = "" # 工具名称 tool_parameters: Dict[str, Any] = field(default_factory=dict) # 工具参数定义 available_for_llm: bool = True # 是否可供LLM使用 tool_description: str = "" # 工具描述 diff --git a/src/plugin_system/core/component_registry.py b/src/plugin_system/core/component_registry.py index 7d7ab34ad..ef28f7d07 100644 --- a/src/plugin_system/core/component_registry.py +++ b/src/plugin_system/core/component_registry.py @@ -198,7 +198,9 @@ class ComponentRegistry: # 如果是llm可用的且启用的工具,添加到 llm可用工具列表 if tool_info.available_for_llm and tool_info.enabled: self._llm_available_tools[tool_name] = tool_class - + + return True + def _register_event_handler_component( self, handler_info: EventHandlerInfo, handler_class: Type[BaseEventHandler] ) -> bool: diff --git a/src/plugin_system/core/plugin_manager.py b/src/plugin_system/core/plugin_manager.py index 98bce4bdb..527270ee3 100644 --- a/src/plugin_system/core/plugin_manager.py +++ b/src/plugin_system/core/plugin_manager.py @@ -345,6 +345,7 @@ class PluginManager: stats = component_registry.get_registry_stats() action_count = stats.get("action_components", 0) command_count = stats.get("command_components", 0) + tool_count = stats.get("tool_components", 0) event_handler_count = stats.get("event_handlers", 0) total_components = stats.get("total_components", 0) @@ -352,7 +353,7 @@ class PluginManager: if total_registered > 0: logger.info("🎉 插件系统加载完成!") logger.info( - f"📊 总览: {total_registered}个插件, {total_components}个组件 (Action: {action_count}, Command: {command_count}, EventHandler: {event_handler_count})" + f"📊 总览: {total_registered}个插件, {total_components}个组件 (Action: {action_count}, Command: {command_count}, Tool: {tool_count}, EventHandler: {event_handler_count})" ) # 显示详细的插件列表 @@ -387,6 +388,9 @@ class PluginManager: command_components = [ c for c in plugin_info.components if c.component_type == ComponentType.COMMAND ] + tool_components = [ + c for c in plugin_info.components if c.component_type == ComponentType.TOOL + ] event_handler_components = [ c for c in plugin_info.components if c.component_type == ComponentType.EVENT_HANDLER ] @@ -398,7 +402,9 @@ class PluginManager: if command_components: command_names = [c.name for c in command_components] logger.info(f" ⚡ Command组件: {', '.join(command_names)}") - + if tool_components: + tool_names = [c.name for c in tool_components] + logger.info(f" 🛠️ Tool组件: {', '.join(tool_names)}") if event_handler_components: event_handler_names = [c.name for c in event_handler_components] logger.info(f" 📢 EventHandler组件: {', '.join(event_handler_names)}")