Routes inbound input to a compiled Spectre rule.
Routing is evidence-first. Each configured strategy can add candidates to a
%Spectre.Router.Context{}; arbitration later decides which candidate becomes
the route. This keeps deterministic matches, trained classifiers, semantic
cache hits, and LLM fallback from overwriting each other prematurely.
Summary
Functions
Returns interrupt, current-flow, and fallback rules in evaluation order.
Evaluates routing without executing a handler, action, or state adapter.
Routes input to the best matching compiled agent rule.
Runs the router pipeline and returns the full routing context.
Converts a completed router context into the selected route.
Functions
@spec candidate_rules(module(), Spectre.State.t()) :: [Spectre.Rule.t()]
Returns interrupt, current-flow, and fallback rules in evaluation order.
Interrupts are first so global commands like cancel/help remain responsive. Current-flow rules come next to make multi-turn flows stable. Remaining rules are kept as fallback candidates so users can still change topic.
Flows nest, so current_flow matches any rule whose flow_path contains the
flow name: setting current_flow: :checkout prioritizes rules declared in
:checkout and in every flow nested below it.
@spec evaluate(module(), Spectre.Input.t() | String.t() | map(), keyword()) :: {:ok, Spectre.Router.Receipt.t()}
Evaluates routing without executing a handler, action, or state adapter.
Evaluation runs the real input and router pipelines but disables journal delivery and online semantic learning. The returned receipt contains no raw input, prompt, model output, matches, or handlers.
{:ok, receipt} = Spectre.Router.evaluate(MyAgent, "help")
@spec route(Spectre.Input.t(), Spectre.Context.t()) :: {:ok, Spectre.Route.t()} | {:error, term()}
Routes input to the best matching compiled agent rule.
{:ok, route} = Spectre.Router.route(input, ctx)
@spec route_context(Spectre.Input.t(), Spectre.Context.t()) :: {:ok, Spectre.Router.Context.t()} | {:error, term()}
Runs the router pipeline and returns the full routing context.
This is useful for runtimes that need enriched input fields produced by router plugs.
{:ok, router_context} = Spectre.Router.route_context(input, ctx)
@spec route_from_context(Spectre.Router.Context.t()) :: {:ok, Spectre.Route.t()} | {:error, term()}
Converts a completed router context into the selected route.
{:ok, route} = Spectre.Router.route_from_context(router_context)