openclaw - ✅(Solved) Fix [Bug] Ollama adapter drops tool_calls when response includes thinking field [1 pull requests, 3 comments, 3 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#60101Fetched 2026-04-08 02:36:18
View on GitHub
Comments
3
Participants
3
Timeline
7
Reactions
0
Author
Timeline (top)
commented ×3cross-referenced ×1mentioned ×1referenced ×1

Root Cause

Root Cause Hypothesis

PR fix notes

PR #60508: test: add coverage for Ollama thinking + tool_calls streaming

Description (problem / solution / changelog)

Summary

Add three test cases that exercise the Ollama streaming adapter when thinking-capable models (e.g. qwen3.5) send thinking/reasoning chunks before or alongside tool_calls.

Test scenarios

  1. thinking → tool_calls (no text): verifies tool_calls are preserved and stopReason is toolUse
  2. thinking → tool_calls in done:true chunk: edge case where tool_calls arrive in the final response chunk
  3. thinking → text → tool_calls: mixed scenario verifying correct ordering of text streaming events and tool call accumulation

Motivation

These tests cover the scenario reported in #60101 where tool_calls could be dropped when the response includes a thinking field. They serve as regression coverage to prevent future breakage of the thinking + tool_calls code path.

Closes #60101

Changed files

  • src/agents/ollama-stream.test.ts (modified, +109/-0)

Code Example

{
  "message": {
    "role": "assistant",
    "content": "",
    "thinking": "The user wants me to run the command...",
    "tool_calls": [{
      "id": "call_vo5f1vhv",
      "function": {
        "name": "exec",
        "arguments": {"command": "python -c \"print(2**10)\""}
      }
    }]
  }
}

---

{
  "message": {
    "role": "assistant",
    "content": "",
    "tool_calls": [{
      "id": "call_5cs28dc4",
      "function": {
        "name": "exec",
        "arguments": {"command": "python -c \"print(2**10)\""}
      }
    }]
  }
}
RAW_BUFFERClick to expand / collapse

Bug

When using Ollama thinking-capable models (e.g. qwen3.5:4b), the Ollama API returns a valid response with both a thinking field and tool_calls. OpenClaw's Ollama adapter appears to drop the tool_calls, resulting in an empty assistant reply and auto-fallback to the next model.

Evidence

Direct Ollama API call to qwen3.5:4b returns correct tool_calls:

{
  "message": {
    "role": "assistant",
    "content": "",
    "thinking": "The user wants me to run the command...",
    "tool_calls": [{
      "id": "call_vo5f1vhv",
      "function": {
        "name": "exec",
        "arguments": {"command": "python -c \"print(2**10)\""}
      }
    }]
  }
}

Same task with granite4:7b-a1b-h (no thinking field) works correctly:

{
  "message": {
    "role": "assistant",
    "content": "",
    "tool_calls": [{
      "id": "call_5cs28dc4",
      "function": {
        "name": "exec",
        "arguments": {"command": "python -c \"print(2**10)\""}
      }
    }]
  }
}

Behavior

  • granite4 (no thinking field): tool_calls parsed correctly, exec runs
  • qwen3.5 (has thinking field): tool_calls dropped, empty reply, falls back to granite4

The subagent history shows qwen3.5 attempts fail silently, then retry message says "Continue where you left off. The previous model attempt failed or timed out." with granite4 as the fallback model.

Root Cause Hypothesis

The Ollama streaming adapter likely does not accumulate/parse tool_calls from chunks that also contain a thinking field. The fix in #50712 addressed sending think: false but did not address the case where thinking IS enabled and tool_calls coexist in the response.

Related Issues

  • #47993 — empty visible reply when provider returns malformed thinking/tool-call output (still OPEN)
  • #50712 — think:false not sent (CLOSED/fixed)

Reproduction

  1. Configure OpenClaw with Ollama provider
  2. Have a thinking-capable model (qwen3.5:4b) and a fallback (granite4:7b-a1b-h)
  3. Spawn a subagent with model override to qwen3.5
  4. Task: simple exec tool call (e.g. run a python command)
  5. Observe: qwen3.5 attempt produces empty reply, fallback to granite4

Environment

  • OpenClaw: latest (April 2026)
  • Ollama: latest (April 2026, post tool-call-in-thinking fix)
  • Models: qwen3.5:4b, granite4:7b-a1b-h
  • OS: Windows 11
  • GPU: RTX 3080 10GB

extent analysis

TL;DR

The Ollama streaming adapter likely needs to be updated to handle tool_calls when a thinking field is present in the response.

Guidance

  • Review the Ollama streaming adapter code to ensure it correctly accumulates and parses tool_calls from chunks containing a thinking field.
  • Verify that the adapter handles the case where thinking is enabled and tool_calls coexist in the response.
  • Check the related issues (#47993 and #50712) for potential clues or fixes that may apply to this problem.
  • Test the adapter with different models and scenarios to ensure the fix works as expected.

Example

No code snippet is provided as the issue does not contain enough information about the adapter's implementation.

Notes

The root cause hypothesis suggests that the issue is specific to the Ollama streaming adapter and its handling of tool_calls with thinking fields. The fix may require updating the adapter to correctly parse and accumulate tool_calls in this scenario.

Recommendation

Apply a workaround by modifying the Ollama streaming adapter to handle tool_calls with thinking fields, as the root cause hypothesis suggests this is the likely cause of the issue.

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