Class FlowGraphBuildingStrategyRegistry

java.lang.Object
com.alibaba.cloud.ai.graph.agent.flow.strategy.FlowGraphBuildingStrategyRegistry

public class FlowGraphBuildingStrategyRegistry extends Object
Registry for FlowGraphStrategy implementations. This allows for dynamic registration and lookup of graph building strategies, enabling extensibility without modifying core code.

The registry is thread-safe and supports runtime registration of new strategies.

  • Method Details

    • getInstance

      public static FlowGraphBuildingStrategyRegistry getInstance()
      Gets the singleton instance of the registry.
      Returns:
      the registry instance
    • registerStrategy

      public void registerStrategy(FlowGraphBuildingStrategy strategy)
      Registers a new graph building strategy (same instance returned each time).
      Parameters:
      strategy - the strategy to register
      Throws:
      IllegalArgumentException - if strategy is null or type is already registered
    • registerStrategy

      public void registerStrategy(String type, Supplier<FlowGraphBuildingStrategy> factory)
      Registers a strategy factory. Each call to createStrategy(String) or getStrategy(String) will use the factory to obtain a strategy instance.
      Parameters:
      type - the strategy type
      factory - the factory that creates strategy instances
      Throws:
      IllegalArgumentException - if type or factory is null, or type is already registered
    • createStrategy

      public FlowGraphBuildingStrategy createStrategy(String type)
      Creates a new strategy instance by type. For built-in strategies a new instance is returned each time; for strategies registered via registerStrategy(FlowGraphBuildingStrategy) the same instance is returned.
      Parameters:
      type - the strategy type
      Returns:
      a strategy implementation
      Throws:
      IllegalArgumentException - if no strategy is found for the type
    • getStrategy

      public FlowGraphBuildingStrategy getStrategy(String type)
      Gets a strategy by type (delegates to the registered factory).
      Parameters:
      type - the strategy type
      Returns:
      the strategy implementation
      Throws:
      IllegalArgumentException - if no strategy is found for the type
    • hasStrategy

      public boolean hasStrategy(String type)
      Checks if a strategy is registered for the given type.
      Parameters:
      type - the strategy type
      Returns:
      true if a strategy is registered, false otherwise
    • getRegisteredTypes

      public Set<String> getRegisteredTypes()
      Gets all registered strategy types.
      Returns:
      a set of all registered strategy types
    • unregisterStrategy

      public Supplier<FlowGraphBuildingStrategy> unregisterStrategy(String type)
      Unregisters a strategy (mainly for testing purposes).
      Parameters:
      type - the strategy type to unregister
      Returns:
      the unregistered strategy factory, or null if none was found
    • clear

      public void clear()
      Clears all registered strategies (mainly for testing purposes).