feat(voice): add AgentSession.claimUserTurn#1663
Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
Open
feat(voice): add AgentSession.claimUserTurn#1663rosetta-livekit-bot[bot] wants to merge 1 commit into
rosetta-livekit-bot[bot] wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 8932824 The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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
Adds
AgentSession.claim_user_turn(), a public async context manager that declares a programmatic user-driven turn. While active:wait_for_inactiveis held open via a session-level counter (_user_turn_claims) and event (_user_turn_released).user_stateis pinned to"speaking"— non-"speaking" updates from the audio path are dropped in_update_user_state.On release,
user_stateis re-derived from the audio path's_user_silence_event:"speaking"if voice still considers the user to be speaking, else"listening". Reentrant; held at the session level so it survives agent handoff.Why
The default
text_input_cb(and any custom callback that doesinterrupt + generate_reply) had a race: a deferred async-tool reply waiting onwait_for_inactivecould resolve in the gap betweenawait sess.interrupt()andsess.generate_reply(...), firing concurrently with the new turn and producing a duplicate response. The default callback now wraps the pair inclaim_user_turnto close the window.Behavior notes
AgentActivity._wait_for_inactive's loop body, so a claim acquired during the body's awaits (e.g. while waiting for ongoing speech) is still honored._user_silence_eventwhen the claim ends.