Skip to content

feat(voice): add UserTurnLimitOptions to interrupt long user speech#5492

Open
longcw wants to merge 4 commits intomainfrom
longc/user-speech-exceeded
Open

feat(voice): add UserTurnLimitOptions to interrupt long user speech#5492
longcw wants to merge 4 commits intomainfrom
longc/user-speech-exceeded

Conversation

@longcw
Copy link
Copy Markdown
Contributor

@longcw longcw commented Apr 20, 2026

Summary

Adds a configurable limit on how long a user can speak before the agent is given a chance to interrupt. Accumulates word count and wall-clock duration across consecutive user turns.

When a threshold is crossed, the framework fires UserTurnExceededEvent and invokes Agent.on_user_turn_exceeded. The default implementation calls session.generate_reply(..., allow_interruptions=False, tool_choice="none") with instructions to politely cut in with a short reply. Users can override the hook for custom behavior.

API

AgentSession(
    turn_handling={
        "user_turn_limit": {"max_words": 100, "max_duration": 30.0},
    },
)

Both thresholds default to None (disabled). Set either or both.

Coordination

AgentActivity._user_turn_exceeded_task waits for the normal EOU-triggered response to resolve before firing the hook — if the agent reaches speaking on its own, the callback is skipped.

longcw added 4 commits April 17, 2026 18:53
Accumulates word count and duration across consecutive user turns;
fires UserTurnExceededEvent and invokes Agent.on_user_turn_exceeded
when thresholds are crossed. Counters reset when the agent reaches
speaking state.
@chenghao-mou chenghao-mou requested a review from a team April 20, 2026 03:17
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 5 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant