Expand description
§cortex-router
A fail-closed, model-free routing policy: given a task and its context, it decides between deterministic tooling, repository analysis, a bounded local model, or the upstream (strong) agent.
Model self-reported confidence is deliberately absent from the API. Routing is a function of inspectable inputs only: task text, evidence state, schema validity, token budgets, mutation authority, and local capability availability.
§Why
“Should a small local model handle this?” is a safety question, not an optimization question. This crate answers it with rules you can read, test, and audit:
- Fail-closed guards. Missing or contradictory evidence, a schema failure, or a budget overrun always escalates upstream.
- Mutation is never local. Anything likely to mutate code or state is reserved for the upstream agent.
- High-risk classes are named. Security, authentication, concurrency, migration, release, deployment, and publication escalate by class.
- Plans never exceed the caller’s bound. The returned
ContextPlanreports at most themax_input_tokensthe request declared.
use cortex_router::{route, EvidenceStatus, ExecutionTarget, RoutingRequest};
let mut request = RoutingRequest::new("Deploy the service to production");
request.evidence = EvidenceStatus::Verified;
let decision = route(&request);
assert_eq!(decision.target, ExecutionTarget::Upstream);
assert!(!decision.advisory_only);
let mut summary = RoutingRequest::new("Summarize the supplied evidence");
summary.evidence = EvidenceStatus::Verified;
assert_eq!(route(&summary).target, ExecutionTarget::Ollama);§Scope and limits
Classification is lexical and currently tuned for English task text, which is
a deliberate trade: it is fast, deterministic, and inspectable, with no model
in the loop. Treat classify as a conservative first filter — it escalates
when uncertain — and layer richer signals above it if you need them.
§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Structs§
Enums§
Constants§
- UPSTREAM_
EVIDENCE_ TOKENS - Default evidence ceiling for upstream work when the caller allows more.
Functions§
- classification_
for_ tier - Turn a model-chosen tier into a
Classification, retaining lexical mutation cues and preferring a more specific lexical class when the tier matches. - classify
- Classify work using stable lexical rules, without calling a model.
- detector_
disagreement - True when two or more deterministic lexicon families fire on the same task.
- fold_
text - Compatibility-normalize, case-fold, and collapse whitespace.
- fold_
words - Fold, then keep letters/digits and turn everything else into spaces so phrase matching can use word boundaries.
- mixed_
script - True when the task mixes Latin letters with another script.
- parse_
model_ tier - Parse a closed-set label into a
ModelTier. - policy_
tier - Map a task class to the model tier the routing policy grants it.
- route
- Select a target through deterministic, fail-closed routing rules.
- route_
with_ classification - Same policy as
route, with a precomputed classification. - tier_
rank - Rank tiers so under-calls are detectable without floating point.