LlmAgent class

Core LLM agent that drives model and tool orchestration flows.

Inheritance

Constructors

LlmAgent({required String name, String description = '', List<BaseAgent>? subAgents, Object? beforeAgentCallback, Object? afterAgentCallback, Object model = '', Object instruction = '', Object globalInstruction = '', Object? staticInstruction, List<Object>? tools, GenerateContentConfig? generateContentConfig, bool disallowTransferToParent = false, bool disallowTransferToPeers = false, String includeContents = 'default', Object? inputSchema, Object? outputSchema, String? outputKey, Object? planner, Object? codeExecutor, Object? beforeModelCallback, Object? afterModelCallback, Object? onModelErrorCallback, Object? beforeToolCallback, Object? afterToolCallback, Object? onToolErrorCallback})
Creates an LLM agent.

Properties

afterAgentCallback Object?
Callback(s) invoked after agent execution.
getter/setter pairinherited
afterModelCallback Object?
After-model callback(s).
getter/setter pair
afterToolCallback Object?
After-tool callback(s).
getter/setter pair
beforeAgentCallback Object?
Callback(s) invoked before agent execution.
getter/setter pairinherited
beforeModelCallback Object?
Before-model callback(s).
getter/setter pair
beforeToolCallback Object?
Before-tool callback(s).
getter/setter pair
canonicalAfterAgentCallbacks List<AgentLifecycleCallback>
Canonical after-agent callbacks.
no setterinherited
canonicalAfterModelCallbacks List<AfterModelCallback>
Canonical after-model callbacks.
no setter
canonicalAfterToolCallbacks List<AfterToolCallback>
Canonical after-tool callbacks.
no setter
canonicalBeforeAgentCallbacks List<AgentLifecycleCallback>
Canonical before-agent callbacks.
no setterinherited
canonicalBeforeModelCallbacks List<BeforeModelCallback>
Canonical before-model callbacks.
no setter
canonicalBeforeToolCallbacks List<BeforeToolCallback>
Canonical before-tool callbacks.
no setter
canonicalModel BaseLlm
Canonical BaseLlm resolved from local, ancestor, or default config.
no setter
canonicalOnModelErrorCallbacks List<OnModelErrorCallback>
Canonical model-error callbacks.
no setter
canonicalOnToolErrorCallbacks List<OnToolErrorCallback>
Canonical tool-error callbacks.
no setter
codeExecutor Object?
Optional code-execution backend.
getter/setter pair
description String
Human-readable description.
getter/setter pairinherited
disallowTransferToParent bool
Whether transfers to parent agents are disallowed.
getter/setter pair
disallowTransferToPeers bool
Whether transfers to peer agents are disallowed.
getter/setter pair
generateContentConfig GenerateContentConfig?
Additional generation configuration.
getter/setter pair
globalInstruction Object
Global instruction as text or InstructionProvider.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
includeContents String
Content inclusion mode for prompts and responses.
getter/setter pair
inputSchema Object?
Optional input schema.
getter/setter pair
instruction Object
Primary instruction as text or InstructionProvider.
getter/setter pair
llmFlow → BaseLlmFlow
LLM flow implementation selected from transfer constraints.
no setter
model Object
Model configuration as a model name or BaseLlm.
getter/setter pair
name String
Agent name.
getter/setter pairinherited
onModelErrorCallback Object?
Model-error callback(s).
getter/setter pair
onToolErrorCallback Object?
Tool-error callback(s).
getter/setter pair
outputKey String?
Optional state key to store final response output.
getter/setter pair
outputSchema Object?
Optional output schema.
getter/setter pair
parentAgent BaseAgent?
Parent agent in the hierarchy, if any.
getter/setter pairinherited
planner Object?
Optional planner implementation.
getter/setter pair
rootAgent BaseAgent
The top-most ancestor in this agent hierarchy.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
staticInstruction Object?
Optional static instruction payload.
getter/setter pair
subAgents List<BaseAgent>
Child agents that this agent may delegate to.
getter/setter pairinherited
tools List<Object>
Tool/toolset/function unions used by this agent.
getter/setter pair

Methods

canonicalGlobalInstruction(ReadonlyContext context) Future<(String, bool)>
Resolves global instruction text and whether it was dynamic.
canonicalInstruction(ReadonlyContext context) Future<(String, bool)>
Resolves primary instruction text and whether it was dynamic.
canonicalTools([ReadonlyContext? context]) Future<List<BaseTool>>
Resolves configured tools into canonical BaseTool instances.
clone({Map<String, Object?>? update}) LlmAgent
Returns a cloned LLM agent with optional field overrides.
override
cloneFieldValue<T>({required Map<String, Object?> update, required String fieldName, required T currentValue}) → T
Reads typed field overrides for clone operations.
inherited
cloneListFieldValue<T>({required Map<String, Object?> update, required String fieldName, required List<T> currentValue}) List<T>
Reads list field overrides for clone operations.
inherited
cloneObjectFieldValue({required Map<String, Object?> update, required String fieldName, required Object? currentValue}) Object?
Reads object field overrides while preserving list copy semantics.
inherited
cloneSubAgentsField(Map<String, Object?> update) List<BaseAgent>
Resolves cloned sub-agent lists from update or existing sub-agents.
inherited
createAgentStateEvent(InvocationContext context) Event
Creates an event containing this agent's latest serialized state.
inherited
createInvocationContext(InvocationContext parentContext) InvocationContext
Creates a child invocation context for this agent.
inherited
findAgent(String targetName) BaseAgent?
Finds an agent named targetName in this subtree.
inherited
findSubAgent(String targetName) BaseAgent?
Finds a descendant agent named targetName.
inherited
loadAgentState(InvocationContext context) BaseAgentState?
Loads this agent's serialized state from context, if present.
inherited
normalizeCloneUpdate(Map<String, Object?>? update) Map<String, Object?>
Normalizes clone update maps into mutable JSON-like maps.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
relinkClonedSubAgents(BaseAgent clonedAgent) → void
Re-links parent pointers for clonedAgent and its sub-agents.
inherited
runAsync(InvocationContext parentContext) Stream<Event>
Runs the agent asynchronously with lifecycle callbacks.
inherited
runAsyncImpl(InvocationContext context) Stream<Event>
Runs async LLM flow execution for this agent.
override
runLive(InvocationContext parentContext) Stream<Event>
Runs the agent in live mode with lifecycle callbacks.
inherited
runLiveImpl(InvocationContext context) Stream<Event>
Runs live LLM flow execution for this agent.
override
toString() String
A string representation of this object.
inherited
validateCloneUpdateFields({required Map<String, Object?> update, required Set<String> allowedFields}) → void
Validates clone-update update keys against allowedFields.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

setDefaultModel(Object model) → void
Sets the process-wide default model.

Constants

defaultModel → const String
Built-in default model name.