feat: Introduce unified tooling system for plugins and MCP

- 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.
This commit is contained in:
DrSmoothl
2026-03-30 23:11:56 +08:00
parent 898b693fe0
commit dc2bf02a42
35 changed files with 1663 additions and 6756 deletions

View File

@@ -0,0 +1,48 @@
"""插件运行时工具 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 不持有独立资源。
"""