Skip to main content

Overview

PipelineWorker 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.
PipelineWorker builds on BaseWorker, so it can take part in a multi-worker system. See Workers for the full worker model. PipelineTask is a deprecated alias for PipelineWorker; existing code that uses it keeps working.

Basic Usage

Constructor Parameters

BasePipeline
required
The pipeline to execute.
PipelineParams
default:"PipelineParams()"
Configuration parameters for the pipeline. See PipelineParams for details.
List[BaseObserver]
default:"[]"
List of observers for monitoring pipeline execution. See Observers for details.
BaseClock
default:"SystemClock()"
Clock implementation for timing operations.
BaseTaskManager | None
default:"None"
Custom task manager for handling asyncio tasks. If None, a default TaskManager is used.
bool
default:"True"
Whether to check for processors’ tasks finishing properly.
float | None
default:"300"
Timeout in seconds before considering the pipeline idle. Set to None to disable idle detection. See Pipeline Idle Detection for details.
Tuple[Type[Frame], ...]
default:"(BotSpeakingFrame, UserSpeakingFrame)"
Frame types that should prevent the pipeline from being considered idle. See Pipeline Idle Detection for details.
bool
default:"True"
Whether to automatically cancel the pipeline task when idle timeout is reached. See Pipeline Idle Detection for details.
bool
default:"False"
Whether to enable OpenTelemetry tracing. See The OpenTelemetry guide for details.
bool
default:"True"
Whether to enable turn tracking. See The OpenTelemetry guide for details.
str | None
default:"None"
Custom ID for the conversation. If not provided, a UUID will be generated. See The OpenTelemetry guide for details.
dict | None
default:"None"
Any additional attributes to add to top-level OpenTelemetry conversation span. See The OpenTelemetry guide for details.
Any
default:"None"
Application-defined bag of resources (database handles, API clients, state, etc.) shared across tool handlers. Passed by reference to every function handler via FunctionCallParams.app_resources. The framework never copies or clears this object; the caller retains their handle and can read mutations after the task finishes.
Any
default:"None"
Deprecated alias for app_resources. Use app_resources in new code.

Methods

Task Lifecycle Management

async
Starts and manages the pipeline execution until completion or cancellation. Typically called via WorkerRunner rather than directly:
async
Sends an EndFrame to the pipeline to gracefully stop the task after all queued frames have been processed.
async
Stops the running pipeline immediately by sending a CancelFrame.
bool
Returns whether the task has finished (all processors have stopped).

Frame Management

async
Queues a single frame to be pushed through the pipeline.Downstream frames are pushed from the beginning of the pipeline. Upstream frames are pushed from the end of the pipeline.Parameters:
async
Queues multiple frames to be pushed through the pipeline.Downstream frames are pushed from the beginning of the pipeline. Upstream frames are pushed from the end of the pipeline.Parameters:

Event Handlers

PipelineWorker provides event handlers for monitoring pipeline lifecycle and frame flow. Register handlers using the @event_handler decorator.

on_pipeline_started

Fired when the StartFrame has been processed by all processors in the pipeline. This indicates the pipeline is fully initialized and running.
Parameters:

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.
Parameters:

on_pipeline_error

Fired when an ErrorFrame reaches the pipeline task (upstream from a processor). If the error is fatal, the pipeline will be cancelled after this handler runs.
Parameters:

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 using set_reached_upstream_filter() or add_reached_upstream_filter().
Parameters:
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 using set_reached_downstream_filter() or add_reached_downstream_filter().
Parameters:

on_idle_timeout

Fired when no activity frames (as specified by idle_timeout_frames) have been received within the idle timeout period. See Pipeline Idle Detection for configuration details.
Parameters:
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.