Zhuoxi2000 opened a new pull request, #1166: URL: https://github.com/apache/flink-agents/pull/1166
<!-- * Thank you very much for contributing to Flink Agents. * Please add the relevant components in the PR title. E.g., [api], [runtime], [java], [python], [hotfix], etc. --> <!-- Please link the PR to the relevant issue(s). Hotfix doesn't need this. --> Linked issue: #1165 ### Purpose of change <!-- What is the purpose of this 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, `convertToOllamaChatMessages` kept only each message's role and text. Runtime flow: `buildRequest` converts each message; an assistant message with tool calls now gets `tool_calls` built 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 <!-- For a non-trivial code change whose implementation is largely AI-assisted: interaction decisions, behavioral contracts, and failure behavior. See `contribution-guides/ai-assisted-pr.md`. Remove this heading and this comment otherwise. --> Interaction decisions: not applicable; one condition (a message has tool calls or not). Behavioral contracts: 1. A message with tool calls is sent with `tool_calls`, one per call, in order, each with `function.name` and `function.arguments` as an object. 2. Arguments given as a JSON string are sent as the parsed object. 3. A message without tool calls is sent as before. Failure behavior: a tool call without a function name, or with arguments that are neither an object nor a JSON object string, throws `IllegalArgumentException` while the request is built; nothing is sent. ### Tests <!-- How is this change verified? --> | Contract | Test | |---|---| | 1, 2, 3 | `OllamaChatModelConnectionTest#buildRequestForwardsAssistantToolCalls`, asserting on the request as serialized by ollama4j | Not 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 <!-- Does this change touches any public APIs? --> No API change. Requests for histories with tool calls now include them; other requests are unchanged. ### Documentation <!-- Do not remove this section. Check the proper box only. --> - [ ] `doc-needed` <!-- Your PR changes impact docs --> - [x] `doc-not-needed` <!-- Your PR changes do not impact docs --> - [ ] `doc-included` <!-- Your PR already contains the necessary documentation updates --> ### Was this patch authored or co-authored using generative AI tooling? <!-- Do not remove this section. Check the proper box only. --> - [x] Yes - [ ] No If yes, include a `Generated-by: <tool name and version> (<model name and version>)` line, for example `Generated-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](https://www.apache.org/legal/generative-tooling.html). Generated-by: Claude Code 2.1.259 (Claude Opus 5.5) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
