Skip to content
FunCoding

Search

Search docs, Skills and MCP

工具、权限与交互事件

关联工具执行和用户请求,区分事件观察、授权响应与业务执行结果。

This page has not been translated into English yet. The original Chinese version is shown below.

工具调用、权限批准、用户问题与子代理工作会共享会话事件流。用对应 ID 关联流程,不要将“请求已发出”直接渲染为“操作已成功”。

工具生命周期

事件关键内容
tool.execution_starttoolCallId、toolName、可选 arguments,以及 MCP server/tool 名称
tool.execution_partial_result临时 partialOutput,例如命令输出块
tool.execution_progress临时 progressMessage
tool.execution_completesuccess,成功 result 或失败 error
tool.user_requested用户明确要求调用的工具及参数

成功 result 的 content 是给模型的简要结果,可能为节省 token 而截断;detailedContent 可保留完整展示内容,contents 则包含结构化文本、终端、图像、音频或资源块。

模型 assistant.message.toolRequests 内含 toolCallId、name、可选 arguments/type;type 缺省按 function,不能只根据工具名称推断调用是否完成。

权限与用户输入

请求关联字段响应入口
permission.requestedrequestId、permissionRequestrespondToPermission()
user_input.requestedrequestId、question、可选 choices/allowFreeformrespondToUserInput()
elicitation.requestedrequestId、message、requestedSchemarespondToElicitation()
exit_plan_mode.requestedrequestId、summary、planContent、actionsrespondToExitPlanMode()
external_tool.requestedrequestId、sessionId、toolCallId、toolName、argumentsrespondToExternalTool()
command.queuedrequestId、commandrespondToQueuedCommand()

这里列出方法名与事件关联,不猜测响应对象的完整 schema;使用当前语言生成类型实现。completed 事件通过同一 requestId 表示请求已解决。

permissionRequest 按 kind 区分 shell、write、read、mcp、url、memory、custom-tool。shell 包含完整命令和可能路径,write 包含文件与 diff,mcp 包含服务器、工具及 readOnly 信息;应根据请求详情决定授权。

permission.completed 的 result.kind 可能为 approved、规则拒绝、用户拒绝、无法询问且无允许规则,或内容排除策略拒绝。事件流中的完成不等于批准。

哪些交互事件是临时的

用户输入、elicitation、退出 Plan、排队命令和预算耗尽请求及其 completed 属于临时事件,恢复不能依靠日志重放它们。权限与 external tool 请求在该参考中属于持久事件,恢复时仍需正确处理请求状态。

子代理与 Skills

subagent.started、completed、failed 使用 toolCallId 关联启动工具调用,包含 agent 名称;后两者还可有模型、耗时、token 与工具次数。事件归属仍用 envelope.agentId。

subagent.selected 表示角色被选中,tools 为 null 表示全部工具;deselected 的 data 为空。skill.invoked 包含名称、路径、注入内容,以及可选 allowedTools、plugin 名称与版本。

这些日志可能携带完整指令、工具参数和输出;应用展示与保存范围应遵循自身数据策略,而不是默认把所有事件发给所有用户。