llm_context_worker

LLM worker with a built-in LLMContext and aggregator pair.

Provides the LLMContextWorker class that extends LLMWorker with a self-contained conversation context, removing the need for subclasses to manually wire LLMContextAggregatorPair.

class pipecat.workers.llm.llm_context_worker.LLMContextWorker(name: str, *, llm: LLMService[Any], active: bool = False, bridged: tuple[str, ...] | None = None, defer_tool_frames: bool = True, context: LLMContext | None = None, user_params: LLMUserAggregatorParams | None = None, assistant_params: LLMAssistantAggregatorParams | None = None)[source]

Bases: LLMWorker

LLM worker that owns an LLMContext and a context aggregator pair.

Useful for workers that need to track their own conversation history, typically workers that run their own LLM pipeline outside of a shared transport pipeline. Subclasses do not need to instantiate the context or aggregators themselves; the pipeline is built as [user_aggregator, llm, assistant_aggregator] automatically.

Example:

worker = LLMContextWorker(
    "worker",
    llm=OpenAILLMService(...),
)

@worker.assistant_aggregator.event_handler("on_assistant_turn_stopped")
async def _on_stopped(aggregator, message):
    ...
__init__(name: str, *, llm: LLMService[Any], active: bool = False, bridged: tuple[str, ...] | None = None, defer_tool_frames: bool = True, context: LLMContext | None = None, user_params: LLMUserAggregatorParams | None = None, assistant_params: LLMAssistantAggregatorParams | None = None)[source]

Initialize the LLMContextWorker.

Parameters:
  • name – Unique name for this worker.

  • llm – The LLM service.

  • active – Whether the worker starts active. Defaults to False.

  • bridged – Bridge configuration forwarded to PipelineWorker. Pass () to wrap the pipeline with bus edges so it can exchange frames with another bridged worker.

  • defer_tool_frames – Whether to defer frames queued during tool execution until all tools complete. Defaults to True.

  • context – Optional pre-built LLMContext. When omitted, a fresh empty context is created.

  • user_params – Optional parameters for the user aggregator.

  • assistant_params – Optional parameters for the assistant aggregator.

property context: LLMContext

The LLMContext owned by this worker.

property user_aggregator: LLMUserAggregator

The user-side context aggregator.

property assistant_aggregator: LLMAssistantAggregator

The assistant-side context aggregator.