Class ConditionalGraphBuildingStrategy

java.lang.Object
com.alibaba.cloud.ai.graph.agent.flow.strategy.AbstractFlowGraphBuildingStrategy
com.alibaba.cloud.ai.graph.agent.flow.strategy.ConditionalGraphBuildingStrategy
All Implemented Interfaces:
FlowGraphBuildingStrategy

public class ConditionalGraphBuildingStrategy extends AbstractFlowGraphBuildingStrategy
Strategy for building conditional execution graphs. In a conditional graph, the execution path is determined by evaluating conditions based on the current state, and different agents are selected accordingly.
  • Constructor Details

    • ConditionalGraphBuildingStrategy

      public ConditionalGraphBuildingStrategy()
  • Method Details

    • buildCoreGraph

      protected void buildCoreGraph(FlowGraphBuilder.FlowGraphConfig config) throws GraphStateException
      Description copied from class: AbstractFlowGraphBuildingStrategy
      Abstract 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:
      buildCoreGraph in class AbstractFlowGraphBuildingStrategy
      Parameters:
      config - the flow graph configuration
      Throws:
      GraphStateException - if graph construction fails
    • connectBeforeModelHooks

      protected void connectBeforeModelHooks() throws GraphStateException
      Description copied from class: AbstractFlowGraphBuildingStrategy
      Connects beforeModel hook edges. Subclasses can override to customize behavior. Default implementation connects hooks in sequence to rootAgent.name().

      This method is called after buildCoreGraph() and before connectAfterModelHooks(). Subclasses that handle hook connections in buildCoreGraph() should override this method with an empty implementation to avoid duplicate edge connections.

      Overrides:
      connectBeforeModelHooks in class AbstractFlowGraphBuildingStrategy
      Throws:
      GraphStateException - if graph construction fails
    • connectAfterModelHooks

      protected void connectAfterModelHooks() throws GraphStateException
      Description copied from class: AbstractFlowGraphBuildingStrategy
      Connects afterModel hook edges. Subclasses can override to customize behavior. Default implementation connects hooks in sequence from rootAgent.name().

      This method is called after connectBeforeModelHooks() and before connectBeforeAgentHooks(). Subclasses that handle hook connections in buildCoreGraph() should override this method with an empty implementation to avoid duplicate edge connections.

      Overrides:
      connectAfterModelHooks in class AbstractFlowGraphBuildingStrategy
      Throws:
      GraphStateException - if graph construction fails
    • getStrategyType

      public String getStrategyType()
      Description copied from interface: FlowGraphBuildingStrategy
      Returns the type identifier for this strategy. This is used for registration and lookup purposes.
      Returns:
      the strategy type identifier
    • validateConfig

      public void validateConfig(FlowGraphBuilder.FlowGraphConfig config)
      Description copied from interface: FlowGraphBuildingStrategy
      Validates that the configuration contains all required parameters for this strategy.
      Parameters:
      config - the configuration to validate