Routing policy for provider selection and failover attempts.
Strategies
:prefer(default) — order candidates bypreferlist, then remaining. This preserves Phase 1 semantics.:weighted— score each candidate usingweightsand health signals, then sort by descending score. Ties are broken bypreferorder.
Weights
When strategy: :weighted, the weights map assigns a static score to
each adapter id. Adapters not listed receive a default weight of 1.0.
Health penalties (failure count) are subtracted from the weight to produce
the final score.
Summary
Functions
Orders candidates according to the policy strategy.
Computes the weighted score for a single candidate.
Types
@type candidate() :: %{:id => candidate_id(), optional(any()) => any()}
@type candidate_id() :: String.t()
@type health_map() :: %{ optional(candidate_id()) => %{failure_count: non_neg_integer()} }
@type strategy() :: :prefer | :weighted
@type t() :: %AgentSessionManager.Routing.RoutingPolicy{ exclude: [candidate_id()], max_attempts: pos_integer(), prefer: [candidate_id()], strategy: strategy(), weights: %{optional(candidate_id()) => number()} }
Functions
@spec attempt_limit(t(), non_neg_integer()) :: non_neg_integer()
Orders candidates according to the policy strategy.
:prefer— apply prefer/exclude filters and reorder bypreferlist.:weighted— score candidates usingweightsand optional health data, break ties withpreferorder, then return sorted.
The opts keyword list may include:
:health— a map of%{adapter_id => %{failure_count: n}}used to penalize unhealthy adapters whenstrategy: :weighted.
@spec score(t(), candidate_id(), health_map()) :: float()
Computes the weighted score for a single candidate.
Score = weight(candidate_id) − failure_count * penalty_per_failure.
The penalty per failure is 0.5 by default.