Skip to content

fix(ollama): run every tool call of a streamed step - #1059

Open
skybleak333 wants to merge 1 commit into
prism-php:mainfrom
skybleak333:fix/ollama-stream-tool-calls
Open

skybleak333 wants to merge 1 commit into
prism-php:mainfrom
skybleak333:fix/ollama-stream-tool-calls

Conversation

@skybleak333

Copy link
Copy Markdown

Description

When an Ollama model called several tools in one streamed step, only the last one ran. Ollama sends each call in its own chunk, always at position 0 of message.tool_calls, and numbers it with function.index (left out for the first call). extractToolCalls() keyed the calls by that position, so the second call overwrote the first.

The repo's own recording shows it: in ollama/stream-with-tools-1.sse, qwen3:14b asks for weather and then, in the next chunk, for search with "index":1. Only search ran, so the recorded second step asks for the weather again.

Calls are now keyed by function.index, and a call without one that starts a new call (it has a name) gets the next free key, so Ollama versions that don't send the index work too.

The existing tools test asserted 2 tool calls; with the same recordings it now sees weather and search in the first step and weather again in the second, so I changed its expectation to that. A new test with two calls in separate chunks checks both run in the first step and both results go back in the next request; it fails without the change. The full suite, PHPStan, Pint and Rector pass.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant