turn_tracking_observer

Turn tracking observer for conversation flow monitoring.

This module provides an observer that monitors conversation turns in a pipeline, tracking when turns start and end based on user and bot speech patterns.

class pipecat.observers.turn_tracking_observer.TurnTrackingObserver(max_frames=100, turn_end_timeout_secs=2.5, **kwargs)[source]

Bases: BaseObserver

Observer that tracks conversation turns in a pipeline.

This observer monitors the flow of conversation by tracking when turns start and end based on user and bot speaking patterns. It handles interruptions, timeouts, and maintains turn state throughout the pipeline.

Turn tracking logic:

  • The first turn starts immediately when the pipeline starts (StartFrame)

  • Subsequent turns start when the user starts speaking

  • A turn ends when the bot stops speaking and either:

    • The user starts speaking again

    • A timeout period elapses with no more bot speech

__init__(max_frames=100, turn_end_timeout_secs=2.5, **kwargs)[source]

Initialize the turn tracking observer.

Parameters:
  • max_frames – Maximum number of frame IDs to keep in history for duplicate detection. Defaults to 100.

  • turn_end_timeout_secs – Timeout in seconds after bot stops speaking before automatically ending the turn. Defaults to 2.5.

  • **kwargs – Additional arguments passed to the parent observer.

async on_push_frame(data: FramePushed)[source]

Process frame events for turn tracking.

Parameters:

data – Frame push event data containing the frame and metadata.