-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
[Bug]: Tool calling when Moonshot / Kimi model used is broken #39603
Description
Bug type
Regression (worked before, now fails)
Summary
After updating to version c6a8ab6 from f304ca0 tool calling stopped working in Moonshot Kimi K2.5 model.
Steps to reproduce
- Configure Moonshot Kimi K2.5 model
- Invoke command requiring tool use , eg. with openclaw tui
- See tool call JSON in the agent output, no actual tool calls.
Expected behavior
Tool calls work
Actual behavior
Tool calls don't work.
OpenClaw version
Operating system
Linux
Install method
npm global
Logs, screenshots, and evidence
Investigating Mattermost channel message delivery. Reading the documentation and relevant code.json
{"read": {"path": "/home/xxx/openclaw/docs/channels/mattermost.md"}}
{"read": {"path": "/home/xxxopenclaw/openclaw.json"}}
{"exec": {"command": "find /home/xxx/openclaw -type f -name \"*.ts\" | xargs grep -l \"mattermost\" | head -20"}}Impact and severity
Affected: All agent use
Severity: High
Frequency: Always
Consequence: Broken agent.
Additional information
Agent 1 diagnosis:
Excellent detective work! I've identified the exact regression point.
Root Cause Identified
Regression introduced: Commit fe94e83 on February 16, 2026 at 14:25:44
Commit message: "fix: make tool schema normalization provider-aware"
What Changed
Before this commit, cleanSchemaForGemini() was applied universally to all tools for all providers. This meant Moonshot (and every other provider) received cleaned schemas with validation keywords removed.
After this commit, schema cleaning became provider-aware:
- Only Gemini/Google providers get Gemini-specific cleaning
- Anthropic providers get no cleaning (they support full JSON Schema)
- Moonshot gets no cleaning (assumed to support all keywords)
Why This Broke Moonshot
Moonshot's API (like Gemini and xAI) appears to reject certain JSON Schema validation keywords. The codebase shows evidence that many OpenAI-compatible APIs reject these keywords:
- Gemini rejects: format, minLength, maxLength, minimum, maximum, pattern, etc. (src/agents/schema/clean-for-gemini.ts:5-30)
- xAI rejects: minLength, maxLength, minItems, maxItems, etc. (commit 00347bd, Mar 2)
- Moonshot: Likely rejects similar keywords (but has NO cleaning)
Tools Affected
I found 10+ tools using validation keywords that Moonshot likely rejects:
- web-search.ts - minimum, maximum on count parameters
- sessions-send-tool.ts - minLength, maxLength, minimum
- sessions-spawn-tool.ts - minimum (and previously maxLength)
- message-tool.ts - minLength, maxLength
- subagents-tool.ts - minimum
- And many more...
Evidence This Matches My Diagnosis
- ✅ No Moonshot schema cleaning exists - Confirmed by examining pi-tools.schema.ts:66-101
- ✅ Similar providers reject these keywords - Gemini, xAI both reject validation constraints
- ✅ Recent related fixes - xAI got schema cleaning (Mar 2), Moonshot thinking mode was fixed (Mar 3), but schema cleaning was never added
- ✅ Affects all channels - Schema cleaning happens at agent execution layer, so TUI and Mattermost both fail
The Fix
The solution is to add Moonshot-specific schema cleaning, similar to what exists for Gemini and xAI. This can be done by: - Creating src/agents/schema/clean-for-moonshot.ts (or reusing Gemini's cleaner)
- Adding Moonshot detection to src/agents/pi-tools.schema.ts
- Applying schema cleaning when provider is Moonshot
Agent 2 diagnosis:
I dug through the history of the shared execution path (no edits made). The most likely regression window is:
- 9757d2b (2026-02-23): introduced strict OpenAI-compatible handling for non-OpenAI providers, including Moonshot, by enabling validateAnthropicTurns for openai-completions providers in src/agents/transcript-policy.ts:132.
- f304ca0 (2026-03-07): expanded that further by enabling applyGoogleTurnOrdering and validateGeminiTurns for the same strict OpenAI-compatible providers in src/agents/transcript-policy.ts:130-131, applied in src/agents/pi-embedded-runner/google.ts:593 and src/agents/pi-embedded-runner/google.ts:611.
Why this is the likely break: - Moonshot/Kimi runs through the same embedded runner path used by both TUI and Mattermost (src/agents/pi-embedded-runner/run/attempt.ts), so one core regression affects both surfaces.
- After those commits, Moonshot transcripts are passed through Gemini/Anthropic turn sanitizers that were originally provider-specific.
- validateAnthropicTurns can strip tool-use blocks when it thinks they are dangling (src/agents/pi-embedded-helpers/turns.ts:16), which can break tool-call continuity.
Secondary finding (likely contributor, but not “the” break commit): - Tool-argument decoding was added only for xAI (ce0c131, src/agents/pi-embedded-runner/run/attempt.ts:436), with no equivalent normalization for Moonshot tool args if they arrive string-encoded/escaped.
So: if you want a single “when it broke” point, I’d mark 2026-03-07 (f304ca0) as the most likely user-visible break, with 2026-02-23 (9757d2b) as the first risk-introducing change.