Class LoopGraphBuildingStrategy
java.lang.Object
com.alibaba.cloud.ai.graph.agent.flow.strategy.AbstractFlowGraphBuildingStrategy
com.alibaba.cloud.ai.graph.agent.flow.strategy.LoopGraphBuildingStrategy
- All Implemented Interfaces:
FlowGraphBuildingStrategy
Converts a LoopAgent into its corresponding StateGraph.
Structure of the loop graph: START -> LoopInitLoop -> LoopDispatchNode (condition met -> SubAgentNode -> LoopDispatchNode; condition not met -> END)
- Since:
- 2025/8/25
- Author:
- vlsmb
-
Field Summary
Fields inherited from class com.alibaba.cloud.ai.graph.agent.flow.strategy.AbstractFlowGraphBuildingStrategy
afterAgentHooks, afterModelHooks, beforeAgentHooks, beforeModelHooks, entryNode, exitNode, graph, rootAgent -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAbstract method that subclasses must implement to build their specific graph structure.protected voidEmpty implementation - afterModel hooks are connected within the loop in buildCoreGraph.protected voidConnects beforeAgent hooks directly to the loop processor.protected voidEmpty implementation - beforeModel hooks are connected within the loop in buildCoreGraph.Generates a KeyStrategyFactory based on the root agent and sub-agents.Returns the type identifier for this strategy.voidValidates loop-specific configuration requirements.Methods inherited from class com.alibaba.cloud.ai.graph.agent.flow.strategy.AbstractFlowGraphBuildingStrategy
addAfterAgentHookNodesToGraph, addBeforeAgentHookNodesToGraph, buildGraph, chainAfterAgentHooks, chainBeforeAgentHooks, connectAfterAgentHooks, connectAfterModelHookEdges, connectBeforeModelHookEdges, determineEntryNode, determineExitNode, filterHooksByPosition, getRootAgentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.alibaba.cloud.ai.graph.agent.flow.strategy.FlowGraphBuildingStrategy
processAgentKeyStrategies, processOutputKey
-
Constructor Details
-
LoopGraphBuildingStrategy
public LoopGraphBuildingStrategy()
-
-
Method Details
-
buildCoreGraph
Description copied from class:AbstractFlowGraphBuildingStrategyAbstract method that subclasses must implement to build their specific graph structure. All common setup (graph creation, hook filtering, node addition, etc.) is already done. Subclasses can directly access protected fields: graph, rootAgent, beforeModelHooks, afterModelHooks, entryNode, exitNode.Note: Subclasses should NOT call connectBeforeModelHookEdges() or connectAfterModelHookEdges() in this method. Instead, override the hook methods (connectBeforeModelHooks(), connectAfterModelHooks()) if custom hook connection logic is needed.
- Overrides:
buildCoreGraphin classAbstractFlowGraphBuildingStrategy- Parameters:
config- the flow graph configuration- Throws:
GraphStateException- if graph construction fails
-
connectBeforeAgentHooks
Connects beforeAgent hooks directly to the loop processor. In loop scenarios, beforeAgent hooks execute once before the loop starts, not before each iteration (which is handled by beforeModel hooks).- Overrides:
connectBeforeAgentHooksin classAbstractFlowGraphBuildingStrategy- Throws:
GraphStateException- if graph construction fails
-
connectBeforeModelHooks
Empty implementation - beforeModel hooks are connected within the loop in buildCoreGraph. This prevents the default behavior of connecting them outside the loop.- Overrides:
connectBeforeModelHooksin classAbstractFlowGraphBuildingStrategy- Throws:
GraphStateException- if graph construction fails
-
connectAfterModelHooks
Empty implementation - afterModel hooks are connected within the loop in buildCoreGraph. This prevents the default behavior of connecting them outside the loop.- Overrides:
connectAfterModelHooksin classAbstractFlowGraphBuildingStrategy- Throws:
GraphStateException- if graph construction fails
-
getStrategyType
Description copied from interface:FlowGraphBuildingStrategyReturns the type identifier for this strategy. This is used for registration and lookup purposes.- Returns:
- the strategy type identifier
-
generateKeyStrategyFactory
Description copied from interface:FlowGraphBuildingStrategyGenerates a KeyStrategyFactory based on the root agent and sub-agents.- Parameters:
config- the configuration containing agents- Returns:
- the generated KeyStrategyFactory
-
validateConfig
Validates loop-specific configuration requirements. - Loop strategy must be provided and be an instance of LoopStrategy - Exactly one sub-agent must be provided (loops execute a single agent repeatedly)- Parameters:
config- the configuration to validate
-