fix: yield tool_call_parts immediately in live mode to unblock Gemini 3.1 tool calls#5408
fix: yield tool_call_parts immediately in live mode to unblock Gemini 3.1 tool calls#5408sandeshveerani4 wants to merge 7 commits intogoogle:mainfrom
Conversation
Tool call parts received via LiveServerToolCall were accumulated in tool_call_parts but only yielded when turn_complete arrived or the receive loop exited. Gemini 3.1 Flash Live models send tool calls via LiveServerToolCall and do not emit turn_complete until the tool response is received, causing a deadlock where the framework never executes the tool because it never sees the function call event. Yield tool_call_parts immediately after receiving them so the framework can execute tools and send responses back to the model.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Response from ADK Triaging Agent Hello @sandeshveerani4, thank you for your contribution! Before we can merge this PR, you will need to sign the Contributor License Agreement (CLA). You can find more information at https://cla.developers.google.com/. Thanks! |
|
Hi @sandeshveerani4 ,Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing unit tests before we can proceed with the review. |
Other models (2.5-pro, native-audio) send turn_complete after tool calls, so they should buffer and merge tool call parts into a single response. Gemini 3.1 does not send turn_complete until a tool response is received, so it must yield immediately to avoid deadlocking.
|
Hello, is there an ETA for when this will be released? |
|
Hey @rohityan, I've fixed the failing unit tests, can you try running the test again and if passed, please approve it as this is really required for live agent to be working with the tools. |
… 3.1 tool calls Fixes #5407 END_PUBLIC Merge #5408 ## Summary - Tool call parts received via `LiveServerToolCall` in `GeminiLlmConnection.receive()` are now yielded immediately instead of being deferred until `turn_complete` - This unblocks function/tool calling for Gemini 3.1 Flash Live models which do not emit `turn_complete` until they receive the tool response ## Problem Gemini 3.1 Flash Live models send tool calls via `LiveServerToolCall` and wait for the tool response before sending `turn_complete`. The current code accumulates `tool_call_parts` and only yields them on `turn_complete` or loop exit, creating a deadlock where tools are never executed. ## Fix Yield `tool_call_parts` immediately after receiving `message.tool_call`. This is backward-compatible — earlier models that send `turn_complete` after tool calls will still work because the existing yield paths become no-ops when `tool_call_parts` is already empty. ## Test plan - [x] Tested with `gemini-3.1-flash-live-preview` in live mode — tool calls now execute on the first message and the model responds with audio after receiving tool results - [x] Verified no regression with the existing `turn_complete`-based flow Co-authored-by: Sasha Sobran <asobran@google.com> COPYBARA_INTEGRATE_REVIEW=#5408 from sandeshveerani4:fix/live-tool-call-yield ca0e760 PiperOrigin-RevId: 908326192
|
Thank you @sandeshveerani4 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit f57b05d. Closing this PR as the changes are now in the main branch. |
Summary
Fixes #5407
LiveServerToolCallinGeminiLlmConnection.receive()are now yielded immediately instead of being deferred untilturn_completeturn_completeuntil they receive the tool responseProblem
Gemini 3.1 Flash Live models send tool calls via
LiveServerToolCalland wait for the tool response before sendingturn_complete. The current code accumulatestool_call_partsand only yields them onturn_completeor loop exit, creating a deadlock where tools are never executed.Fix
Yield
tool_call_partsimmediately after receivingmessage.tool_call. This is backward-compatible — earlier models that sendturn_completeafter tool calls will still work because the existing yield paths become no-ops whentool_call_partsis already empty.Test plan
gemini-3.1-flash-live-previewin live mode — tool calls now execute on the first message and the model responds with audio after receiving tool resultsturn_complete-based flow