Basic Pipeline Structure
A Pipeline takes a list of frame processors and connects them in sequence. Here’s a simple voice AI pipeline that matches the voice AI agent architecture we discussed earlier:Understanding Frames and Frame Processing
Before diving deeper into pipelines, it’s important to understand how data moves through them using frames and frame processors.What Are Frames?
Frames are data containers that carry information through your pipeline. Think of them as packages on a conveyor belt. Each frame contains a specific type of data that processors can examine and act upon. Frames automatically receive unique identifiers and names (likeTranscriptionFrame#1
) that help with debugging and tracking data flow through your pipeline.
Common frame types include:
- Audio frames: Raw audio data from users or generated by TTS
- Text frames: Transcriptions, LLM responses, or other text content
- Image frames: Visual data for multimodal applications
- System frames: Control signals for pipeline management
- Context frames: Conversation history and state information
What Are Frame Processors?
Frame Processors are the workers in your pipeline. Each processor has a specific job - like converting speech to text, generating responses, or playing audio. They:- Receive frames from the previous processor in the pipeline
- Process the data (transcribe audio, generate text, etc.)
- Create new frames with their output
- Pass frames along to the next processor
Frame Types
Frames in Pipecat have different base classes that determine how they’re processed:- SystemFrames: Processed immediately (interruptions, pipeline control, user input)
- DataFrames & ControlFrames: Queued and processed in order (audio output, text, images)
Frame Processing Order
Frames are processed in guaranteed order, even across ParallelPipelines. This enables reliable sequencing. For example, you can push two frames in order and the order will be respected. Additionally, the corresponding processing will finish before allowing the next frame to be processed. Let’s look at an example where we push two frames—TTSSpeakFrame
and EndFrame
—in order to say goodbye then end the pipeline:
How Frame Processors Work
Every frame processor follows the same pattern with two key methods:process_frame()
: Inspect and handle incoming framespush_frame()
: Send frames upstream or downstream
Custom Frame Processors
Learn how to build your own frame processors
How Data Flows Through Pipelines
Understanding data flow is crucial for building effective pipelines:Frame Processing Order
Order matters: Processors must be arranged so that each receives the frame types it needs:transport.input()
createsInputAudioRawFrame
s from user audiostt
receives audio frames and outputsTranscriptionFrame
sllm
processes text and generatesLLMTextFrame
stts
converts text frames toTTSAudioRawFrame
s andTTSTextFrame
stransport.output()
createsOutputAudioRawFrame
s and sends audio back to user
Frame Propagation
Processors always push frames: Processors don’t consume frames, they pass them along:Parallel Processing Patterns
UseParallelPipeline
to create branches where each branch receives all upstream frames. Frames are collected and pushed individually from each branch:
- Both TTS branches receive all LLM output
- Each branch can filter and process frames independently
- Results from both branches flow to
transport.output()
Frame Queuing and Processing
Frame processors have internal queues that ensure ordered processing:- SystemFrames bypass queues for immediate processing (interruptions, errors)
- DataFrames and ControlFrames are queued and processed in order
- Queuing is managed automatically by the pipeline infrastructure
- Order is guaranteed even across complex pipeline structures
Learn more about frame flow patterns in the Custom Frame Processor
Guide.
Pipeline Execution
Creating a Pipeline Task
Wrap your pipeline in aPipelineTask
to configure execution parameters:
Running the Pipeline
UsePipelineRunner
to execute your pipeline task:
- Lifecycle Management: Handles startup, execution, and cleanup
- Signal Handling: Responds to SIGINT/SIGTERM for graceful shutdown (when
handle_sigint=True
) - Resource Cleanup: Ensures proper disposal of resources when tasks complete
Pipeline Lifecycle
The pipeline runs continuously, processing frames as they arrive, until one of these conditions occurs:- Normal Completion: Bot code returns (session ends)
- Signal Termination: SIGINT or SIGTERM received (if
handle_sigint=True
) - Task Cancellation: Explicit call to
task.cancel()
- Error Condition: Unhandled exception in pipeline
- Starting: Initializing processors and connections
- Running: Actively processing frames and handling events
- Stopping: Gracefully shutting down processors
- Stopped: All resources cleaned up
Configuring Pipeline Behavior
Beyond the basic pipeline structure, you can fine-tune behavior through PipelineParams and add monitoring capabilities:Pipeline Parameters
PipelineParams
lets you configure how your entire pipeline operates:
Monitoring and Observability
Add observers to monitor pipeline events and track custom application metrics:Pipeline Parameters
Configure execution parameters, audio settings, and debugging options
Metrics Guide
Monitor pipeline performance, latency, and API usage in real-time
Observer Pattern
Monitor pipeline events, frame processing, and custom application events
Key Takeaways
- Order matters - arrange processors so each gets the frames it needs
- Processors push frames - processors pass frames downstream, not consume them
- Frame types determine processing - SystemFrames bypass queues, others are ordered
- Queuing ensures reliability - frames are processed in guaranteed order
- Parallel processing enables conditional logic and multi-modal handling
- PipelineTask configures execution parameters and monitoring
- PipelineRunner manages the complete pipeline lifecycle
- PipelineParams control pipeline-wide behavior like audio settings and metrics
What’s Next
Now that you understand how pipelines orchestrate processing, let’s explore the different transport options that connect your pipeline to users.Transports
Learn about the different ways users can connect to your voice AI pipeline