Expand description
AI routing policies (DW-085): within-request escalation and latency-vs-cost selection. Composed over DW-076 routing.
Two policy kinds:
- FallbackChain: calls an external classifier service to estimate prompt complexity. Simple prompts (score < threshold) route to the cheap model; complex prompts (score >= threshold) escalate to the costlier model. On classifier error, fails open to the cheap model (the safe default).
- LatencyCost: static config-based selection. Candidates are sorted at compile time by the configured preference (cost, latency, or balanced); the policy returns the best candidate deterministically (no runtime metrics needed).
A policy composes over DW-076 routing: the candidate aliases it
names (cheap, escalate_to, or candidates[].model) are
themselves plain chain/canary aliases. The policy resolves each
alias to its PRIMARY RouteTarget at compile time (the first
chain entry or the first canary version), so the runtime
evaluation returns a flat candidate list the dataplane walks with
the same failover loop as a plain chain.
§Dependency direction
ai depends on config only. The classifier HTTP call reuses
the same hyper_util client pattern as the DW-083 semantic cache
(no new dependencies).
Structs§
- Live
Latency Tracker - AI-15 (#203): Live latency tracker for LatencyCost policies.
Maintains a rolling window of latency observations per model alias.
Thread-safe (wrapped in Arc
).
Enums§
- Compiled
Routing Policy - A compiled routing policy (DW-085). Built at AiRuntime compile
time from the config block; immutable once built. The
evaluatemethod returns the candidate list to walk (the same shape asAiRuntime::route) plus aPolicyDecisionthe dataplane records as a metric. - Policy
Decision - The decision a routing policy made for one request (DW-085). The
dataplane records this as a metric (the
aidomain cannot importobservability— the dependency direction forbids it — so the decision travels back to the caller, which records it).