Class FlowAgentBuilder<T extends FlowAgent,B extends FlowAgentBuilder<T,B>>

java.lang.Object
com.alibaba.cloud.ai.graph.agent.flow.builder.FlowAgentBuilder<T,B>
Type Parameters:
T - the concrete FlowAgent type this builder creates
B - the concrete builder type (for fluent interface support)
Direct Known Subclasses:
LlmRoutingAgent.LlmRoutingAgentBuilder, LoopAgent.LoopAgentBuilder, ParallelAgent.ParallelAgentBuilder, SequentialAgent.SequentialAgentBuilder, SupervisorAgent.SupervisorAgentBuilder

public abstract class FlowAgentBuilder<T extends FlowAgent,B extends FlowAgentBuilder<T,B>> extends Object
Abstract base builder for FlowAgent and its subclasses. Provides common builder functionality and enforces consistent builder patterns.
  • Field Details

  • Constructor Details

    • FlowAgentBuilder

      public FlowAgentBuilder()
  • Method Details

    • name

      public B name(String name)
      Sets the agent name.
      Parameters:
      name - the unique name of the agent
      Returns:
      this builder instance for method chaining
    • description

      public B description(String description)
      Sets the agent description.
      Parameters:
      description - the description of the agent's capability
      Returns:
      this builder instance for method chaining
    • compileConfig

      public B compileConfig(CompileConfig compileConfig)
      Sets the compile configuration.
      Parameters:
      compileConfig - the compile configuration
      Returns:
      this builder instance for method chaining
    • saver

      public B saver(BaseCheckpointSaver saver)
    • subAgents

      public B subAgents(List<Agent> subAgents)
      Sets the list of sub-agents.
      Parameters:
      subAgents - the list of sub-agents
      Returns:
      this builder instance for method chaining
    • stateSerializer

      public B stateSerializer(StateSerializer stateSerializer)
      Sets the state serializer for the agent.
      Parameters:
      stateSerializer - the state serializer to use
      Returns:
      this builder instance for method chaining
    • executor

      public B executor(Executor executor)
      Sets the executor for parallel nodes.

      This executor will be used for all parallel nodes in the agent's execution graph. When a parallel node is executed, it will use this executor to run the parallel branches concurrently.

      Parameters:
      executor - the Executor to use for parallel nodes
      Returns:
      this builder instance for method chaining
    • self

      protected abstract B self()
      Returns the concrete builder instance. This method enables fluent interface support in subclasses.
      Returns:
      this builder instance
    • validate

      protected void validate()
      Validates the builder state before creating the agent. Subclasses can override this method to add specific validation logic.
      Throws:
      IllegalArgumentException - if validation fails
    • build

      public T build()
      Builds the concrete FlowAgent instance. Subclasses must implement this method to create the specific agent type.
      Returns:
      the built FlowAgent instance
      Throws:
      GraphStateException - if agent creation fails
    • doBuild

      public abstract T doBuild()