Overview
Turn events provide hooks into the conversation turn lifecycle, allowing you to know when users and assistants start or stop speaking. These events are emitted by the context aggregators (LLMUserAggregator and LLMAssistantAggregator) and are particularly useful for:
- Collecting transcriptions - Get complete user and assistant transcripts when turns end
- Turn tracking - Monitor conversation flow and timing
- Analytics - Measure turn durations, detect timeouts, and track conversation patterns
Events Summary
| Event | Emitter | Description |
|---|---|---|
on_user_turn_started | user_aggregator | User begins speaking |
on_user_turn_stopped | user_aggregator | User finishes speaking (includes transcript) |
on_user_turn_stop_timeout | user_aggregator | User turn ended due to timeout |
on_assistant_turn_started | assistant_aggregator | Assistant begins responding |
on_assistant_turn_stopped | assistant_aggregator | Assistant finishes responding (includes transcript) |
User Turn Events
User turn events are registered on theuser_aggregator from an LLMContextAggregatorPair.
on_user_turn_started
Fired when a user turn is detected to have started, based on the configured start strategies.| Parameter | Type | Description |
|---|---|---|
aggregator | LLMUserAggregator | The user aggregator instance |
strategy | BaseUserTurnStartStrategy | The strategy that triggered the turn start |
on_user_turn_stopped
Fired when a user turn is detected to have ended, based on the configured stop strategies. This event includes the complete user transcript for the turn.| Parameter | Type | Description |
|---|---|---|
aggregator | LLMUserAggregator | The user aggregator instance |
strategy | BaseUserTurnStopStrategy | The strategy that triggered the turn stop |
message | UserTurnStoppedMessage | Contains the user’s transcript and metadata |
on_user_turn_stop_timeout
Fired when a user turn times out without any stop strategy triggering. This is a fallback mechanism that ends the turn after a configurable timeout period (default: 5.0 seconds) when the user has stopped speaking according to VAD but no transcription-based stop has occurred.| Parameter | Type | Description |
|---|---|---|
aggregator | LLMUserAggregator | The user aggregator instance |
After
on_user_turn_stop_timeout fires, on_user_turn_stopped will also be called with the accumulated transcript.Assistant Turn Events
Assistant turn events are registered on theassistant_aggregator from an LLMContextAggregatorPair.
on_assistant_turn_started
Fired when the assistant begins generating a response.| Parameter | Type | Description |
|---|---|---|
aggregator | LLMAssistantAggregator | The assistant aggregator instance |
on_assistant_turn_stopped
Fired when the assistant finishes responding or is interrupted. This event includes the complete assistant transcript for the turn.| Parameter | Type | Description |
|---|---|---|
aggregator | LLMAssistantAggregator | The assistant aggregator instance |
message | AssistantTurnStoppedMessage | Contains the assistant’s transcript and metadata |
This event fires when the LLM response completes, when the user interrupts, or when a user image is appended to context.
Message Types
UserTurnStoppedMessage
Contains the user’s complete transcript when their turn ends.The complete transcribed text from the user’s turn.
ISO 8601 timestamp indicating when the user turn started.
Optional identifier for the user, if available from the transport.
AssistantTurnStoppedMessage
Contains the assistant’s complete transcript when their turn ends.The complete text content from the assistant’s turn.
ISO 8601 timestamp indicating when the assistant turn started.
Related
- Transcriptions - Collect conversation transcripts using turn events
- User Turn Strategies - Configure turn detection behavior
- Turn Tracking Observer - Track complete turn cycles with timing