KeiSeiKit-1.0/_primitives/_rust/kei-model-router/src/lib.rs
Parfii-bot 0be354a920 KeiSeiKit-public — clean state
Single-commit clean baseline after security scrub of niche-tells,
project codenames, internal jargon, and contributor-email leaks.

Contents:
- 100 Rust crates (_primitives/_rust/)
- 37 agent manifests (_manifests/) + generated specs (_generated/)
- 67 user-invocable skills (skills/)
- 33 hooks (hooks/)
- Composition blocks (_blocks/)
- Documentation (docs/, README.md)
- TS adapter packages (_ts_packages/)
- Assembler (_assembler/)
- Roles (_roles/)
- Templates (_templates/)
- Forgejo CI (.forgejo/)

Author: Denis Parfionovich <info@greendragon.info>

License: see LICENSE.
2026-05-01 12:09:03 +08:00

40 lines
1.6 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! kei-model-router — model selection for Claude Code Agent spawns.
//!
//! Concern: given an incoming Agent invocation (subagent_type, prompt,
//! task-class DNA), pick the cheapest model in {Haiku 4.5, Sonnet 4.6,
//! Opus 4.7} that meets the empirical quality bar for similar past
//! invocations. Reads from `kei-ledger` posterior, writes back outcomes.
//!
//! Constructor Pattern: each cube under 200 LOC, each function under 30.
//! Cubes assembled here:
//!
//! - `pricing` — verified per-MTok constants (RULE 0.4, 2026-04-30)
//! - `dna_class` — task-class DNA extraction (strip nonce/body suffixes)
//! - `complexity` — τ-estimator (regex+length+role heuristics)
//! - `posterior` — Beta posterior from ledger rows per (task-class, model)
//! - `kernel` — substrate similarity for unseen task classes
//! - `select` — decision rule: argmin cost s.t. P[q ≥ q*] ≥ 1δ
//! - `escalate` — retry-ladder bookkeeping
//!
//! Distinct from `kei-router` (which handles NL→tool dispatch and
//! generic LLM provider abstraction). This crate's only job is selecting
//! WHICH Claude tier to spawn an Agent on.
pub mod calibrate;
pub mod complexity;
pub mod dna_class;
pub mod escalate;
pub mod kernel;
pub mod posterior;
pub mod pricing;
pub mod select;
pub use complexity::{ComplexityEstimate, Tier};
pub use escalate::{next_after_failure, EscalationDecision, MAX_ESCALATION_DEPTH};
pub use kernel::{similarity, KernelWeights};
pub use posterior::Posterior;
pub use pricing::{
cost_micro_cents, Model, ModelPricing, HAIKU_45, OPUS_47, OPUS_47_TOKENIZER_OVERHEAD,
SONNET_46,
};
pub use select::{select, Decision, DecisionInput};