feat: add configurable client tools and photo input

This commit is contained in:
Xin Wang
2026-07-30 19:06:03 +08:00
parent 510a277b5a
commit 913435785e
24 changed files with 1802 additions and 139 deletions

View File

@@ -14,6 +14,8 @@ from services.runtime_variables import (
DynamicVariableStore,
value_at_path,
)
from services.client_tools import ClientToolError, ClientToolPort
from services.tool_policy import policy_for_tool
from services.tools import McpClientError, McpToolClient
@@ -29,9 +31,14 @@ class ToolExecutor:
store: DynamicVariableStore,
*,
mcp_client: McpToolClient | None = None,
client_tools: ClientToolPort | None = None,
):
self.store = store
self._mcp_client = mcp_client or McpToolClient()
self._client_tools = client_tools
def set_client_tools(self, client_tools: ClientToolPort | None) -> None:
self._client_tools = client_tools
def register_secrets(self, tool: RuntimeTool) -> None:
dynamic = (tool.secrets or {}).get("dynamic_variables") or {}
@@ -78,8 +85,12 @@ class ToolExecutor:
result = await self._execute_http(tool, normalized_arguments)
elif tool.type == "mcp":
result = await self._execute_mcp(tool, normalized_arguments)
elif tool.type == "client":
result = await self._execute_client(tool, normalized_arguments)
else:
raise ToolExecutionError(f"不支持工具类型: {tool.type}")
if result.get("status") != "ok":
return {**result, "updated_variables": []}
return self._apply_result_assignments(
tool,
result,
@@ -187,6 +198,25 @@ class ToolExecutor:
raise ToolExecutionError(str(exc)) from exc
return {"status": "ok", "data": payload}
async def _execute_client(
self,
tool: RuntimeTool,
arguments: dict[str, Any],
) -> dict[str, Any]:
if self._client_tools is None:
raise ToolExecutionError("当前运行模式不支持客户端工具")
config = (tool.definition or {}).get("config") or {}
policy = policy_for_tool(tool)
try:
return await self._client_tools.call(
tool.function_name,
arguments,
timeout_seconds=float(config.get("timeout_seconds") or 3),
wait_for_response=policy.wait_for_response,
)
except ClientToolError as exc:
raise ToolExecutionError(str(exc)) from exc
def _apply_result_assignments(
self,
tool: RuntimeTool,