Skip to content

fix(ollama): add streamToolCalls fallback for tool calling#5783

Open
deepmehta11 wants to merge 5 commits intoopenclaw:mainfrom
deepmehta11:fix/ollama-streaming-tool-calls
Open

fix(ollama): add streamToolCalls fallback for tool calling#5783
deepmehta11 wants to merge 5 commits intoopenclaw:mainfrom
deepmehta11:fix/ollama-streaming-tool-calls

Conversation

@deepmehta11
Copy link

@deepmehta11 deepmehta11 commented Jan 31, 2026

Summary

  • Adds streamToolCalls config option for providers to disable streaming when tools are present
  • Ollama provider now defaults to streamToolCalls: false
  • Implements non-streaming fallback using complete() instead of streamSimple() when tools are in the context

Ollama's streaming implementation doesn't properly emit tool_calls delta chunks, causing tool calls to be silently lost. This fix detects when tools are present and uses non-streaming requests for affected providers.

Test plan

  • Added unit tests for isOllamaProvider(), shouldDisableStreamingForTools(), and createOllamaAwareStreamFn()
  • All 11 new tests passing
  • Existing pi-embedded-runner tests still pass
  • TypeScript compiles without errors
  • Linter passes

Fixes #5769

Greptile Overview

Greptile Summary

This PR introduces a streamToolCalls provider config flag (defaulting to false for Ollama) and adds an Ollama-aware StreamFn wrapper that switches to non-streaming complete() when tools are present, working around Ollama streaming not emitting tool-call deltas. It integrates the wrapper into the embedded runner’s stream function setup and adds unit tests for the new helper logic.

Main concerns are around the fallback stream event semantics and option parity between streamSimple() and the complete()-based path (potentially changing stop reasons and dropping some options only when tools are present).

Confidence Score: 3/5

  • Reasonably safe to merge, but verify stream event semantics in the complete() fallback.
  • Core change is a targeted fallback for Ollama tool-calls and is covered by basic unit tests, but the new complete()-based stream emulation may not match pi-ai’s expected event/stop-reason conventions and may drop some options compared to the streaming path, which could cause subtle regressions only when tools are present.
  • src/agents/pi-embedded-runner/ollama-stream.ts

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

Ollama and some other local models don't properly emit tool_calls delta
chunks when streaming is enabled. This causes tool calls to be silently
lost, breaking all tool functionality for local models.

This fix adds:
- `streamToolCalls` config option for providers (set to `false` to disable
  streaming when tools are present)
- Ollama provider now defaults to `streamToolCalls: false`
- Non-streaming fallback uses `complete()` instead of `streamSimple()`
  when tools are in the context

When `streamToolCalls: false` is set and tools are present, the agent
uses a non-streaming API call and wraps the response in a stream format
for compatibility with the existing architecture.

Fixes openclaw#5769
@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Jan 31, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Deep Mehta and others added 4 commits January 31, 2026 15:56
- Only wrap streamFn when streamToolCalls is disabled (P2)
- Pass through all options to completeSimple() (P1)
- Properly map stopReason to valid done event reasons (P0)
@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Feb 15, 2026
@openclaw-barnacle openclaw-barnacle bot removed the stale Marked as stale due to inactivity label Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ollama (and other local models): streaming breaks tool calling — need stream:false fallback

1 participant

Comments