fix(voice): preserve e2e latency across agent handoffs - #7161
Closed
mikemikimike wants to merge 1 commit into
Closed
fix(voice): preserve e2e latency across agent handoffs#7161mikemikimike wants to merge 1 commit into
mikemikimike wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
Comment on lines
+1630
to
+1631
| handoff_user_metrics = self._session._handoff_user_metrics | ||
| self._session._handoff_user_metrics = None |
Contributor
There was a problem hiding this comment.
🟡 Handoff latency reaches the wrong reply
_generate_reply clears session-wide handoff metrics before validating the request or confirming the target activity. A failed, realtime, or concurrent reply can consume them first. The handoff reply then loses end-to-end latency, while an unrelated reply can inherit stale data.
Prompt for agents
The handoff metrics are stored on AgentSession and consumed by whichever AgentActivity._generate_reply call happens next. This is not scoped to the activity created by the handoff, and consumption occurs before tool validation and before selecting the pipeline or realtime path. Associate the metrics with the specific target activity or handoff generation instead of a session-wide next-call slot. Consume them only after a valid pipeline reply has been created, and define cleanup for failed or abandoned handoffs so stale metrics cannot reach later replies.
Was this helpful? React with 👍 or 👎 to provide feedback.
Contributor
|
closing in favor of #7167 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary\n\nPreserve the originating user's speech metrics when a function tool triggers an agent handoff. The next agent's first generate_reply() can now report �2e_latency on its assistant message, span, and OpenTelemetry histogram.\n\nThe propagation uses a task-local ContextVar, so direct AgentSession.update_agent() handoffs and returned handoff tasks work without sharing mutable per-turn state.\n\n## Tests\n\n- ests/test_update_agent_long_on_enter.py — added a synthetic audio regression test for a handoff reply\n- 94 passed across ests/test_agent_session.py, ests/test_tool_output_per_call.py, and ests/test_update_agent_long_on_enter.py\n-
uff check and compileall pass\n\nCloses #7157.