Repository navigation
[integration][java] Forward assistant tool calls in the Ollama chat history - #1166
Merged
wenjin272 merged 1 commit intoSep 29, 2026
Merged
Conversation
wenjin272
approved these changes
Sep 29, 2026
wenjin272
left a comment
Contributor
There was a problem hiding this comment.
Thanks for taking this on. LGTM
2 of 5 tasks
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.
Linked issue: #1165
Purpose of change
A Java agent on Ollama now sends the assistant's earlier tool calls back with the chat history, so the model sees the calls that produced the tool results, as a Python agent already does. Before,
convertToOllamaChatMessageskept only each message's role and text.Runtime flow:
buildRequestconverts each message; an assistant message with tool calls now getstool_callsbuilt from each call's function name and arguments. Key decisions: match the Python connection, which sends the name and the arguments object and no id; the framework-assigned id is unknown to Ollama. Arguments that arrive as a JSON string are parsed into an object, since Ollama expects one.Behavioral Semantics
Interaction decisions: not applicable; one condition (a message has tool calls or not).
Behavioral contracts:
tool_calls, one per call, in order, each withfunction.nameandfunction.argumentsas an object.Failure behavior: a tool call without a function name, or with arguments that are neither an object nor a JSON object string, throws
IllegalArgumentExceptionwhile the request is built; nothing is sent.Tests
OllamaChatModelConnectionTest#buildRequestForwardsAssistantToolCalls, asserting on the request as serialized by ollama4jNot verified: a live multi-turn tool call against an Ollama server; the failure paths above have no dedicated test. Module tests pass locally (16/16), with spotless.
API
No API change. Requests for histories with tool calls now include them; other requests are unchanged.
Documentation
doc-neededdoc-not-neededdoc-includedWas this patch authored or co-authored using generative AI tooling?
If yes, include a
Generated-by: <tool name and version> (<model name and version>)line, for exampleGenerated-by: Claude Code 2.1.226 (Claude Opus 4.6), in the commit message so it reaches Git history. Repeat the same line here for reviewer visibility. See the ASF generative tooling guidance.Generated-by: Claude Code 2.1.259 (Claude Opus 5.5)