Class RoutingGraphBuildingStrategy

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

public class RoutingGraphBuildingStrategy extends AbstractFlowGraphBuildingStrategy
Strategy for building LLM-based routing graphs. In a routing graph, an LLM decides which sub-agent should handle the task based on the input content and agent capabilities.

This strategy extends AbstractFlowGraphBuildingStrategy and customizes hook handling: beforeModel/afterModel hooks wrap around the RoutingNode instead of the root agent.

  • Constructor Details

    • RoutingGraphBuildingStrategy

      public RoutingGraphBuildingStrategy()
  • 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
    • generateKeyStrategyFactory

      public KeyStrategyFactory generateKeyStrategyFactory(FlowGraphBuilder.FlowGraphConfig config)
      Description copied from interface: FlowGraphBuildingStrategy
      Generates a KeyStrategyFactory based on the root agent and sub-agents.
      Parameters:
      config - the configuration containing agents
      Returns:
      the generated KeyStrategyFactory
    • 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