fix(ollama): persist assistant response in message_history to fix multi-turn tool calling - #427
Open
nankingjing wants to merge 3 commits into
Open
fix(ollama): persist assistant response in message_history to fix multi-turn tool calling#427nankingjing wants to merge 3 commits into
nankingjing wants to merge 3 commits into
Conversation
…ti-turn tool calling
…ti-turn tool calling
Author
|
Reviewed — persisting assistant responses in message_history is the correct fix for multi-turn Ollama conversations. Ready for review. |
The previous fix used OpenAI items for tool-call history, but expects for assistant tool turns and for text turns. The mismatch caused subsequent ollama.chat calls to reject the conversation history and broke multi-turn tool calling. - Record assistant tool-call turns as Ollama-native . - Record assistant text turns as . - Remove trailing blank line flagged by . - Add regression tests covering both persistence shapes.
Author
|
Updated the fix to use the Ollama-native message shape for assistant turns instead of OpenAI records, which rejects during multi-turn tool calling. Also added regression tests covering both text-only and tool-call persistence. Tests and lint pass locally. |
Author
|
Updated: the fix now persists assistant responses in Ollama-native message shape (role/tool_calls) instead of OpenAI |
nankingjing
force-pushed
the
fix/ollama-chat-history
branch
from
July 16, 2026 14:34
f14fd02 to
cd68621
Compare
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.
Problem
The
OllamaClient.chat()method never persists the assistant's response (text or tool calls) inself.message_history. All other LLM clients (AnthropicClient,OpenAIClient,OpenAICompatibleClient,GoogleClient) correctly append the assistant response to their message history after each chat call, but the Ollama client was missing this step.This breaks multi-turn conversations with tool calling because:
BaseAgent._tool_call_handleronly passes new tool result messages to subsequentchat()callsself.message_history(withreuse_history=Trueas default)user asks task -> user provides tool results(missing the assistant's decision to call tools)Fix
Added persistence of the assistant response to
self.message_historyafter receiving the LLM response:EasyInputMessageParam(role="assistant", content=..., type="message")ResponseFunctionToolCallParam(call_id=..., name=..., arguments=..., type="function_call")for each tool callAlso added
EasyInputMessageParamto the imports fromopenai.types.responses.This follows the same pattern used by all other LLM client implementations.
Verification
self.message_history.append()calls in OllamaClient vs multiple in every other client