langgoap.StrategyRouter

langgoap.StrategyRouter#

class StrategyRouter(strategies, classifier, transition_model=None, default='astar', on_unknown='raise', on_strategy_chosen=None)[source]#

Dispatches to a registered PlanningStrategy by name.

StrategyRouter itself satisfies the PlanningStrategy Protocol, so callers that already accept a strategy (e.g. GoapPlanner(strategy=...)) can opt in by passing a router with no other changes.

Parameters:
  • strategies (Mapping[str, PlanningStrategy]) – Mapping from strategy name to strategy instance.

  • classifier (StrategyClassifier) – Callable from ProblemFeatures to a registered strategy name.

  • transition_model (TransitionModel | None) – Optional model consulted by extract_features() for the is_stochastic and risk_profile features. Defaults to DeterministicTransitionModel.

  • default (str) – Name of the fallback strategy used when on_unknown="default" and the classifier returns a name not registered in strategies.

  • on_unknown (Literal['raise', 'default']) – "raise" (default) turns unknown classifier outputs into KeyError — strict mode catches misconfigured routers loudly. "default" silently falls back to strategies[default].

  • on_strategy_chosen (Callable[[str], None] | None) – Optional callback invoked with the name of the strategy actually dispatched to (after on_unknown fallback resolution). Useful for observers that need to know which concrete strategy ran — e.g. a dashboard recorder that renders an A* tree for one turn and an MCTS tree for the next.

__init__(strategies, classifier, transition_model=None, default='astar', on_unknown='raise', on_strategy_chosen=None)#
Parameters:
Return type:

None

Methods

__init__(strategies, classifier[, ...])

plan(start, goal, actions, *[, ...])

Classify (start, goal, actions) and dispatch to the chosen strategy.

Attributes

default

last_chosen

on_strategy_chosen

on_unknown

transition_model

strategies

classifier