- Added a new `tooling` module to define a unified model for tool declarations, invocations, and execution results, facilitating compatibility between plugins, legacy actions, and MCP tools. - Implemented `ToolProvider` interface for various tool providers including built-in tools, MCP tools, and plugin runtime tools. - Enhanced `MCPManager` and `MCPConnection` to support unified tool invocation and execution results. - Updated `ComponentRegistry` and related classes to accommodate the new tool specifications and descriptions. - Refactored existing components to utilize the new tooling system, ensuring backward compatibility with legacy actions. - Improved error handling and logging for tool invocations across different providers.
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""插件运行时工具 Provider。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Optional
|
|
|
|
from src.core.tooling import ToolExecutionContext, ToolExecutionResult, ToolInvocation, ToolProvider, ToolSpec
|
|
|
|
from .component_query import component_query_service
|
|
|
|
|
|
class PluginToolProvider(ToolProvider):
|
|
"""将插件 Tool 与兼容旧 Action 暴露为统一工具 Provider。"""
|
|
|
|
provider_name = "plugin_runtime"
|
|
provider_type = "plugin"
|
|
|
|
async def list_tools(self) -> list[ToolSpec]:
|
|
"""列出插件运行时当前可用的工具声明。"""
|
|
|
|
return list(component_query_service.get_llm_available_tool_specs().values())
|
|
|
|
async def invoke(
|
|
self,
|
|
invocation: ToolInvocation,
|
|
context: Optional[ToolExecutionContext] = None,
|
|
) -> ToolExecutionResult:
|
|
"""执行插件工具或兼容旧 Action 的工具调用。
|
|
|
|
Args:
|
|
invocation: 工具调用请求。
|
|
context: 执行上下文。
|
|
|
|
Returns:
|
|
ToolExecutionResult: 工具执行结果。
|
|
"""
|
|
|
|
return await component_query_service.invoke_tool_as_tool(
|
|
invocation=invocation,
|
|
context=context,
|
|
)
|
|
|
|
async def close(self) -> None:
|
|
"""关闭 Provider。
|
|
|
|
插件运行时工具 Provider 不持有独立资源。
|
|
"""
|
|
|