tools整合彻底完成

This commit is contained in:
UnCLAS-Prommer
2025-07-28 23:57:55 +08:00
parent 8bf7166aa4
commit af27d0dbf0
13 changed files with 189 additions and 601 deletions

View File

@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, Type
from src.plugin_system.base.base_tool import BaseTool
from src.plugin_system.base.component_types import ComponentType
@@ -6,20 +6,22 @@ from src.common.logger import get_logger
logger = get_logger("tool_api")
def get_tool_instance(tool_name: str) -> Optional[BaseTool]:
"""获取公开工具实例"""
from src.plugin_system.core import component_registry
tool_class = component_registry.get_component_class(tool_name, ComponentType.TOOL)
if not tool_class:
return None
return tool_class()
tool_class: Type[BaseTool] = component_registry.get_component_class(tool_name, ComponentType.TOOL) # type: ignore
return tool_class() if tool_class else None
def get_llm_available_tool_definitions():
from src.plugin_system.core import component_registry
"""获取LLM可用的工具定义列表
Returns:
List[Tuple[str, Dict[str, Any]]]: 工具定义列表,为[("tool_name", 定义)]
"""
from src.plugin_system.core import component_registry
llm_available_tools = component_registry.get_llm_available_tools()
return [tool_class().get_tool_definition() for tool_class in llm_available_tools.values()]
return [(name, tool_class.get_tool_definition()) for name, tool_class in llm_available_tools.items()]