Skip to content

feat: add HandoffMetrics for measuring agent handoff timing#5442

Open
longcw wants to merge 3 commits intomainfrom
longc/handoff-metrics
Open

feat: add HandoffMetrics for measuring agent handoff timing#5442
longcw wants to merge 3 commits intomainfrom
longc/handoff-metrics

Conversation

@longcw
Copy link
Copy Markdown
Contributor

@longcw longcw commented Apr 14, 2026

Summary

  • Add HandoffMetrics to measure agent handoff cost, emitted via metrics_collected and attached to AgentHandoff.metrics
  • Tracks orchestration timing: drain_duration, new_activity_duration, on_enter_duration, and total duration
  • Reports whether STT pipeline and realtime session were reused across the handoff (stt_reused, realtime_session_reused)

Limitation

HandoffMetrics does not include the WebSocket connection time for new realtime sessions or STT streams. When resources are not reused, the connection is established asynchronously in a background task. This connection time is already reported separately via RealtimeModelMetrics.acquire_time and STTMetrics.acquire_time through the existing metrics_collected pipeline.

Add HandoffMetrics to measure the cost of agent handoffs, including:
- drain_duration: time to drain the old activity (on_exit + pending speech)
- new_activity_duration: time to start/resume the new activity
- on_enter_duration: time for the new agent's on_enter callback
- stt_reused / realtime_session_reused: whether resources were reused
@chenghao-mou chenghao-mou requested a review from a team April 14, 2026 05:46
Copy link
Copy Markdown
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

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.

1 participant