Class LlmAgent
- All Implemented Interfaces:
Node
-
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.static booleandelegatesTask(BaseTool tool) Returns whethertooldelegates a task to aAgentMode.TASKsub-agent, whose response the delegating agent gives once the task ends.protected BaseLlmFlowbooleanbooleanstatic booleanendsTaskWithError(Event event) Returns whethereventreports an execution error of a task's run, such as a failure, rather than an error code a model gave as its finish or block reason.executor()static booleanfinishesTask(Event event) Returns whethereventends a task with its ownfinish_taskcall that succeeded: one the task agent answered, not the user or an agent it transferred to.static LlmAgentfromConfig(LlmAgentConfig config, String configAbsPath) Creates an LlmAgent from configuration with full subagent support.Optional<com.google.genai.types.GenerateContentConfig> booleanReturns whether this agent's own mode isexpected.Returns the configured history setting,LlmAgent.IncludeContents.DEFAULTwhen unset.booleanReturns whetherLlmAgent.Builder.includeContents(IncludeContents)was set, which aSINGLE_TURNworkflow node then uses instead of running without history.Optional<com.google.genai.types.Schema> Returns the schema the node's input must match.booleanReturns whether this agent runs as aAgentMode.CHATworkflow node, either set or because another agent in its tree sets a mode.static booleanisFinishTaskTool(Object tool) Returns whethertoolis thefinish_tasktool a task agent gets.maxSteps()mode()Returns how this agent converses when it runs as a workflow node, or empty without a mode.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.io.reactivex.rxjava3.core.Flowable<Event> Runs this agent as a workflow node: aAgentMode.SINGLE_TURNagent takes the node input as its user turn and gives the first final reply, its own or its inline target's, as output; aAgentMode.TASKagent works untilfinish_tasksucceeds, failing withStateSchemaExceptionif the node's state schema rejects itsoutputKey()write; and aAgentMode.CHATagent runs the tasks it delegates and stays open (waitForOutput()).static booleanrunsAsTask(BaseAgent agent, InvocationContext context) Returns whetheragentruns as aAgentMode.TASKworkflow node incontext, so it ends its task withfinish_task.static booleanrunsAsTool(BaseAgent agent) Returns whetheragentis aAgentMode.SINGLE_TURNorAgentMode.TASKagent, which its parent calls as a tool rather than transfers to.tools()toolsets()Returns the configured tools and toolsets, thenfinish_taskfor aAgentMode.TASKagent, then one tool perAgentMode.TASKorAgentMode.SINGLE_TURNsub-agent.com.google.common.collect.ImmutableList<BaseAgent> Returns the agents this one may transfer to: its sub-agents, plus its parent and peers unless disallowed, in the order the model sees them.com.google.common.collect.ImmutableList<BaseAgent> transferTargets(InvocationContext context) Returns the agents this one may transfer to incontext.booleanReturnstruefor aAgentMode.CHATorAgentMode.TASKagent, whose node stays open across turns until it produces an output.Methods inherited from class BaseAgent
afterAgentCallback, beforeAgentCallback, canonicalAfterAgentCallbacks, canonicalBeforeAgentCallbacks, findAgent, findSubAgent, fromConfig, 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.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.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.Methods inherited from class BaseNode
config, description, name, stateSchema, validateOutgoingEdgesModifier and TypeMethodDescriptionconfig()Returns the node's retry policy and execution timeout.Returns what the node does, for humans and for a model that may call it.final Stringname()Returns the name that identifies the node within its graph.Optional<com.google.genai.types.Schema> Returns the schema of the state keys that the node and its children may write; a child inherits it unless it declares its own.protected voidvalidateOutgoingEdges(Collection<Edge> edges) ThrowsGraphValidationExceptionif this node cannot serve theedgesthat leave it, such as an edge for a route it never emits.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Node
requiresAllPredecessorsModifier and TypeMethodDescriptiondefault booleanReturnstrueif the node runs only once every predecessor has completed, receiving all their outputs keyed by node name, as a fan-in node does.
-
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.
-
runNode
@Experimental public io.reactivex.rxjava3.core.Flowable<Event> runNode(Context context, @Nullable Object nodeInput) Runs this agent as a workflow node: aAgentMode.SINGLE_TURNagent takes the node input as its user turn and gives the first final reply, its own or its inline target's, as output; aAgentMode.TASKagent works untilfinish_tasksucceeds, failing withStateSchemaExceptionif the node's state schema rejects itsoutputKey()write; and aAgentMode.CHATagent runs the tasks it delegates and stays open (waitForOutput()). The flow of a chat or task agent stops at a handoff, and the workflow runs the target as a node, or fails the run if the handoff is invalid. Any other agent runs asBaseAgent.runNode(Context, Object)runs it. -
waitForOutput
Returnstruefor aAgentMode.CHATorAgentMode.TASKagent, whose node stays open across turns until it produces an output. An agent without a mode is a chat agent when another agent in its tree sets a mode.- Specified by:
waitForOutputin interfaceNode- Overrides:
waitForOutputin classBaseNode
-
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
Returns the configured history setting,LlmAgent.IncludeContents.DEFAULTwhen unset. ASINGLE_TURNworkflow node overrides an unset one; seeincludeContentsExplicit(). -
includeContentsExplicit
Returns whetherLlmAgent.Builder.includeContents(IncludeContents)was set, which aSINGLE_TURNworkflow node then uses instead of running without history.This method is only for use by Agent Development Kit.
-
mode
Returns how this agent converses when it runs as a workflow node, or empty without a mode. -
hasMode
Returns whether this agent's own mode isexpected.This method is only for use by Agent Development Kit.
-
isChatNode
Returns whether this agent runs as aAgentMode.CHATworkflow node, either set or because another agent in its tree sets a mode.This method is only for use by Agent Development Kit.
-
runsAsTask
Returns whetheragentruns as aAgentMode.TASKworkflow node incontext, so it ends its task withfinish_task. A task agent run any other way runs as an agent without a mode does.This method is only for use by Agent Development Kit.
-
isFinishTaskTool
Returns whethertoolis thefinish_tasktool a task agent gets.This method is only for use by Agent Development Kit.
-
runsAsTool
Returns whetheragentis aAgentMode.SINGLE_TURNorAgentMode.TASKagent, which its parent calls as a tool rather than transfers to.This method is only for use by Agent Development Kit.
-
finishesTask
Returns whethereventends a task with its ownfinish_taskcall that succeeded: one the task agent answered, not the user or an agent it transferred to.This method is only for use by Agent Development Kit.
-
endsTaskWithError
Returns whethereventreports an execution error of a task's run, such as a failure, rather than an error code a model gave as its finish or block reason.This method is only for use by Agent Development Kit.
-
delegatesTask
Returns whethertooldelegates a task to aAgentMode.TASKsub-agent, whose response the delegating agent gives once the task ends.This method is only for use by Agent Development Kit.
-
tools
-
toolsUnion
Returns the configured tools and toolsets, thenfinish_taskfor aAgentMode.TASKagent, then one tool perAgentMode.TASKorAgentMode.SINGLE_TURNsub-agent. -
toolsets
-
disallowTransferToParent
public boolean disallowTransferToParent() -
disallowTransferToPeers
public boolean disallowTransferToPeers() -
transferTargets
Returns the agents this one may transfer to: its sub-agents, plus its parent and peers unless disallowed, in the order the model sees them. Transfer to a parent or peer needs anLlmAgentparent, and an agent its parent calls as a tool is no transfer target.This method is only for use by Agent Development Kit.
-
transferTargets
@Experimental public com.google.common.collect.ImmutableList<BaseAgent> transferTargets(InvocationContext context) Returns the agents this one may transfer to incontext. Outside a workflow a single-turn agent cannot run as a tool, so it stays a transfer target, as before modes.This method is only for use by Agent Development Kit.
-
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. An edge into the node fails at build when its source's output schema lists a key or type this one rejects, so an open producer such as a map builds, and aFunctionNodeon aContentport checks the edge against theContentschema. A node that requires all predecessors applies it to each predecessor's output, not the joined map. A run checks a node's schemas only for type,nullable,enum,anyOf,properties,requiredanditems; it ignoresminimum,maximum,pattern, lengths andformat.- 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. A run checks a record, POJO or enum input or output in its JSON form and hands on that form: a map for a record, the name for an enum.- 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
-