Skip to main content

Overview

LLMWorker extends PipelineWorker with an LLM pipeline and automatic tool registration. Pass an LLMService to the constructor and define tools with the @tool decorator. Decorated methods are registered as direct functions on the LLM and tracked so frames queued during tool execution can be deferred until all tools complete.

Configuration

name
str
required
Unique name for this agent.
llm
LLMService
required
The LLM service. @tool decorated methods are automatically registered on it.
pipeline
Pipeline | None
default:"None"
Optional pipeline override. When None, defaults to Pipeline([llm]). Subclasses can pass a custom pipeline that wraps the LLM with additional processors.
active
bool
default:"False"
Whether the agent starts active. Defaults to False, since LLM agents typically wait to be activated.
bridged
tuple[str, ...] | None
default:"None"
Bridge configuration forwarded to PipelineWorker. Pass () to wrap the LLM pipeline with bus edge processors so it can exchange frames with another bridged agent. See PipelineWorker for details.
defer_tool_frames
bool
default:"True"
Whether to defer frames queued during tool execution until all tools complete. When True, any frames queued via queue_frame() while a @tool method is running are held in an internal queue and delivered automatically once the last tool finishes.

Properties

Inherits all properties from PipelineWorker.

llm

The LLM service this agent wraps.

tool_call_active

True when one or more @tool methods are executing.

Methods

build_tools

Return the tools for this agent’s LLM. By default, returns all methods decorated with @tool. Override to provide additional or different tools. Returns: List of tool functions.

on_activated

Configure the LLM with tools and activation messages. The decorated @tool methods are set on the LLM. When args contains messages, they are appended to the LLM context. When args contains run_llm (defaults to True when messages are set), the LLM is triggered after appending.

activate_worker

Activate another agent, optionally finishing an in-progress tool call. When called from a @tool handler, pass params.result_callback to ensure any pending LLM output is fully delivered before the target is activated. To hand off (deactivate this agent and activate the target), pass deactivate_self=True.

end

Request a graceful end of the session. When called from a @tool handler, pass params.result_callback to ensure any pending LLM output is fully delivered before ending.

queue_frame

Queue a frame, deferring delivery until all tools complete (if any). When tool calls are in progress, the frame is held in an internal queue and delivered automatically once the last tool finishes. When no tools are active, the frame is queued immediately.

process_deferred_tool_frames

Process deferred frames before they are flushed. Called after all in-flight tools complete, before the deferred frames are queued into the pipeline. Override to inspect, modify, reorder, or filter the frames. Returns: The frames to queue. Return the list as-is for default behavior.

Decorators

@tool

Mark an LLMWorker method as an LLM tool. Decorated methods are automatically registered with the LLM and included in build_tools().
Can be used with or without arguments:

Parameters

cancel_on_interruption
bool
default:"True"
Whether to cancel this tool call when an interruption occurs.
timeout
float | None
default:"None"
Timeout in seconds for this tool call. Defaults to None (uses the LLM service default).

Method signature

Tool methods receive the LLM function call parameters object as their first argument (after self), followed by the tool’s declared parameters:
Tool methods must call params.result_callback() to return a result to the LLM. The method signature (parameter names, types, and docstring) is automatically used to generate the tool schema.