fix(plugin): 修复 OpenClaw 工具调用消息格式不兼容导致的 toolResult 孤儿错误#1632
Conversation
The OpenClaw Responses API replay path only recognizes `toolCall` blocks (with `arguments` field), but the OpenViking context engine plugin was emitting `toolUse` blocks (with `input` field) from its assembled context. This mismatch caused `toolResult` orphan errors on subsequent turns after tool use. Changes: - convertToAgentMessages: emit toolCall+arguments instead of toolUse+input, matching the OpenClaw canonical format - Add canonicalizeAgentMessages() to normalize legacy/variant block formats (toolUse, functionCall, tool_call) into toolCall before sanitizeToolUseResultPairing - Add canonicalizeAssistantBlock() for per-block normalization with id/name/arguments field mapping - messageDigest: update type guard from toolUse to toolCall This preserves backward compatibility on input (old toolUse blocks are still accepted and normalized) while ensuring output always matches the current OpenClaw Responses API contract.
|
Moss seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
持续关注 |
Important
Minor
|
- Remove 'unknown' fallback for toolResult.toolName in canonicalizeAgentMessages(); preserve undefined to let downstream normalizeToolResultName() backfill from paired toolCall - Remove 'unknown' fallback for tool_name in convertToAgentMessages() structured path; only set toolName on toolResult when the value exists - Only include toolName on toolResult when present (not always) - Update test expectations: toolUse → toolCall, input → arguments - Update README/README_CN: describe canonical output format with backward-compat note
|
感谢 review,两条反馈都已在 40ac50e 中修复合并:
25 个 ut 测试全部通过。 |
问题
OpenViking 作为 OpenClaw 上下文引擎插件时,组装的上下文中工具调用块使用的是旧版
toolUse类型(带input字段),而 OpenClaw Responses API 重放路径只识别规范格式toolCall(带arguments字段),导致多轮对话中工具调用后出现toolResult孤儿错误。根因
convertToAgentMessages()输出:type: "toolUse"+input字段 → OpenClaw Responses 重放不识别toolResult消息配对失败,触发验证错误修改内容
1.
convertToAgentMessages— 输出改为规范格式toolUse+input→toolCall+argumentstoolUseBlocks→toolCallBlocks2. 新增
canonicalizeAssistantBlock()+canonicalizeAgentMessages()sanitizeToolUseResultPairing之前对 assembled context 做规范化toolUse/functionCall/tool_call→toolCallinput/toolInput→argumentstoolUseId/toolCallId→id(保留已有值)toolResult消息携带toolCallId和toolName3.
messageDigest— 类型守卫更新b.type === "toolUse"→b.type === "toolCall"向后兼容
三种旧格式输入(
toolUse、functionCall、tool_call)仍然被接受,组装时统一规范化为toolCall输出。测试验证
在运行中的 OpenClaw 实例上验证:应用修复后重新启用 OpenViking 插件,多轮对话中的工具调用不再产生孤儿错误。