Repository navigation
fix(py/plugins/ollama): send tool calls and tool names in chat messages - #169
Merged
Merged
Conversation
build_chat_messages ignored tool_request parts, so the assistant turn that asked for a tool reached Ollama with no tool_calls, and folded every tool response into one message with no tool_name. The model then saw a tool result for a call it never made and called the tool again until max_turns. Send tool requests as tool_calls, and each tool response as its own tool message with tool_name, encoding non-string output as JSON, as the JS Ollama plugin does. Fixes genkit-ai/genkit#7277 Upstream-Commit: genkit-ai/genkit@a60c918 Upstream-PR: genkit-ai/genkit#7279
Closed
3 of 4 tasks
cabljac
approved these changes
Nov 23, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moved from genkit-ai/genkit#7279. Fixes genkit-ai/genkit#7277.
A tool loop on an Ollama model now finishes. Before this change, the assistant turn that asked for a tool went back to Ollama with no
tool_calls, and the tool results went back with notool_name. The model then saw an answer to a call it never made, so it called the tool again on every turn until it hit the cap.Changes
tool_calls. Non-object tool input is sent as{}, because Ollama'sargumentsmust be an object.toolmessage withtool_name, instead of being merged into one unnamed message. Non-string output is sent as JSON, and non-ASCII characters are kept as they are rather than escaped.Breaking changes
None.