Skip to content

fix(voice): avoid old-agent reply generation when handoff is required#5184

Open
api2062 wants to merge 1 commit intolivekit:mainfrom
api2062:api2062/5150
Open

fix(voice): avoid old-agent reply generation when handoff is required#5184
api2062 wants to merge 1 commit intolivekit:mainfrom
api2062:api2062/5150

Conversation

@api2062
Copy link

@api2062 api2062 commented Mar 20, 2026

Summary

When both handoff and reply are required in the same turn, the old agent can still produce an extra reply before control moves to the new agent.

This change ensures handoff takes priority and prevents extra old-agent reply generation.
It also preserves previously discovered handoff tasks by avoiding replacement with None.

Changes

  • gate reply generation behind not handoff required in pipeline and realtime paths
  • only overwrite new_agent_task when a non-None task is provided
  • add regression test for handoff+reply-required flow

Validation

  • added failing test first, then verified it passes with fix
  • ran tests: uv run pytest tests/test_agent_session.py -q (18 passed)
  • ran formatting/lint checks

Closes #5150

@CLAassistant
Copy link

CLAassistant commented Mar 20, 2026

CLA assistant check
All committers have signed the CLA.

@api2062 api2062 marked this pull request as ready for review March 20, 2026 22:47
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 3 additional findings.

Open in Devin Review

Copy link
Contributor

@onurburak9 onurburak9 left a comment

Choose a reason for hiding this comment

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

Thanks for improving the handoff flow, lgtm

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.

Agent handoff fails when tool returning Agent runs in parallel with reply-producing tool (pipeline path)

3 participants