Skip to main content

rinne_loop/
priors.rs

1//! Static capability priors for known models (`CONTEXT.md` §7).
2//!
3//! Day-one seed for tiering an unknown pool with no learned data: known models
4//! mapped to per-dimension scores and a relative cost/quota class. Unknown
5//! models get a conservative default, and the within-pool cascade discovers
6//! their real level through evaluator outcomes. This same table is what the
7//! phase-two learned router refines from logged trajectories, so the priors
8//! degrade gracefully into learned weights.
9
10/// Relative cost/quota rank, not an absolute price. `Cheap` < `Workhorse` <
11/// `Frontier` defines the cascade order within whatever pool is present.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
13pub enum CostClass {
14    Cheap = 0,
15    Workhorse = 1,
16    Frontier = 2,
17}
18
19/// Per-dimension capability scores (0–100) plus family and cost class.
20#[derive(Debug, Clone, Copy)]
21pub struct ModelPrior {
22    /// Vendor family, e.g. `claude`, `grok`, `openai`, `google`, `deepseek`.
23    /// Drives cross-family evaluator independence.
24    pub family: &'static str,
25    pub cost: CostClass,
26    pub coding: u8,
27    pub reasoning: u8,
28    pub long_context: u8,
29    pub vision: u8,
30    pub structured_output: u8,
31}
32
33impl ModelPrior {
34    /// A coding-agent-weighted strength used to order models within a cost
35    /// class (coding and reasoning dominate).
36    pub fn strength(&self) -> u32 {
37        (self.coding as u32) * 4
38            + (self.reasoning as u32) * 4
39            + (self.long_context as u32)
40            + (self.structured_output as u32)
41    }
42}
43
44/// The conservative default for an unrecognized model: mid-tier, unknown family,
45/// so the cascade discovers its true level rather than over-trusting it.
46const DEFAULT: ModelPrior = ModelPrior {
47    family: "unknown",
48    cost: CostClass::Workhorse,
49    coding: 60,
50    reasoning: 60,
51    long_context: 60,
52    vision: 40,
53    structured_output: 60,
54};
55
56/// Look up priors for a model id/alias by case-insensitive substring match
57/// (most specific patterns first). Returns [`DEFAULT`] for unknown models.
58pub fn prior_for(model: &str) -> ModelPrior {
59    let m = model.to_lowercase();
60    let has = |needle: &str| m.contains(needle);
61
62    // ----- Anthropic / Claude -----
63    if has("opus") {
64        return p("claude", CostClass::Frontier, 90, 95, 90, 85, 88);
65    }
66    if has("sonnet") {
67        return p("claude", CostClass::Workhorse, 85, 82, 85, 80, 85);
68    }
69    if has("haiku") {
70        return p("claude", CostClass::Cheap, 70, 65, 75, 70, 78);
71    }
72
73    // ----- xAI / Grok -----
74    if has("grok-build") || has("grok-4") {
75        return p("grok", CostClass::Frontier, 82, 80, 80, 60, 75);
76    }
77    if has("grok-composer") || has("composer") || has("grok") {
78        return p("grok", CostClass::Workhorse, 72, 68, 70, 50, 70);
79    }
80
81    // ----- Google / Gemini -----
82    if has("gemini") && (has("flash") || has("lite")) {
83        return p("google", CostClass::Cheap, 68, 65, 88, 75, 72);
84    }
85    if has("gemini") {
86        return p("google", CostClass::Frontier, 84, 86, 92, 88, 82);
87    }
88
89    // ----- DeepSeek -----
90    if has("deepseek") && has("reason") {
91        return p("deepseek", CostClass::Workhorse, 80, 88, 70, 40, 72);
92    }
93    if has("deepseek") {
94        return p("deepseek", CostClass::Cheap, 78, 70, 70, 30, 70);
95    }
96
97    // ----- OpenAI ladder (nano < mini < standard < pro) -----
98    if has("nano") {
99        return p("openai", CostClass::Cheap, 68, 64, 70, 60, 80);
100    }
101    if has("mini") {
102        return p("openai", CostClass::Workhorse, 80, 78, 80, 75, 85);
103    }
104    if has("gpt") || has("openai") || has("o3") || has("o4") {
105        return p("openai", CostClass::Frontier, 88, 90, 85, 88, 90);
106    }
107
108    DEFAULT
109}
110
111const fn p(
112    family: &'static str,
113    cost: CostClass,
114    coding: u8,
115    reasoning: u8,
116    long_context: u8,
117    vision: u8,
118    structured_output: u8,
119) -> ModelPrior {
120    ModelPrior {
121        family,
122        cost,
123        coding,
124        reasoning,
125        long_context,
126        vision,
127        structured_output,
128    }
129}
130
131/// The vendor family for a model id, or `"unknown"`.
132pub fn family_of(model: &str) -> &'static str {
133    prior_for(model).family
134}
135
136/// The vendor family for a worker by name, used where model ids aren't known
137/// (e.g. `doctor`, which sees worker names but not their models).
138pub fn family_of_worker(name: &str) -> &'static str {
139    match name {
140        "claude-code" | "anthropic" | "claude" => "claude",
141        "grok" => "grok",
142        "codex" | "openai" => "openai",
143        "antigravity" | "google" | "gemini" => "google",
144        "deepseek" => "deepseek",
145        // OpenCode / Aider / Cursor depend on the user's provider config.
146        _ => "unknown",
147    }
148}
149
150/// The cascade ladder for a worker's models. The order is taken AS GIVEN —
151/// config/discovery already orders models cheapest→strongest (discovery sorts by
152/// the platform's pricing; users list them in tier order; adapters declare them
153/// cheap→strong). Priors are no longer used to *reorder* the ladder — only for
154/// family detection — so any model from any platform tiers by real cost or by
155/// the user's intent rather than a hardcoded name table.
156pub fn tier_ladder(models: &[String]) -> Vec<String> {
157    models.to_vec()
158}
159
160#[cfg(test)]
161mod tests {
162    use super::*;
163
164    #[test]
165    fn ladder_preserves_given_order() {
166        // The ladder is the order as given (cheap→strong) — not re-sorted.
167        let models = vec![
168            "haiku".to_string(),
169            "sonnet".to_string(),
170            "opus".to_string(),
171        ];
172        assert_eq!(tier_ladder(&models), models);
173    }
174
175    #[test]
176    fn families_classify() {
177        assert_eq!(family_of("claude-opus-4-8"), "claude");
178        assert_eq!(family_of("grok-build"), "grok");
179        assert_eq!(family_of("gemini-2.5-flash"), "google");
180        assert_eq!(family_of("deepseek-reasoner"), "deepseek");
181        assert_eq!(family_of("something-unheard-of"), "unknown");
182    }
183
184    #[test]
185    fn unknown_model_gets_conservative_default() {
186        let pr = prior_for("mystery-model-9000");
187        assert_eq!(pr.family, "unknown");
188        assert_eq!(pr.cost, CostClass::Workhorse);
189    }
190
191    #[test]
192    fn cost_class_orders_the_cascade() {
193        assert!(CostClass::Cheap < CostClass::Workhorse);
194        assert!(CostClass::Workhorse < CostClass::Frontier);
195    }
196}