Skip to content

fix(google): deliver tool calls before combined turn completion - #7164

Open
noooooooookro wants to merge 1 commit into
livekit:mainfrom
noooooooookro:fix/7151-google-realtime-tool-call-finalization
Open

fix(google): deliver tool calls before combined turn completion#7164
noooooooookro wants to merge 1 commit into
livekit:mainfrom
noooooooookro:fix/7151-google-realtime-tool-call-finalization

Conversation

@noooooooookro

Copy link
Copy Markdown

Fixes #7151

What changed

Google Realtime can send a single response containing both terminal server content and a tool call. The receive loop now defers generation finalization for that server content, keeping the function channel open until the tool call is delivered. Existing responses without a tool call retain their current completion behavior.

Validation

  • python -m pytest tests/test_plugin_google_realtime.py -q (19 passed)
  • ruff check livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/realtime_api.py tests/test_plugin_google_realtime.py
  • ruff format --check livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/realtime_api.py tests/test_plugin_google_realtime.py

@noooooooookro
noooooooookro requested a review from a team as a code owner September 8, 2026 04:56
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

self._handle_server_content(response.server_content)
self._handle_server_content(
response.server_content,
defer_completion=response.tool_call is not None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behaviour is right. Maybe a cleaner shape: finalize here instead of in the two handlers. Both _handle_server_content and _handle_tool_calls are only called from this loop, so the loop can own the decision and the defer_completion flag goes away.

if response.server_content:
    self._handle_server_content(response.server_content)
if response.tool_call:
    self._handle_tool_calls(response.tool_call)
if ((sc := response.server_content) and sc.turn_complete) or response.tool_call:
    self._mark_current_generation_done()

Then drop the turn_complete finalize at the end of _handle_server_content and the one at the end of _handle_tool_calls. Same order as now: content, then the calls, then close, in one iteration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google realtime: a response carrying both a terminal server_content and a tool_call kills the receive task

3 participants