CMDC.Plugin.Builtin.PatchToolCalls (cmdc v0.5.0)

Copy Markdown View Source

P1 悬空工具调用修复插件。

before_request 事件中扫描消息序列,检测无对应 tool_result 的 assistant tool_calls(悬空调用),并通过 emit {:synthetic_tool_results, list} 通知 Agent 追加合成响应,确保消息序列在发送给 LLM 前的有效性。

与内置 Repair 模块的关系

层次模块时机触发
L1 内部Agent 内建修复器run_turn 开始自动(每 turn)
L2 PluginPatchToolCallsbefore_requestPlugin Pipeline

内建修复器处理 Agent 内部的孤立调用(含重定位、去重);PatchToolCalls 作为 Plugin 层的额外保护,可自定义合成消息内容,并在 Pipeline 中由用户显式启用。

emit 事件协议

  • {:synthetic_tool_results, [{call_id, content, is_error}]} — 需补充的合成结果列表

Agent 收到此 emit 后将为每个 call_id 追加 tool_result 消息到 state.messages

配置

{CMDC.Plugin.Builtin.PatchToolCalls,
  synthetic_content: "Error: Tool call was interrupted or not executed.",
  is_error: true
}