feat(agent): human-in-the-loop approval for MCP tool calls (#1173)
Add an opt-in human approval gate so Agent runs pause before executing MCP tools that operators flag as dangerous, surface an approval card in the chat UI, and only resume after the user approves (optionally with edited args) or rejects. Backend - New mcp_tool_approvals table + repo/service to mark per-tool approval required (PG migration 000042 + sqlite init). - approval.Gate coordinates RequestAndWait / Resolve with sync.Once delivery, configurable timeout, and Redis Pub/Sub fan-out so multi- replica deployments work without sticky sessions. - MCPTool.Execute integrates the gate; uses a round-level ApprovalCtx (without the per-tool 60s timeout) for the wait, and re-derives a fresh 60s exec ctx after approval so CallTool keeps a full window. - New SSE response types (tool_approval_required / _resolved) and EventBus events plumb approval state to AgentStreamDisplay. - REST: list/set per-tool approval flag, resolve pending approval. - Configurable via agent.tool_approval_timeout_seconds (yaml) or WEKNORA_AGENT_TOOL_APPROVAL_TIMEOUT env (accepts seconds or Go duration). Frontend - MCP settings: per-tool "require approval" switch on the test panel. - Chat: ToolApprovalCard renders the pause point with editable JSON args, validation feedback, mm:ss countdown that turns warning/danger near deadline, and a resolved state that retains context. - i18n strings added for zh-CN / en-US / ko-KR / ru-RU. Docs - docs/zh/mcp-approval.md covering behavior, config, API, deployment considerations (Redis cross-instance, restart limitations).
This commit is contained in:
@@ -381,6 +381,12 @@ WEKNORA_SANDBOX_DOCKER_IMAGE=wechatopenai/weknora-sandbox:latest
|
||||
# 注:此值为全局默认值。若单个智能体在数据库中配置了独立的 llm_call_timeout,则以智能体配置为准(优先级更高)。
|
||||
# WEKNORA_AGENT_LLM_TIMEOUT=300
|
||||
|
||||
# MCP 工具人工审核等待超时(秒)(可选)
|
||||
# 当某个 MCP 工具被标记为「需人工审核」后,Agent 会暂停并等待用户确认;
|
||||
# 该值控制最长等待时间,超时视为拒绝。默认 600(10 分钟)。
|
||||
# 也支持 Go duration 写法(如 30s / 5m / 1h)。
|
||||
# WEKNORA_AGENT_TOOL_APPROVAL_TIMEOUT=600
|
||||
|
||||
# APK 镜像源设置(可选)
|
||||
APK_MIRROR_ARG=mirrors.tencent.com
|
||||
|
||||
|
||||
Reference in New Issue
Block a user