Overview
PipelineTask is the central class for managing pipeline execution. It handles the lifecycle of the pipeline, processes frames in both directions, manages task cancellation, and provides event handlers for monitoring pipeline activity.
Basic Usage
Constructor Parameters
The pipeline to execute.
Configuration parameters for the pipeline. See
PipelineParams for details.
List of observers for monitoring pipeline execution. See
Observers for details.
Clock implementation for timing operations.
Custom task manager for handling asyncio tasks. If None, a default TaskManager
is used.
Whether to check for processors’ tasks finishing properly.
Timeout in seconds before considering the pipeline idle. Set to None to
disable idle detection. See Pipeline Idle
Detection for details.
Frame types that should prevent the pipeline from being considered idle. See
Pipeline Idle Detection for
details.
Whether to automatically cancel the pipeline task when idle timeout is
reached. See Pipeline Idle
Detection for details.
Whether to enable OpenTelemetry tracing. See The OpenTelemetry
guide for details.
Whether to enable turn tracking. See The OpenTelemetry
guide for details.
Custom ID for the conversation. If not provided, a UUID will be generated. See
The OpenTelemetry guide for details.
Any additional attributes to add to top-level OpenTelemetry conversation span.
See The OpenTelemetry guide for details.
Methods
Task Lifecycle Management
Starts and manages the pipeline execution until completion or cancellation.
Sends an EndFrame to the pipeline to gracefully stop the task after all queued
frames have been processed.
Stops the running pipeline immediately by sending a CancelFrame.
Returns whether the task has finished (all processors have stopped).
Frame Management
Queues a single frame to be pushed down the pipeline.
Queues multiple frames to be pushed down the pipeline.
Event Handlers
PipelineTask provides event handlers for monitoring pipeline lifecycle and frame flow. Register handlers using the@event_handler decorator.
| Event | Description |
|---|---|
on_pipeline_started | Pipeline has started processing |
on_pipeline_finished | Pipeline reached a terminal state |
on_pipeline_error | An error frame reached the pipeline task |
on_frame_reached_upstream | A filtered frame type reached the pipeline source |
on_frame_reached_downstream | A filtered frame type reached the pipeline sink |
on_idle_timeout | No activity detected within the idle timeout period |
on_pipeline_started
Fired when theStartFrame has been processed by all processors in the pipeline. This indicates the pipeline is fully initialized and running.
| Parameter | Type | Description |
|---|---|---|
task | PipelineTask | The pipeline task instance |
frame | StartFrame | The start frame that was processed |
on_pipeline_finished
Fired after the pipeline reaches any terminal state. This includes normal completion (EndFrame), explicit stop (StopFrame), or cancellation (CancelFrame). Use this event for cleanup, logging, or post-processing.
| Parameter | Type | Description |
|---|---|---|
task | PipelineTask | The pipeline task instance |
frame | Frame | The terminal frame (EndFrame, StopFrame, or CancelFrame) |
The deprecated events
on_pipeline_ended, on_pipeline_stopped, and on_pipeline_cancelled still work but will emit a deprecation warning. Use on_pipeline_finished and inspect the frame type if you need to distinguish between terminal states.on_pipeline_error
Fired when anErrorFrame reaches the pipeline task (upstream from a processor). If the error is fatal, the pipeline will be cancelled after this handler runs.
| Parameter | Type | Description |
|---|---|---|
task | PipelineTask | The pipeline task instance |
frame | ErrorFrame | The error frame with error details |
on_frame_reached_upstream
Fired when a frame of a registered type reaches the pipeline source (the start of the pipeline). You must configure which frame types trigger this event usingset_reached_upstream_filter() or add_reached_upstream_filter().
| Parameter | Type | Description |
|---|---|---|
task | PipelineTask | The pipeline task instance |
frame | Frame | The frame that reached the pipeline source |
This event only fires for frame types you’ve explicitly registered. By default, no frame types are monitored. This is for efficiency — checking every frame would be wasteful when you typically only care about specific types.
on_frame_reached_downstream
Fired when a frame of a registered type reaches the pipeline sink (the end of the pipeline). You must configure which frame types trigger this event usingset_reached_downstream_filter() or add_reached_downstream_filter().
| Parameter | Type | Description |
|---|---|---|
task | PipelineTask | The pipeline task instance |
frame | Frame | The frame that reached the pipeline sink |
on_idle_timeout
Fired when no activity frames (as specified byidle_timeout_frames) have been received within the idle timeout period. See Pipeline Idle Detection for configuration details.
| Parameter | Type | Description |
|---|---|---|
task | PipelineTask | The pipeline task instance |
If
cancel_on_idle_timeout is True (the default), the pipeline will be automatically cancelled after this handler runs. Set it to False if you want to handle idle timeouts yourself.