Class LoopAgent
java.lang.Object
com.alibaba.cloud.ai.graph.agent.Agent
com.alibaba.cloud.ai.graph.agent.flow.agent.FlowAgent
com.alibaba.cloud.ai.graph.agent.flow.agent.LoopAgent
Loop Agent that supports multiple loop modes:
- COUNT: Execute a fixed number of loops
- CONDITION: Continue looping based on a condition, similar to a do-while structure, but when the condition is true, terminate the loop
- JSON_ARRAY: Parse a JSON array and iterate over its elements
- Other Loop Strategy: Users can implement the LoopStrategy interface according to their needs.
Note: The LoopAgent must have a subAgent, which is the agent that will be executed in each loop.
Usage example:
LoopAgent loopAgent = LoopAgent.builder()
.name("example-loop-agent")
.description("Example loop agent")
.loopStrategy(LoopMode.condition(messagePredicate))
.subAgent(subAgent)
.build();
- Since:
- 2025/8/25
- Author:
- vlsmb
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class com.alibaba.cloud.ai.graph.agent.flow.agent.FlowAgent
interruptBefore, stateSerializer, subAgentsFields inherited from class com.alibaba.cloud.ai.graph.agent.Agent
compileConfig, compiledGraph, description, executor, graph, name -
Method Summary
Modifier and TypeMethodDescriptionstatic LoopAgent.LoopAgentBuilderbuilder()protected StateGraphAbstract method for subclasses to specify their graph building strategy.Methods inherited from class com.alibaba.cloud.ai.graph.agent.flow.agent.FlowAgent
asStateGraph, initGraph, schedule, subAgentsMethods inherited from class com.alibaba.cloud.ai.graph.agent.Agent
applyExecutorConfig, buildMessageInput, buildNonStreamConfig, buildStreamConfig, description, doInvoke, doInvokeAndGetOutput, doStream, getAndCompileGraph, getCurrentState, getGraph, invoke, invoke, invoke, invoke, invoke, invoke, invokeAndGetOutput, invokeAndGetOutput, invokeAndGetOutput, invokeAndGetOutput, invokeAndGetOutput, invokeAndGetOutput, name, schedule, stream, stream, stream, stream, stream, stream
-
Field Details
-
LOOP_STRATEGY
- See Also:
-
-
Method Details
-
buildSpecificGraph
protected StateGraph buildSpecificGraph(FlowGraphBuilder.FlowGraphConfig config) throws GraphStateException Description copied from class:FlowAgentAbstract 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:
buildSpecificGraphin classFlowAgent- Parameters:
config- the graph configuration- Returns:
- the constructed StateGraph
- Throws:
GraphStateException- if graph construction fails
-
builder
-