Zhuoxi2000 opened a new pull request, #960:
URL: https://github.com/apache/flink-agents/pull/960

   <!--
   * 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: #947
   
   ### Purpose of change
   
   <!-- What is the purpose of this change? -->
   
   The Gemini Developer API frequently returns `functionCall` parts without an 
id. `convertFunctionCall` previously emitted neither `id` nor `original_id` in 
that case, which broke the runtime round-trip twice:
   
   1. `ToolCallAction` reads the id via `String.valueOf(toolCall.get("id"))`, 
so every id-less call keyed the `success`/`responses`/`error` maps on the 
literal string `"null"` — two parallel id-less calls collided and only the last 
result survived.
   2. `original_id` is what `ToolCallAction` propagates as the TOOL message's 
`externalId`; without it the follow-up turn cannot resolve the function name 
for Gemini's `functionResponse` part, and `resolveToolFunctionName` throws 
`"Tool message must carry the function name"` — turn 1 executes the tool, turn 
2 crashes.
   
   Fix: when the native id is absent, synthesize a UUID and set both `id` and 
`original_id`, plus a `synthetic_id` marker. `convertToolCallToPart` skips 
echoing the id back to Gemini when the marker is present, so on-the-wire 
behavior for id-less calls is unchanged — the synthetic id exists purely for 
runtime correlation. Calls that carry a native id are untouched.
   
   ### Tests
   
   <!-- How is this change verified? -->
   
   Three new cases in `GeminiChatModelConnectionTest`: id-less calls get unique 
synthetic ids (`id == original_id`, `synthetic_id` set, two calls never 
collide); a synthetic id is never echoed back to the API 
(`Part.functionCall().id()` stays empty); and the full id-less round trip — 
assistant turn → `buildToolCallIdToNameMap` → TOOL turn with `externalId` — 
resolves the function name (this exact flow threw before the fix). Existing 16 
tests pass unchanged (20/20 total).
   
   ### API
   
   <!-- Does this change touches any public APIs? -->
   
   None (`synthetic_id` is an internal marker key inside the tool-call map).
   
   ### 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 -->


-- 
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]

Reply via email to