Class ParallelAgent


public class ParallelAgent extends FlowAgent
ParallelAgent executes multiple sub-agents in parallel and merges their results.

This agent implements the Parallel Fan-Out/Gather pattern where:

  • Fan-Out: The input is distributed to all sub-agents simultaneously
  • Parallel Execution: All sub-agents execute concurrently
  • Gather: Results from all sub-agents are collected and merged

The agent leverages the underlying ParallelNode infrastructure to achieve true parallel execution and provides configurable result merging strategies.

  • Constructor Details

  • Method Details

    • builder

      public static ParallelAgent.ParallelAgentBuilder builder()
    • buildSpecificGraph

      protected StateGraph buildSpecificGraph(FlowGraphBuilder.FlowGraphConfig config) throws GraphStateException
      Description copied from class: FlowAgent
      Abstract method for subclasses to specify their graph building strategy. This method should be implemented by concrete FlowAgent subclasses to define how their specific graph structure should be built.
      Specified by:
      buildSpecificGraph in class FlowAgent
      Parameters:
      config - the graph configuration
      Returns:
      the constructed StateGraph
      Throws:
      GraphStateException - if graph construction fails
    • mergeStrategy

      public ParallelAgent.MergeStrategy mergeStrategy()
      Gets the merge strategy used by this ParallelAgent.
      Returns:
      the merge strategy
    • mergeOutputKey

      public String mergeOutputKey()
    • maxConcurrency

      public Integer maxConcurrency()
      Gets the maximum concurrency limit for this ParallelAgent.
      Returns:
      the max concurrency, or null if unlimited
    • buildNonStreamConfig

      protected RunnableConfig buildNonStreamConfig(RunnableConfig config)
      Override buildNonStreamConfig to add maxConcurrency to RunnableConfig metadata. This allows the ParallelNode to access the concurrency limit during execution.
      Overrides:
      buildNonStreamConfig in class Agent
    • buildStreamConfig

      protected RunnableConfig buildStreamConfig(RunnableConfig config)
      Override buildStreamConfig to add maxConcurrency to RunnableConfig metadata. This allows the ParallelNode to access the concurrency limit during execution.
      Overrides:
      buildStreamConfig in class Agent