Package com.google.adk.agents
Class ParallelAgent
java.lang.Object
com.google.adk.workflow.BaseNode
com.google.adk.agents.BaseAgent
com.google.adk.agents.ParallelAgent
- All Implemented Interfaces:
Node
A shell agent that runs its sub-agents in parallel in isolated manner.
This approach is beneficial for scenarios requiring multiple perspectives or attempts on a single task, such as running different algorithms simultaneously or generating multiple responses for review by a subsequent evaluation agent.
Composition with LlmAgents: a ParallelAgent does not transfer control
back to a parent LlmAgent. To follow a fan-out with an aggregation step, wrap both in a
SequentialAgent (used as the root or transferred-to agent). Each parallel sub-agent
publishes via outputKey and the aggregator reads via {key} placeholders in its
instruction:
var contacts =
LlmAgent.builder()
.name("contacts")
.model("gemini-flash-latest")
.instruction("List contacts.")
.outputKey("contacts")
.build();
var schedule =
LlmAgent.builder()
.name("schedule")
.model("gemini-flash-latest")
.instruction("List schedule.")
.outputKey("schedule")
.build();
var writer =
LlmAgent.builder()
.name("writer")
.model("gemini-flash-latest")
.instruction("Write: contacts={contacts}, schedule={schedule}")
.build();
var gather =
ParallelAgent.builder().name("gather").subAgents(contacts, schedule).build();
var root = SequentialAgent.builder().name("root").subAgents(gather, writer).build();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic ParallelAgent.Builderbuilder()static ParallelAgentfromConfig(ParallelAgentConfig config, String configAbsPath) Creates a ParallelAgent from configuration.protected io.reactivex.rxjava3.core.Flowable<Event>runAsyncImpl(InvocationContext invocationContext) Runs sub-agents in parallel and emits their events.protected io.reactivex.rxjava3.core.Flowable<Event>runLiveImpl(InvocationContext invocationContext) Not supported for ParallelAgent.Methods inherited from class com.google.adk.agents.BaseAgent
afterAgentCallback, beforeAgentCallback, canonicalAfterAgentCallbacks, canonicalBeforeAgentCallbacks, close, findAgent, findSubAgent, fromConfig, parentAgent, parentAgent, rootAgent, runAsync, runLive, runNode, subAgents, toolOriginMethods inherited from class com.google.adk.workflow.BaseNode
config, description, inputSchema, name, outputSchema, rerunOnResume, 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
-
Method Details
-
builder
-
fromConfig
public static ParallelAgent fromConfig(ParallelAgentConfig config, String configAbsPath) throws ConfigAgentUtils.ConfigurationException Creates a ParallelAgent from configuration.- Parameters:
config- the agent configurationconfigAbsPath- The absolute path to the agent config file.- Returns:
- the configured ParallelAgent
- Throws:
ConfigAgentUtils.ConfigurationException- if the configuration is invalid
-
runAsyncImpl
protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext) Runs sub-agents in parallel and emits their events.Sets the branch and merges event streams from all sub-agents.
- Specified by:
runAsyncImplin classBaseAgent- Parameters:
invocationContext- Invocation context.- Returns:
- Flowable emitting events from all sub-agents.
-
runLiveImpl
protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext) Not supported for ParallelAgent.- Specified by:
runLiveImplin classBaseAgent- Parameters:
invocationContext- Invocation context.- Returns:
- Flowable that always throws UnsupportedOperationException.
-