openclaw - 💡(How to fix) Fix Kimi K2.5 (anthropic-messages) multi-turn tool calling fails: reasoning_content missing in assistant tool_use messages [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70565Fetched 2026-04-24 05:56:21
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Error Message

thinking is enabled but reasoning_content is missing in assistant tool call message at index N

Root Cause

Moonshot/Kimi's Anthropic-compatible endpoint has a strict requirement: when thinking is enabled, every assistant message containing tool_use blocks must also include a reasoning_content field in the conversation history. Even an empty string is rejected; a minimum of one space is required.

The current convertMessages function in anthropic.js does not populate reasoning_content for assistant messages with tool calls when replaying conversation history.

Fix Action

Fix / Workaround

  • #57573 — Same bug in the Kimi web search provider path (fixed by PR #59356)
  • #16952 — Earlier report of the same error string, possibly related

Code Example

thinking is enabled but reasoning_content is missing in assistant tool call message at index N

---

model: kimi/k2p5
   api: anthropic-messages
   thinking: true

---

const isKimiAnthropic = model.provider === "kimi" || model.provider === "moonshot" || 
                        model.baseUrl?.includes("moonshot.cn") || model.baseUrl?.includes("kimi.com");

// ... when building assistant message ...
if (isKimiAnthropic && hasToolUse) {
    const rc = reasoningChunks.join("\n\n");
    assistantMessage.reasoning_content = rc.length > 0 ? rc : " ";
}
RAW_BUFFERClick to expand / collapse

Bug Description

When using Kimi K2.5 (or any Moonshot model) via the anthropic-messages API format with thinking/reasoning enabled, multi-turn tool calling fails with a 400 Bad Request error on the second and subsequent turns.

Error Message

thinking is enabled but reasoning_content is missing in assistant tool call message at index N

Root Cause

Moonshot/Kimi's Anthropic-compatible endpoint has a strict requirement: when thinking is enabled, every assistant message containing tool_use blocks must also include a reasoning_content field in the conversation history. Even an empty string is rejected; a minimum of one space is required.

The current convertMessages function in anthropic.js does not populate reasoning_content for assistant messages with tool calls when replaying conversation history.

Steps to Reproduce

  1. Configure OpenClaw with Kimi K2.5 via anthropic-messages API format:
    model: kimi/k2p5
    api: anthropic-messages
    thinking: true
  2. Send a message that triggers a tool call (e.g., use web_search or any custom tool).
  3. The first request succeeds — Kimi returns thinking blocks + tool_use blocks.
  4. Send a follow-up message in the same conversation.
  5. OpenClaw replays the assistant message (with tool_use) back to Kimi, but without reasoning_content.
  6. Kimi API returns 400 Bad Request with the error above.
  7. OpenClaw falls back to the next model in the fallback chain (e.g., GPT-5.4).

Expected Behavior

Multi-turn tool calling should work correctly with Kimi K2.5 when thinking is enabled, preserving reasoning_content in assistant messages that contain tool_use.

Environment

  • OpenClaw version: 2026.4.21
  • Node.js: v22.22.2
  • Model: kimi/k2p5 (also reproducible with moonshot-v1-128k)
  • API format: anthropic-messages

Related Issues

  • #57573 — Same bug in the Kimi web search provider path (fixed by PR #59356)
  • #16952 — Earlier report of the same error string, possibly related

Suggested Fix

In convertMessages within anthropic.js, when the provider is Kimi/Moonshot and the assistant message contains tool_use blocks, collect any thinking blocks into reasoning_content and always include it (using " " as fallback if empty):

const isKimiAnthropic = model.provider === "kimi" || model.provider === "moonshot" || 
                        model.baseUrl?.includes("moonshot.cn") || model.baseUrl?.includes("kimi.com");

// ... when building assistant message ...
if (isKimiAnthropic && hasToolUse) {
    const rc = reasoningChunks.join("\n\n");
    assistantMessage.reasoning_content = rc.length > 0 ? rc : " ";
}

This is the same category of fix that was applied to the web search provider in PR #59356, but needs to be applied to the main model path as well.

Additional Context

This bug is not unique to OpenClaw — the same root cause has been reported in multiple projects:

All of these share the same pattern: Moonshot's stateless API requires clients to resend reasoning_content in assistant messages during multi-step tool calling, but the client library's message serialization omits this field.

extent analysis

TL;DR

Update the convertMessages function in anthropic.js to include reasoning_content in assistant messages with tool_use blocks when using Kimi or Moonshot models.

Guidance

  • Verify that the model.provider is either "kimi" or "moonshot" and that the message contains tool_use blocks before applying the fix.
  • Collect any thinking blocks into reasoning_content and include it in the assistant message, using a space as a fallback if empty.
  • Test the updated convertMessages function with the provided steps to reproduce the issue to ensure the fix works as expected.
  • Review related issues (#57573, #16952) and additional context from other projects (CoPaw #388, nanobot #390, LiteLLM #21672) for further insight into the problem and its solution.

Example

The suggested fix provides a code snippet that demonstrates how to update the convertMessages function:

const isKimiAnthropic = model.provider === "kimi" || model.provider === "moonshot" || 
                        model.baseUrl?.includes("moonshot.cn") || model.baseUrl?.includes("kimi.com");

// ... when building assistant message ...
if (isKimiAnthropic && hasToolUse) {
    const rc = reasoningChunks.join("\n\n");
    assistantMessage.reasoning_content = rc.length > 0 ? rc : " ";
}

Notes

This fix is specific to the Kimi and Moonshot models when using the anthropic-messages API format with thinking/reasoning enabled. The same issue may occur in other projects or configurations, but the provided solution should be applicable.

Recommendation

Apply the suggested fix to the convertMessages function in anthropic.js to resolve the issue with multi-turn tool calling when using Kimi or Moonshot models. This fix has been successfully applied in other projects

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING