TurnTrackingObserver monitors and tracks conversational turns in your Pipecat pipeline, providing events when turns start and end. It intelligently identifies when a user-bot interaction cycle begins and completes.
Turn Lifecycle
A turn represents a complete user-bot interaction cycle:- Start: When the user starts speaking (or pipeline starts for first turn)
- Processing: User speaks, bot processes and responds
- End: After the bot finishes speaking and either:
- The user starts speaking again
- A timeout period elapses with no further activity
EndFrame or CancelFrame) while a turn is active, that turn ends with was_interrupted=True.
Events
The observer emits two main events:on_turn_started: When a new turn begins- Parameters:
turn_number(int)
- Parameters:
on_turn_ended: When a turn completes- Parameters:
turn_number(int),duration(float, in seconds),was_interrupted(bool)
- Parameters:
Usage
The observer is automatically created when you initialize aPipelineWorker with enable_turn_tracking=True (which is the default):
Configuration
To configure the observer, create aTurnTrackingObserver yourself and pass it in the observers list of PipelineWorker:
float
default:"2.5"
Timeout in seconds after bot stops speaking before automatically ending the
turn.
int | None
default:"None"
deprecated
Deprecated since 1.12.0, removed in 2.0.0. No replacement. The observer
receives each frame once.
Interruptions
The observer automatically detects interruptions when the user starts speaking while the bot is still speaking. In this case:- The current turn is marked as interrupted (
was_interrupted=True) - A new turn begins immediately
How It Works
The observer monitors specific frame types to track conversation flow:- StartFrame: Initiates the first turn
- UserStartedSpeakingFrame: Starts user speech or triggers a new turn
- BotStartedSpeakingFrame: Marks bot speech beginning
- BotStoppedSpeakingFrame: Starts the turn end timeout
Use Cases
- Analytics: Measure turn durations, interruption rates, and conversation flow
- Logging: Record turn-based logs for diagnostics and analysis
- Visualization: Show turn-based conversation timelines in UIs
- Tracing: Group spans and metrics by conversation turns