Skip to content

Conversation

@randombet
Copy link

@randombet randombet commented Feb 6, 2026

Summary

  • Early return after handoff in realtime pipeline: After update_agent() triggers activity transition, the old code continued using self._rt_session for chat context updates and reply generation. Since update_agent() closes the old realtime session, this caused errors and broken agent transfers. Added early return to skip post-handoff processing.
  • Resume paused agent activity on transfer back: When transferring back to an agent that was previously active, its activity was paused rather than closed. The code always started a new activity, losing the paused state. Now checks for existing activity and resumes it instead.
  • Enable manual function calls for Gemini realtime: Set manual_function_calls=True so the framework controls tool execution flow rather than Gemini auto-executing, preventing race conditions during agent handoff where tool responses could be sent to the wrong session.

Context

These bugs were discovered while building a multi-agent example with Gemini Realtime API. Transferring from main agent to a specialist worked, but transferring back consistently failed because:

  1. The handoff tool returned an AgentHandoff, triggering update_agent() which starts closing the old realtime session
  2. But the realtime tool output handler continued past the handoff, trying to call self._rt_session.update_chat_ctx() on the closing session
  3. This caused the transfer to hang or error out silently

Test plan

  • Verify agent transfer works bidirectionally (main → specialist → main) with Gemini realtime
  • Verify STT-LLM-TTS pipeline agent transfer is unaffected (fix Setting up packages #1 only touches the realtime path)
  • Verify single-agent Gemini realtime sessions work normally (no regression from manual_function_calls=True)

Open with Devin

@CLAassistant
Copy link

CLAassistant commented Feb 6, 2026

CLA assistant check
All committers have signed the CLA.

Three fixes for agent transfer with Gemini realtime models:

1. Early return after handoff in realtime pipeline (agent_activity.py):
   After update_agent() triggers activity transition, the old code continued
   using self._rt_session for chat context updates and reply generation.
   Since update_agent() closes the old realtime session, this caused errors
   and broken transfers. Added early return to skip post-handoff processing.

2. Resume paused agent activity on transfer back (agent_session.py):
   When transferring back to an agent that was previously active, its
   activity was paused rather than closed. The code always started a new
   activity, losing the paused state. Now checks for existing activity
   and resumes it instead.

3. Enable manual function calls for Gemini realtime (realtime_api.py):
   Set manual_function_calls=True so the framework controls tool execution
   flow rather than Gemini auto-executing, preventing race conditions
   during agent handoff where tool responses could be sent to the wrong
   session.
@randombet randombet force-pushed the fix/realtime-handoff-race-conditions branch from 2fc2b01 to bdf59f7 Compare February 6, 2026 23:17
Copy link
Contributor

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

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 potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@randombet randombet force-pushed the fix/realtime-handoff-race-conditions branch from f2269ce to 729d755 Compare February 7, 2026 00:04
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.

2 participants