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
str
required
Unique name for this agent.
LLMService
required
The LLM service.
@tool decorated methods are automatically registered on it.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.bool
default:"False"
Whether the agent starts active. Defaults to
False, since LLM agents
typically wait to be activated.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.bool
default:"True"
Whether to defer frames queued from inside a tool handler until all tools
complete. When
True, frames queued via queue_frame() from inside a @tool
method, or from anything that method awaits, are held in an internal queue and
delivered automatically once the last tool finishes. Frames queued from
elsewhere are not deferred.Properties
Inherits all properties fromPipelineWorker.
llm
tool_call_active
True when one or more @tool methods are executing.
Methods
build_tools
@tool. Override to provide additional or different tools.
Returns: List of tool functions.
on_activated
@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
@tool handler, deliver the function call result first with await params.result_callback(result): the output it triggers is delivered before the target is activated. The handover itself waits until the tool call asking for it has finished.
end
@tool handler, deliver the function call result first with await params.result_callback(result): the LLM output it triggers is delivered before the session ends.
queue_frame
@tool handlers, or from anything that handler awaits, is held and delivered once the last tool finishes. Frames from anywhere else are queued immediately: the worker’s own traffic and frames arriving over the bus, which run outside any handler’s context, and frames a handler on a different worker queues here, which this worker would never release.
process_deferred_tool_frames
Returns: The frames to queue. Return the list as-is for default behavior.
Decorators
@tool
Mark anLLMWorker method as an LLM tool. Decorated methods are automatically registered with the LLM and included in build_tools().
Parameters
bool
default:"True"
Whether to cancel this tool call when an interruption occurs.
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 (afterself), 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.