Overview
BaseWorker is the abstract base class that all agents inherit from. It handles agent lifecycle, parent-child relationships, bus communication, and job coordination.
A BaseWorker connects to a WorkerBus, registers itself in the shared registry, accepts activation/deactivation, and exchanges job requests/responses with other agents. Agents that need to run a Pipecat pipeline use a concrete subclass like LLMWorker, while BaseWorker itself operates purely through bus messages (e.g. coordinators, orchestrators).
Configuration
Unique name for this agent, used for bus message routing and registry lookup.
If
None, an auto-generated name is used (useful for instances that don’t
participate in inter-agent communication).Whether the agent starts active. When
False, the agent waits for an
activate_worker() call before on_activated fires.Whether to warn about tasks left running when the worker finishes. Only
applies when the worker owns its task manager; a worker sharing the runner’s
task manager leaves the report to the runner.
Optional task manager for handling asyncio tasks.
The bus is not passed in the constructor. It is provided by the runner when
the agent is registered with
WorkerRunner.add_workers(),
which calls attach() internally.Properties
bus
RuntimeError if accessed before attach() has been called.
active
activation_args
None if the agent is inactive. The value is cleared when the agent is deactivated.
parent
None if this is a root agent.
registry
RuntimeError if accessed before attach() has been called.
started_at
None if not yet started.
bridged
False on BaseWorker; subclasses such as PipelineWorker override it.
children
add_workers().
active_jobs
job_id.
job_groups
job_id.
Lifecycle Hooks
Override these methods to react to lifecycle events. Always callsuper() when overriding.
on_activated
on_deactivated
on_worker_ready
watch_workers(). For child agents it fires only on the parent.
on_worker_failed
Agent Management
add_workers
on_worker_ready when each one starts.
activate_worker
on_activated hook will be called with the provided arguments. To hand off (deactivate this agent and activate the target), pass deactivate_self=True.
deactivate_worker
on_deactivated hook will be called.
watch_workers
on_worker_ready fires immediately. Otherwise it fires when the agent eventually registers.
end
cancel
wait
Job Coordination
request_job
on_job_response, on_job_completed) or job() for that.
Returns: The generated
job_id.
job
async for inside the block to receive intermediate events.
Returns: A
JobContext to use with async with.
request_job_group
Returns: The generated
job_id shared by all agents in the group.
job_group
async for inside the block to receive intermediate events.
Returns: A
JobGroupContext to use with async with.
cancel_job_group
request_job_update
send_job_response
send_job_update
send_job_stream_start
send_job_stream_data
send_job_stream_end
create_job_group_and_request_job
group.wait() or use job_group() for that. Used internally by job() and job_group().
Returns: The created JobGroup.
Job Hooks
Override these methods to handle job events. Always callsuper() when overriding.
on_job_request
@job handler. Override to perform work. Use send_job_update() to report progress and send_job_response() to return results.
on_job_response
on_job_update
on_job_update_requested
send_job_update().
on_job_completed
on_job_error
ERROR or FAILED status and cancel_on_error is set.
on_job_stream_start
on_job_stream_data
on_job_stream_end
on_job_cancelled
Bus
send_bus_message
send_bus_error_message
on_bus_message
Decorators
@job
Mark an agent method as a job handler. Decorated methods are automatically collected at initialization and dispatched when matching job requests arrive. Each request runs in its own asyncio task so the bus message loop is never blocked.name argument:
Job name to match. The handler only receives requests with a matching name.
When
True, requests with this name run one at a time in FIFO order. When
False (the default), multiple requests run concurrently. The wait time
counts against the requester’s timeout.BusJobRequestMessage.
@worker_ready
Mark a method as a handler for a specific agent becoming ready. Decorated methods are collected at initialization; when the agent starts, it callswatch_workers for each handler, and the method is called when the watched agent registers.
The name of the agent to watch.
WorkerReadyData instance.