Class SequentialAgent
- All Implemented Interfaces:
Node
Composition with LlmAgents: a SequentialAgent does not transfer control
back to a parent LlmAgent. Use it as the root or transferred-to agent and place any
follow-up LlmAgent as the next sibling. Upstream publishes via outputKey and
downstream reads via {key} placeholders in its instruction:
var draft =
LlmAgent.builder()
.name("draft")
.model("gemini-flash-latest")
.instruction("Draft a summary.")
.outputKey("draft")
.build();
var reviewer =
LlmAgent.builder()
.name("reviewer")
.model("gemini-flash-latest")
.instruction("Polish the draft: {draft}")
.build();
var pipeline =
SequentialAgent.builder().name("pipeline").subAgents(draft, reviewer).build();
Persistence: in BaseAgent.runAsync(InvocationContext), each sub-agent starts only after the Runner
has saved the previous sub-agent's events to the session, so it sees their state changes. An
agent that wraps this one and drops, holds back, buffers or changes the id of those events can
make this agent wait forever; to use its output inside your own agent, run this agent with a
separate Runner and session.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic SequentialAgent.Builderbuilder()static SequentialAgentfromConfig(SequentialAgentConfig config, String configAbsPath) Creates a SequentialAgent from configuration.protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext) Runs sub-agents sequentially.protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext) Runs sub-agents sequentially in live mode.Methods inherited from class BaseAgent
afterAgentCallback, beforeAgentCallback, canonicalAfterAgentCallbacks, canonicalBeforeAgentCallbacks, close, findAgent, findSubAgent, fromConfig, parentAgent, parentAgent, rootAgent, runAsync, runLive, runNode, 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.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.io.reactivex.rxjava3.core.Flowable<Event> runLive(InvocationContext parentContext) Runs the agent synchronously.io.reactivex.rxjava3.core.Flowable<Event> Runs this agent as a workflow node, on the node's branch so the nodes after it see its events.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, validateOutgoingEdges, 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 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.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.
-
Method Details
-
builder
-
runAsyncImpl
protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext) Runs sub-agents sequentially.Three modes: with resumability on, a resume fast-forwards to the checkpointed sub-agent and pauses on a long-running call; with the deprecated shim on, the same happens but the resume point is reconstructed from history and nothing is checkpointed; with neither, sub-agents just run in order.
- Specified by:
runAsyncImplin classBaseAgent- Parameters:
invocationContext- Invocation context.- Returns:
- Flowable emitting events from sub-agents.
-
runLiveImpl
protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext) Runs sub-agents sequentially in live mode.- Specified by:
runLiveImplin classBaseAgent- Parameters:
invocationContext- Invocation context.- Returns:
- Flowable emitting events from sub-agents in live mode.
-
fromConfig
public static SequentialAgent fromConfig(SequentialAgentConfig config, String configAbsPath) throws ConfigAgentUtils.ConfigurationException Creates a SequentialAgent from configuration.- Parameters:
config- the agent configurationconfigAbsPath- The absolute path to the agent config file.- Returns:
- the configured SequentialAgent
- Throws:
ConfigAgentUtils.ConfigurationException- if the configuration is invalid
-