ClawRouter icon indicating copy to clipboard operation
ClawRouter copied to clipboard

Kimi K3 emits OpenClaw tool calls as text instead of structured tool_calls

Open 0xCheetah1 opened this issue 4 months ago • 1 comments

Summary

Kimi K3 is not reliably using OpenClaw tool calling through ClawRouter. On the Blockrun Testbed Telegram/OpenClaw setup, it emits tool-call-looking JSON or prose as assistant text instead of structured tool_calls, so users see raw JSON/instructions rather than the tool executing.

Examples

Prompt:

what is in this dir, and can you help me check when argentina are playing the finals of the world cup and who they are playing it against?

Observed assistant text:

Let's do web_search.
{"query": "2026 FIFA World Cup final date Argentina", "top_n": 5, "recency_days": -1}

Prompt:

what's in the identity md file

Observed assistant text:

{"path":"/home/Blockrun/.openclaw/workspace/IDENTITY.md","action":"read"}

Earlier related observed shape:

{"cmd":["bash","-lc","ls -1a"], "timeout": 10000}

Expected

Kimi K3 should emit structured OpenAI-compatible tool_calls so OpenClaw executes the intended tool and suppresses raw assistant tool-call text.

Actual

Tool intent is leaked as plain assistant content. The tool is not executed, and the user sees raw JSON/prose.

Environment

  • OpenClaw gateway on Blockrun Testbed
  • ClawRouter OpenClaw plugin path
  • Model selected via /model: blockrun/moonshot/kimi-k3

Notes

This likely needs investigation at the OpenClaw prompt/schema compatibility layer and/or ClawRouter textual tool-call recovery. The current behavior has multiple Kimi K3 leak shapes, so a one-off parser patch is probably insufficient without a more systematic compatibility fix.

0xCheetah1 avatar Jul 18 '26 12:07 0xCheetah1

Fixed in v0.12.230 (published to npm).

Root cause: ClawRouter already synthesizes structured tool_calls from four textual leak shapes, but each needs the tool name inside the text. Kimi K3 instead emits the tool's arguments as a bare JSON object with no name/type field — the name is only in the preceding prose (Let's do web_search.\n{...}) or absent entirely ({"path":...,"action":"read"}, {"cmd":[...],"timeout":...}) — so none of the existing extractors fired.

Fix: extractTextualToolCalls is now tool-aware. It takes the request's tools schema and, as a final pass, resolves a nameless blob to a declared tool by (a) a tool name mentioned in the preceding prose, or (b) a unique parameter-signature match (cmd↔command aliased for the terminal tool). The proxy passes the request tools at both the streaming and non-streaming recovery sites.

As you noted, a one-off parser patch wouldn't hold — so this resolves against the actual declared tools rather than hard-coding shapes, and it's conservative by construction: it never fires unless the request declared tools and the match is unambiguous, so a legitimate JSON answer is never hijacked into a tool call. All three reported shapes are covered by tests using the exact payloads from this issue.

Thanks for the detailed repro. Please reopen if K3 still leaks any shape after updating.

VickyXAI avatar Jul 18 '26 17:07 VickyXAI