Skip to content

Kimi Code thinking/tool replay fails: missing reasoning_content in assistant tool-call replay #91558

Closed

Description

@liuhaiyang14

Summary

When using Kimi Code through an OpenAI-compatible provider in OpenClaw, a normal single-turn response can succeed, but enabling thinking for an agent turn that uses tools fails during tool-call replay.

The provider rejects the follow-up request with:

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

This looks like the OpenAI-compatible replay path is not preserving or reconstructing the assistant reasoning_content required by Kimi Code when thinking is enabled and tool calls are replayed.

Environment

  • OpenClaw version: 2026.6.1
  • Gateway version: 2026.6.1
  • Provider id: moonshot-code
  • Model id: kimi-for-coding
  • API style: openai-completions
  • Base URL: https://api.kimi.com/coding/v1
  • Current workaround: keep Kimi Code thinking disabled and use it as a late fallback.

Current working model config workaround:

{
  "id": "kimi-for-coding",
  "name": "Kimi Code (for coding)",
  "api": "openai-completions",
  "reasoning": false,
  "compat": {
    "supportsReasoningEffort": false,
    "maxTokensField": "max_tokens"
  }
}

Agent model params workaround:

{
  "max_tokens": 65536,
  "thinking": false
}

Reproduction

  1. Configure Kimi Code as an OpenAI-compatible provider with reasoning enabled:
{
  "models": {
    "providers": {
      "moonshot-code": {
        "baseUrl": "https://api.kimi.com/coding/v1",
        "apiKey": "${KIMI_API_KEY}",
        "api": "openai-completions",
        "models": [
          {
            "id": "kimi-for-coding",
            "name": "Kimi Code (for coding)",
            "input": ["text", "image"],
            "reasoning": true,
            "contextWindow": 131072,
            "maxTokens": 65536,
            "compat": {
              "supportsReasoningEffort": true,
              "maxTokensField": "max_tokens"
            },
            "api": "openai-completions"
          }
        ]
      }
    }
  }
}
  1. Run a simple thinking-enabled turn:
openclaw agent \
  --model moonshot-code/kimi-for-coding \
  --thinking high \
  --session-key agent:codex:kimi-thinking-simple \
  --message 'Test Kimi Code thinking high. Reply only KIMI_THINK_SIMPLE_OK_9.' \
  --json

This succeeds.

  1. Run a thinking-enabled tool turn:
openclaw agent \
  --model moonshot-code/kimi-for-coding \
  --thinking high \
  --session-key agent:codex:kimi-thinking-tool \
  --message 'You must call exec to run: printf KIMI_TOOL_OK. Then reply only FINAL_KIMI_TOOL_OK.' \
  --json

Actual result

The run fails with:

GatewayClientRequestError: FailoverError: LLM request failed: provider rejected the request schema or tool payload.

Gateway logs show the provider error:

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

Relevant diagnostic fields:

{
  "provider": "moonshot-code",
  "model": "kimi-for-coding",
  "failoverReason": "format",
  "providerRuntimeFailureKind": "schema",
  "rawErrorPreview": "400 thinking is enabled but reasoning_content is missing in assistant tool call message at index 2"
}

Expected result

OpenClaw should either:

  1. Preserve and replay Kimi Code reasoning_content correctly for assistant messages that contain tool calls, or
  2. Automatically disable thinking for Kimi Code tool-using sessions when the provider requires reasoning_content replay that OpenClaw cannot satisfy, or
  3. Expose a provider compat flag similar to existing reasoning replay controls so Kimi Code can be configured safely.

Workaround

Keep Kimi Code configured with thinking disabled and use it only as a fallback:

{
  "reasoning": false,
  "compat": {
    "supportsReasoningEffort": false,
    "maxTokensField": "max_tokens"
  }
}

Agent params:

{
  "max_tokens": 65536,
  "thinking": false
}

This avoids the replay failure, but prevents thinking-enabled Kimi Code tool use.

Additional notes

I tested Qwen3.7 Plus with OpenClaw compat.thinkingFormat: "qwen" under the same style of tool-call replay test. Qwen completed the tool turn and a follow-up turn successfully. So this appears to be specific to Kimi Code / Moonshot-style reasoning_content replay behavior rather than all OpenAI-compatible thinking providers.

Activity

  1. clawsweeper commented on Jun 9, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

    Current main already has the safe Kimi Code replay path: the OpenAI-compatible transport now honors the explicit reasoning-content compat flag for custom providers, and the bundled Kimi provider backfills reasoning_content on assistant tool-call replay when thinking is enabled. This is current-main-only for the custom-provider fix, so the reported v2026.6.1 behavior is explained by the release lag.

    So I’m closing this as already implemented rather than keeping a duplicate issue open.

    Review details

    Best possible solution:

    Keep the current-main compat behavior and direct custom Kimi OpenAI-compatible users to either the bundled kimi/kimi-for-coding provider or compat.requiresReasoningContentOnAssistantMessages: true until the next release ships it.

    Do we have a high-confidence way to reproduce the issue?

    Yes for the shipped failure path at source level: v2026.6.1 ignored the explicit custom-provider compat flag in the agent transport, while current main honors it. I did not run the live Kimi request without credentials.

    Is this the best way to solve the issue?

    Yes. The maintainable fix is to keep Kimi-specific behavior in the bundled provider and expose the generic compat flag for custom OpenAI-compatible routes instead of hard-coding every custom provider id.

    Security review:

    Security review: No patch is under review, and the issue does not report a security-sensitive behavior.

    AGENTS.md: found and applied where relevant.

    What I checked:

    • Repository policy read: Read the full root AGENTS.md and applicable scoped guides for agents/plugins/gateway before reviewing provider replay behavior. (AGENTS.md:1, aa935ddeb23f)
    • Custom provider compat is honored on current main: Current main resolves compat.requiresReasoningContentOnAssistantMessages from the configured model before building OpenAI-compatible replay payloads, so custom Kimi-style providers can opt into the required replay contract. (src/agents/openai-transport-stream.ts:3440, 55de547b5214)
    • Replay backfill exists in the shared OpenAI-compatible serializer: When the compat flag is true and model reasoning is enabled, assistant replay messages missing reasoning_content are backfilled with an empty string before the request is sent. (src/llm/providers/openai-completions.ts:1062, 55de547b5214)
    • Regression coverage for custom providers: Current tests cover a custom OpenAI-compatible provider opting into requiresReasoningContentOnAssistantMessages, matching the safe configuration requested by the issue. (src/agents/openai-transport-stream.test.ts:10123, 55de547b5214)
    • Bundled Kimi provider backfills tool-call replay: The Kimi provider wrapper adds reasoning_content: "" to assistant messages with OpenAI tool calls when thinking is enabled, preserving native reasoning when already present. (extensions/kimi-coding/stream.ts:90, 55de547b5214)
    • Current docs expose the configuration path: Current main documents models.providers.*.models.*.compat.requiresReasoningContentOnAssistantMessages and the built-in kimi/kimi-for-coding provider path. Public docs: docs/gateway/config-tools.md. (docs/gateway/config-tools.md:572, aa935ddeb23f)

    Likely related people:

    • Vincent Koc: Blame for the current compat resolution, Kimi replay wrapper, and related docs points to the current-main proof commit used for this close decision. (role: current implementation provenance; confidence: high; commits: 55de547b5214; files: src/agents/openai-transport-stream.ts, extensions/kimi-coding/stream.ts, docs/providers/moonshot.md)
    • Ayaan Zaidi: Recent Kimi stream work changed the bundled Kimi payload behavior around native tool schemas, making this a useful routing candidate for provider replay follow-up if needed. (role: recent adjacent contributor; confidence: medium; commits: d7b8faa7bf01; files: extensions/kimi-coding/stream.ts)
    • Mario Zechner: Earlier history moved Kimi Coding into the built-in provider path that current docs recommend for kimi/kimi-for-coding. (role: feature-history contributor; confidence: medium; commits: bf15d0a3f5e1; files: docs/providers/moonshot.md, extensions/kimi-coding/index.ts)

    Codex review notes: model gpt-5.5, reasoning high; reviewed against aa935ddeb23f; fix evidence: commit 55de547b5214, main fix timestamp 2026-06-09T01:02:22+02:00.

  2. added
    P2Normal backlog priority with limited blast radius.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.
    on Jun 9, 2026
  3. locked as resolved and limited conversation to collaborators on Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions