File tree Expand file tree Collapse file tree
core/src/main/java/com/google/adk/agents Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030 *
3131 * <p>The loop continues until a sub-agent escalates, or until the maximum number of iterations is
3232 * reached (if specified).
33+ *
34+ * <p><b>Composition:</b> a {@code LoopAgent} does not transfer control back to a parent {@link
35+ * LlmAgent}, so an LlmAgent orchestrator that transfers to a {@code LoopAgent} cannot react to the
36+ * loop's results afterwards. To run a loop and then react to its result, place the {@code
37+ * LoopAgent} and the follow-up agent as siblings inside a {@link SequentialAgent} (used as the root
38+ * or transferred-to agent).
3339 */
3440public class LoopAgent extends BaseAgent {
3541 private static final Logger logger = LoggerFactory .getLogger (LoopAgent .class );
Original file line number Diff line number Diff line change 3434 * <p>This approach is beneficial for scenarios requiring multiple perspectives or attempts on a
3535 * single task, such as running different algorithms simultaneously or generating multiple responses
3636 * for review by a subsequent evaluation agent.
37+ *
38+ * <p><b>Composition:</b> a {@code ParallelAgent} does not transfer control back to a parent {@link
39+ * LlmAgent}, so an LlmAgent orchestrator that transfers to a {@code ParallelAgent} cannot react to
40+ * the parallel results afterwards. To follow a fan-out with an aggregation/follow-up step, place
41+ * the {@code ParallelAgent} and the follow-up agent as siblings inside a {@link SequentialAgent}
42+ * (used as the root or transferred-to agent):
43+ *
44+ * <pre>{@code
45+ * SequentialAgent.builder()
46+ * .subAgents(ImmutableList.of(parallelDataAgent, aggregatorLlmAgent))
47+ * .build();
48+ * }</pre>
49+ *
50+ * <p>The {@code SequentialAgent} runs the {@code ParallelAgent} first, then runs {@code
51+ * aggregatorLlmAgent}, which can see the parallel sub-agents' events in the session.
3752 */
3853public class ParallelAgent extends BaseAgent {
3954
Original file line number Diff line number Diff line change 2222import org .slf4j .Logger ;
2323import org .slf4j .LoggerFactory ;
2424
25- /** An agent that runs its sub-agents sequentially. */
25+ /**
26+ * An agent that runs its sub-agents sequentially.
27+ *
28+ * <p><b>Composition:</b> a {@code SequentialAgent} does not transfer control back to a parent
29+ * {@link LlmAgent}, so an LlmAgent orchestrator that transfers to a {@code SequentialAgent} cannot
30+ * react to its results afterwards. Use {@code SequentialAgent} itself as the root or transferred-to
31+ * agent and place any follow-up LlmAgent as the next sibling sub-agent.
32+ */
2633public class SequentialAgent extends BaseAgent {
2734
2835 private static final Logger logger = LoggerFactory .getLogger (SequentialAgent .class );
You can’t perform that action at this time.
0 commit comments