Skip to content

fix(ai-ollama): accept tool_calls done reason - #17972

Open
swaraj017 wants to merge 2 commits into
eclipse-theia:masterfrom
swaraj017:fix/ollama-tool-calls-streaming
Open

fix(ai-ollama): accept tool_calls done reason#17972
swaraj017 wants to merge 2 commits into
eclipse-theia:masterfrom
swaraj017:fix/ollama-tool-calls-streaming

Conversation

@swaraj017

Copy link
Copy Markdown

What it does

Fixes the Ollama integration treating done_reason: "tool_calls" as an unexpected response termination.

Ollama can use tool_calls as a valid done_reason when a model finishes a response by requesting tool execution. Previously, Theia only accepted stop, which caused the Ollama language model to throw:

Ollama stopped unexpectedly. Reason: tool_calls

This PR updates both done_reason checks in packages/ai-ollama/src/node/ollama-language-model.ts to accept both stop and tool_calls, while continuing to reject other unexpected reasons.

How to test

  • Verified the change with git diff --check.
  • Verified that the final diff contains only the intended changes in packages/ai-ollama/src/node/ollama-language-model.ts.
  • Attempted to run yarn test:packages ai-ollama, but the test command could not be executed because the local Yarn/Corepack setup reported that the workspace package was missing from the lockfile and requested yarn install.

The existing packages/ai-ollama/src/node/ollama-language-model.spec.ts was left unchanged.

Follow-ups

None.

Breaking changes

Attribution

None.

Review checklist

Reminder for reviewers

@github-project-automation github-project-automation Bot moved this to Waiting on reviewers in PR Backlog Aug 30, 2026
@ndoschek

ndoschek commented Sep 2, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution! The change itself looks correct to me, but before this can be approved though, please have a look at those two points here:

First, please test the change yourself and describe it in "How to test". Right now that section only lists an inspection of the diff, which tells us nothing about behaviour, and the review requirements in doc/pull-requests.md ask authors to verify their changes before requesting a review.

Second, please add a regression test. No live server is needed: handleStreamingRequest takes the ollama client as a parameter, so a fake client is enough, and ollama-language-model.spec.ts already has the TestableOllamaModel pattern for protected methods.

One final note on tooling: this repo uses npm, not yarn. See doc/Developing.md for how to set up the build and run the tests: https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md

@swaraj017

Copy link
Copy Markdown
Author

Screenshot 2026-09-05 202902

How to test

  • Built the @theia/ai-ollama package with:
    npm run build --workspace=@theia/ai-ollama
  • Ran:
    npm test --workspace=@theia/ai-ollama
  • All 8 tests pass, including the regression test:
    should accept tool_calls as a valid done reason
  • The regression test uses a mocked Ollama client with a streaming response containing done_reason: 'tool_calls', so no live Ollama server is required.

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

Labels

None yet

Projects

Status: Waiting on reviewers

Development

Successfully merging this pull request may close these issues.

[Ollama] Streaming crashes with "Ollama stopped unexpectedly. Reason: tool_calls" when the runtime reports done_reason=tool_calls

2 participants