Skip to content

Kimi (moonshotai) stops agent loop after first tool call - reasoning_content not handled in multi-step #36316

Closed as not planned

Description

@CezarPraxe

Summary

When using a Kimi model (e.g. cf/@cf/moonshotai/kimi-k2.6 / kimi-k2.7-code) through an OpenAI-compatible provider, the agent loop stops after the first tool call instead of continuing to the next step. A model like MiniMax M3 on the same provider works fine (read -> edit -> done).

Environment

Reproduction (agent loop)

Task: "read alvo.py, find the bug and fix by adding the missing import".

  1. Model calls glob (or read).
  2. OpenCode returns the tool result.
  3. Model returns finish_reason: "stop" with no follow-up tool call -> agent ends without editing.

Observed step_finish after the tool result: reason:"stop". The model is capable of the next step (see below).

Key evidence — raw provider API works

Calling the same provider/model directly (curl) with the same multi-turn tool sequence returns a correct continuation:

  • After glob result only: finish_reason:"tool_calls", model calls read.
  • After glob + read results: finish_reason:"tool_calls", model calls edit_file with correct args.

So the endpoint/model is fine; the issue is in how OpenCode drives the multi-step loop for this model.

Suspected cause

Kimi returns its reasoning in a separate reasoning_content field (not interleaved in the streamed content). OpenCode appears to not continue the loop correctly when the model emits reasoning_content after a tool result, finalizing the turn early (stop) instead of executing the next tool call.

Config flags tested (no effect)

  • reasoning: true / false
  • interleaved: true / false
  • attachment + modalities present / absent (minimal config with only name/limit/tool_call)
  • Multiple provider endpoints (cf/, nvidia/, cline-pass/)

All still stop after the first tool call. MiniMax (no separate reasoning_content behavior) works in every configuration.

Expected behavior

After a tool result, the agent should continue calling tools (read -> edit) until the task is complete, as it does for MiniMax.

Minimal raw repro (works, proves endpoint OK)

POST /v1/chat/completions
{
"model": "cf/@cf/moonshotai/kimi-k2.6",
"messages": [
{"role":"system","content":"You are a coding agent."},
{"role":"user","content":"Read alvo.py and fix the missing import."},
{"role":"assistant","tool_calls":[{"id":"call_1","type":"function","function":{"name":"glob","arguments":"{"pattern":"**/alvo.py"}"}}]},
{"role":"tool","tool_call_id":"call_1","content":"/sandbox/alvo.py"}
],
"tools":[{"type":"function","function":{"name":"read","description":"Read","parameters":{"type":"object","properties":{"filePath":{"type":"string"}},"required":["filePath"]}}}],
"tool_choice":"auto"
}

Response: finish_reason:"tool_calls" -> read tool call (correct).

Activity

  1. github-actions commented on Jul 10, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. github-actions commented on Sep 9, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions