Package com.google.adk.agents
Class LlmAgent
java.lang.Object
com.google.adk.workflow.BaseNode
com.google.adk.agents.BaseAgent
com.google.adk.agents.LlmAgent
- All Implemented Interfaces:
Node
The LLM-based agent.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder forLlmAgent.static enumEnum to define if contents of previous events should be included in requests to the underlying LLM. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionList<? extends Callbacks.AfterModelCallback>List<? extends Callbacks.AfterToolCallback>List<? extends Callbacks.BeforeModelCallback>List<? extends Callbacks.BeforeToolCallback>static LlmAgent.Builderbuilder()Returns aLlmAgent.BuilderforLlmAgent.List<? extends Callbacks.AfterModelCallback>The resolved afterModelCallback field as a list.List<? extends Callbacks.AfterToolCallback>The resolved afterToolCallback field as a list.List<? extends Callbacks.BeforeModelCallback>The resolved beforeModelCallback field as a list.List<? extends Callbacks.BeforeToolCallback>The resolved beforeToolCallback field as a list.Constructs the text global instruction for this agent based on theglobalInstructionfield.canonicalInstruction(ReadonlyContext context) Constructs the text instruction for this agent based on theinstructionfield.List<? extends Callbacks.OnModelErrorCallback>The resolved onModelErrorCallback field as a list.List<? extends Callbacks.OnToolErrorCallback>The resolved onToolErrorCallback field as a list.io.reactivex.rxjava3.core.Flowable<BaseTool>Constructs the list of tools for this agent based on thetools()field.io.reactivex.rxjava3.core.Flowable<BaseTool>canonicalTools(@Nullable ReadonlyContext context) Constructs the list of tools for this agent based on thetools()field.io.reactivex.rxjava3.core.Completableclose()Closes all sub-agents.protected BaseLlmFlowbooleanbooleanexecutor()static LlmAgentfromConfig(LlmAgentConfig config, String configAbsPath) Creates an LlmAgent from configuration with full subagent support.Optional<com.google.genai.types.GenerateContentConfig>Optional<com.google.genai.types.Schema>Returns the schema the node's input must match.maxSteps()model()List<? extends Callbacks.OnModelErrorCallback>List<? extends Callbacks.OnToolErrorCallback>Optional<com.google.genai.types.Schema>Returns the schema that the node's output value must match.booleanplanning()booleanReturnstrue, so that a workflow resuming this agent as a node runs it again and its model sees the answers to its long-running calls.protected io.reactivex.rxjava3.core.Flowable<Event>runAsyncImpl(InvocationContext invocationContext) Agent-specific asynchronous logic.protected io.reactivex.rxjava3.core.Flowable<Event>runLiveImpl(InvocationContext invocationContext) Agent-specific synchronous logic.tools()toolsets()Methods inherited from class com.google.adk.agents.BaseAgent
afterAgentCallback, beforeAgentCallback, canonicalAfterAgentCallbacks, canonicalBeforeAgentCallbacks, findAgent, findSubAgent, fromConfig, parentAgent, parentAgent, rootAgent, runAsync, runLive, runNode, subAgents, toolOriginMethods inherited from class com.google.adk.workflow.BaseNode
config, description, name, stateSchema, waitForOutputMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.google.adk.workflow.Node
requiresAllPredecessors
-
Constructor Details
-
LlmAgent
-
-
Method Details
-
builder
Returns aLlmAgent.BuilderforLlmAgent. -
determineLlmFlow
-
runAsyncImpl
protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext) Description copied from class:BaseAgentAgent-specific asynchronous logic.- Specified by:
runAsyncImplin classBaseAgent- Parameters:
invocationContext- Current invocation context.- Returns:
- stream of agent-generated events.
-
runLiveImpl
protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext) Description copied from class:BaseAgentAgent-specific synchronous logic.- Specified by:
runLiveImplin classBaseAgent- Parameters:
invocationContext- Current invocation context.- Returns:
- stream of agent-generated events.
-
canonicalInstruction
public io.reactivex.rxjava3.core.Single<Map.Entry<String,Boolean>> canonicalInstruction(ReadonlyContext context) Constructs the text instruction for this agent based on theinstructionfield. Also returns a boolean indicating that state injection should be bypassed when the instruction is constructed with anInstruction.Provider.This method is only for use by Agent Development Kit.
- Parameters:
context- The context to retrieve the session state.- Returns:
- The resolved instruction as a
Singlewrapped Map.Entry. The key is the instruction string and the value is a boolean indicating if state injection should be bypassed.
-
canonicalGlobalInstruction
public io.reactivex.rxjava3.core.Single<Map.Entry<String,Boolean>> canonicalGlobalInstruction(ReadonlyContext context) Constructs the text global instruction for this agent based on theglobalInstructionfield. Also returns a boolean indicating that state injection should be bypassed when the instruction is constructed with anInstruction.Provider.This method is only for use by Agent Development Kit.
- Parameters:
context- The context to retrieve the session state.- Returns:
- The resolved global instruction as a
Singlewrapped Map.Entry. The key is the instruction string and the value is a boolean indicating if state injection should be bypassed.
-
canonicalTools
Constructs the list of tools for this agent based on thetools()field.- Returns:
- The resolved list of tools as a
Singlewrapped list ofBaseTool.
-
canonicalTools
public io.reactivex.rxjava3.core.Flowable<BaseTool> canonicalTools(@Nullable ReadonlyContext context) Constructs the list of tools for this agent based on thetools()field.- Parameters:
context- The context to retrieve the session state.- Returns:
- The resolved list of tools as a
Singlewrapped list ofBaseTool.
-
instruction
-
globalInstruction
-
model
-
planning
public boolean planning() -
maxSteps
-
generateContentConfig
-
includeContents
-
tools
-
toolsUnion
-
toolsets
-
disallowTransferToParent
public boolean disallowTransferToParent() -
disallowTransferToPeers
public boolean disallowTransferToPeers() -
beforeModelCallback
-
afterModelCallback
-
beforeToolCallback
-
afterToolCallback
-
onModelErrorCallback
-
onToolErrorCallback
-
canonicalBeforeModelCallbacks
The resolved beforeModelCallback field as a list.This method is only for use by Agent Development Kit.
-
canonicalAfterModelCallbacks
The resolved afterModelCallback field as a list.This method is only for use by Agent Development Kit.
-
canonicalOnModelErrorCallbacks
The resolved onModelErrorCallback field as a list.This method is only for use by Agent Development Kit.
-
canonicalBeforeToolCallbacks
The resolved beforeToolCallback field as a list.This method is only for use by Agent Development Kit.
-
canonicalAfterToolCallbacks
The resolved afterToolCallback field as a list.This method is only for use by Agent Development Kit.
-
canonicalOnToolErrorCallbacks
The resolved onToolErrorCallback field as a list.This method is only for use by Agent Development Kit.
-
inputSchema
Description copied from interface:NodeReturns the schema the node's input must match.- Specified by:
inputSchemain interfaceNode- Overrides:
inputSchemain classBaseNode
-
outputSchema
Description copied from interface:NodeReturns the schema that the node's output value must match. The content of a message-as-output event is not checked against this schema.- Specified by:
outputSchemain interfaceNode- Overrides:
outputSchemain classBaseNode
-
rerunOnResume
Returnstrue, so that a workflow resuming this agent as a node runs it again and its model sees the answers to its long-running calls.- Specified by:
rerunOnResumein interfaceNode- Overrides:
rerunOnResumein classBaseNode
-
executor
-
outputKey
-
codeExecutor
-
resolvedModel
-
fromConfig
public static LlmAgent fromConfig(LlmAgentConfig config, String configAbsPath) throws ConfigAgentUtils.ConfigurationException Creates an LlmAgent from configuration with full subagent support.- Parameters:
config- the agent configurationconfigAbsPath- The absolute path to the agent config file. This is needed for resolving relative paths for e.g. tools and subagents.- Returns:
- the configured LlmAgent
- Throws:
ConfigAgentUtils.ConfigurationException- if the configuration is invalid
-
close
public io.reactivex.rxjava3.core.Completable close()Description copied from class:BaseAgentCloses all sub-agents.
-