Class LlmAgent
java.lang.Object
com.google.adk.agents.BaseAgent
com.google.adk.agents.LlmAgent
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> maxSteps()model()List<? extends Callbacks.OnModelErrorCallback> List<? extends Callbacks.OnToolErrorCallback> Optional<com.google.genai.types.Schema> booleanplanning()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 BaseAgent
afterAgentCallback, beforeAgentCallback, canonicalAfterAgentCallbacks, canonicalBeforeAgentCallbacks, description, findAgent, findSubAgent, fromConfig, name, parentAgent, parentAgent, rootAgent, runAsync, runLive, subAgents, toolOriginModifier and TypeMethodDescriptioncom.google.common.collect.ImmutableList<? extends Callbacks.AfterAgentCallback> com.google.common.collect.ImmutableList<? extends Callbacks.BeforeAgentCallback> com.google.common.collect.ImmutableList<? extends Callbacks.AfterAgentCallback> The resolved afterAgentCallback field as a list.com.google.common.collect.ImmutableList<? extends Callbacks.BeforeAgentCallback> The resolved beforeAgentCallback field as a list.final StringGets the one-line description of the agent's capability.Finds an agent (this or descendant) by name.findSubAgent(String name) Recursively search sub agent by name.static BaseAgentfromConfig(BaseAgentConfig config, String configAbsPath) Creates a new agent instance from a configuration object.final Stringname()Gets the agent's unique name.Retrieves the parent agent in the agent tree.protected voidparentAgent(BaseAgent parentAgent) Sets the parent agent.Returns the root agent for this agent by traversing up the parent chain.io.reactivex.rxjava3.core.Flowable<Event> runAsync(InvocationContext parentContext) Runs the agent asynchronously.io.reactivex.rxjava3.core.Flowable<Event> runLive(InvocationContext parentContext) Runs the agent synchronously.Returns the origin of the tool when this agent is used as a tool.
-
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
-
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
-
outputSchema
-
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
-