Observers
Observer Pattern
Understanding and implementing observers in Pipecat
Observer Pattern
The Observer pattern in Pipecat allows non-intrusive monitoring of frames as they flow through the pipeline. Observers can watch frame traffic without affecting the pipeline’s core functionality.
Base Observer
All observers must inherit from BaseObserver
and implement the on_push_frame
method:
Using Multiple Observers
You can attach multiple observers to a pipeline task. Each observer will be notified of all frames:
Example: Debug Observer
Here’s an example observer that logs interruptions and bot speaking events:
Common Use Cases
Observers are particularly useful for:
- Debugging frame flow
- Logging specific events
- Monitoring pipeline behavior
- Collecting metrics
- Converting internal frames to external messages