Skip to content

feat(voice): add AgentSession.claimUserTurn#1663

Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
bruise-gorse-headsets
Open

feat(voice): add AgentSession.claimUserTurn#1663
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
bruise-gorse-headsets

Conversation

@rosetta-livekit-bot
Copy link
Copy Markdown
Contributor

@rosetta-livekit-bot rosetta-livekit-bot Bot commented Jun 1, 2026

Summary

Adds AgentSession.claim_user_turn(), a public async context manager that declares a programmatic user-driven turn. While active:

  • wait_for_inactive is held open via a session-level counter (_user_turn_claims) and event (_user_turn_released).
  • user_state is pinned to "speaking" — non-"speaking" updates from the audio path are dropped in _update_user_state.

On release, user_state is 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 does interrupt + generate_reply) had a race: a deferred async-tool reply waiting on wait_for_inactive could resolve in the gap between await sess.interrupt() and sess.generate_reply(...), firing concurrently with the new turn and producing a duplicate response. The default callback now wraps the pair in claim_user_turn to close the window.

Behavior notes

  • The hold check sits at the end of 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.
  • Voice transitions during the claim are not lost — they're recoverable from _user_silence_event when the claim ends.
  • Pre-claim "away" status doesn't carry through: post-claim state goes to "listening", and the away timer restarts naturally.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 1, 2026

🦋 Changeset detected

Latest commit: 8932824

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
@livekit/agents Major
@livekit/agents-plugin-anam Major
@livekit/agents-plugin-assemblyai Major
@livekit/agents-plugin-baseten Major
@livekit/agents-plugin-bey Major
@livekit/agents-plugin-cartesia Major
@livekit/agents-plugin-cerebras Major
@livekit/agents-plugin-deepgram Major
@livekit/agents-plugin-elevenlabs Major
@livekit/agents-plugin-fishaudio Major
@livekit/agents-plugin-google Major
@livekit/agents-plugin-hedra Major
@livekit/agents-plugin-hume Major
@livekit/agents-plugin-inworld Major
@livekit/agents-plugin-lemonslice Major
@livekit/agents-plugin-liveavatar Major
@livekit/agents-plugin-livekit Major
@livekit/agents-plugin-minimax Major
@livekit/agents-plugin-mistral Major
@livekit/agents-plugin-mistralai Major
@livekit/agents-plugin-neuphonic Major
@livekit/agents-plugin-openai Major
@livekit/agents-plugin-perplexity Major
@livekit/agents-plugin-phonic Major
@livekit/agents-plugin-resemble Major
@livekit/agents-plugin-rime Major
@livekit/agents-plugin-runway Major
@livekit/agents-plugin-sarvam Major
@livekit/agents-plugin-silero Major
@livekit/agents-plugin-tavus Major
@livekit/agents-plugins-test Major
@livekit/agents-plugin-trugen Major
@livekit/agents-plugin-xai Major

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

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.

0 participants