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 createsB- the concrete builder type (for fluent interface support)
- Direct Known Subclasses:
LlmRoutingAgent.LlmRoutingAgentBuilder,LoopAgent.LoopAgentBuilder,ParallelAgent.ParallelAgentBuilder,SequentialAgent.SequentialAgentBuilder
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 Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the concrete FlowAgent instance.compileConfig(CompileConfig compileConfig) Sets the compile configuration.description(String description) Sets the agent description.abstract TdoBuild()Sets the executor for parallel nodes.Sets hooks for the agent.Sets hooks for the agent from a list.Sets the agent name.saver(BaseCheckpointSaver saver) protected abstract Bself()Returns the concrete builder instance.stateSerializer(StateSerializer stateSerializer) Sets the state serializer for the agent.Sets the list of sub-agents.protected voidvalidate()Validates the builder state before creating the agent.
-
Field Details
-
name
-
description
-
compileConfig
-
saver
-
subAgents
-
stateSerializer
-
executor
-
hooks
-
-
Constructor Details
-
FlowAgentBuilder
public FlowAgentBuilder()
-
-
Method Details
-
name
Sets the agent name.- Parameters:
name- the unique name of the agent- Returns:
- this builder instance for method chaining
-
description
Sets the agent description.- Parameters:
description- the description of the agent's capability- Returns:
- this builder instance for method chaining
-
compileConfig
Sets the compile configuration.- Parameters:
compileConfig- the compile configuration- Returns:
- this builder instance for method chaining
-
saver
-
subAgents
Sets the list of sub-agents.- Parameters:
subAgents- the list of sub-agents- Returns:
- this builder instance for method chaining
-
stateSerializer
Sets the state serializer for the agent.- Parameters:
stateSerializer- the state serializer to use- Returns:
- this builder instance for method chaining
-
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- theExecutorto use for parallel nodes- Returns:
- this builder instance for method chaining
-
hooks
Sets hooks for the agent. Hooks allow you to intercept and modify agent execution at various points (before/after agent, before/after model calls).Common use cases include:
- Message trimming to reduce token consumption
- Conversation summarization for long-running threads
- Logging and monitoring
- Content filtering and safety checks
- Parameters:
hooks- varargs of Hook instances- Returns:
- this builder instance for method chaining
-
hooks
Sets hooks for the agent from a list.- Parameters:
hooks- list of Hook instances- Returns:
- this builder instance for method chaining
- See Also:
-
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
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
-