Class BaseAgent
java.lang.Object
com.google.adk.workflow.BaseNode
com.google.adk.agents.BaseAgent
- All Implemented Interfaces:
Node
- Direct Known Subclasses:
LlmAgent, LoopAgent, ParallelAgent, PlannerAgent, RemoteA2AAgent, SequentialAgent
Base class for all agents.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBaseAgent.Builder<B extends BaseAgent.Builder<B>>Base Builder for all agents. -
Constructor Summary
ConstructorsConstructorDescriptionBaseAgent(String name, @Nullable String description, @Nullable List<? extends BaseAgent> subAgents, @Nullable List<? extends Callbacks.BeforeAgentCallback> beforeAgentCallback, @Nullable List<? extends Callbacks.AfterAgentCallback> afterAgentCallback) Creates a new BaseAgent. -
Method Summary
Modifier 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.io.reactivex.rxjava3.core.Completableclose()Closes all sub-agents.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.protected abstract io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext) Agent-specific asynchronous logic.io.reactivex.rxjava3.core.Flowable<Event> runLive(InvocationContext parentContext) Runs the agent synchronously.protected abstract 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 through itsrunAsync(InvocationContext)lifecycle, including its callbacks.Returns the origin of the tool when this agent is used as a tool.Methods inherited from class BaseNode
config, description, inputSchema, name, outputSchema, rerunOnResume, stateSchema, waitForOutputModifier 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.Optional<com.google.genai.types.Schema> Returns the schema the node's input must match.final Stringname()Returns the name that identifies the node within its graph.Optional<com.google.genai.types.Schema> Returns the schema that the node's output value must match.booleanReturnstrueif a resumed node runs again from scratch, rather than completing with the resuming answer as its output.Optional<com.google.genai.types.Schema> Returns the schema declaring the state keys the node uses.booleanReturnstrueif the node stays re-triggerable until it produces an output or a route, instead of completing when its run completes.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
-
BaseAgent
public BaseAgent(String name, @Nullable String description, @Nullable List<? extends BaseAgent> subAgents, @Nullable List<? extends Callbacks.BeforeAgentCallback> beforeAgentCallback, @Nullable List<? extends Callbacks.AfterAgentCallback> afterAgentCallback) Creates a new BaseAgent.- Parameters:
name- Unique agent name. Cannot be "user" (reserved).description- Agent purpose; null is treated as an empty string.subAgents- Agents managed by this agent.beforeAgentCallback- Callbacks before agent execution. Invoked in order until one doesn't return null.afterAgentCallback- Callbacks after agent execution. Invoked in order until one doesn't return null.
-
-
Method Details
-
close
public io.reactivex.rxjava3.core.Completable close()Closes all sub-agents.- Returns:
- a
Completablethat completes when all sub-agents are closed.
-
parentAgent
Retrieves the parent agent in the agent tree.- Returns:
- the parent agent, or
nullif this agent does not have a parent.
-
parentAgent
Sets the parent agent.- Parameters:
parentAgent- The parent agent to set.
-
rootAgent
Returns the root agent for this agent by traversing up the parent chain.- Returns:
- the root agent.
-
findAgent
Finds an agent (this or descendant) by name.- Returns:
- an
Optionalcontaining the agent or descendant with the given name, orOptional.empty()if not found.
-
findSubAgent
Recursively search sub agent by name.- Returns:
- an
Optionalcontaining the sub agent with the given name, orOptional.empty()if not found.
-
subAgents
-
beforeAgentCallback
public com.google.common.collect.ImmutableList<? extends Callbacks.BeforeAgentCallback> beforeAgentCallback() -
afterAgentCallback
public com.google.common.collect.ImmutableList<? extends Callbacks.AfterAgentCallback> afterAgentCallback() -
toolOrigin
Returns the origin of the tool when this agent is used as a tool.- Returns:
- the tool origin, defaults to "BASE_AGENT".
-
canonicalBeforeAgentCallbacks
public com.google.common.collect.ImmutableList<? extends Callbacks.BeforeAgentCallback> canonicalBeforeAgentCallbacks()The resolved beforeAgentCallback field as a list.This method is only for use by Agent Development Kit.
-
canonicalAfterAgentCallbacks
public com.google.common.collect.ImmutableList<? extends Callbacks.AfterAgentCallback> canonicalAfterAgentCallbacks()The resolved afterAgentCallback field as a list.This method is only for use by Agent Development Kit.
-
runAsync
Runs the agent asynchronously.- Parameters:
parentContext- Parent context to inherit.- Returns:
- stream of agent-generated events.
-
runLive
Runs the agent synchronously.- Parameters:
parentContext- Parent context to inherit.- 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 through itsrunAsync(InvocationContext)lifecycle, including its callbacks. The node input is not used. -
runAsyncImpl
protected abstract io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext) Agent-specific asynchronous logic.- Parameters:
invocationContext- Current invocation context.- Returns:
- stream of agent-generated events.
-
runLiveImpl
protected abstract io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext) Agent-specific synchronous logic.- Parameters:
invocationContext- Current invocation context.- Returns:
- stream of agent-generated events.
-
fromConfig
Creates a new agent instance from a configuration object.- Parameters:
config- Agent configuration.configAbsPath- Absolute path to the configuration file.- Returns:
- new agent instance.
-