tokio_prompt_orchestrator/routing/mod.rs
1//! # Stage: Model Routing Intelligence
2//!
3//! ## Responsibility
4//! Automatically route prompts to the optimal worker backend based on
5//! complexity scoring. Simple prompts go to the free local model (llama.cpp /
6//! Mistral); complex prompts go directly to the paid cloud model (Claude API).
7//! Prompts in the middle zone try local first with cloud fallback.
8//!
9//! ## Guarantees
10//! - Deterministic: the same prompt text always produces the same complexity
11//! score and initial routing decision.
12//! - Thread-safe: all state (`CostTracker`, adaptive threshold) uses atomics
13//! or interior locking — safe under concurrent pipeline access.
14//! - Non-blocking: `route()` is a pure O(n) scan over the prompt with no
15//! I/O, allocation-free hot path.
16//! - Bounded: adaptive threshold adjustment is clamped between
17//! `local_threshold` and `1.0`, so it can never oscillate unboundedly.
18//!
19//! ## NOT Responsible For
20//! - Actually calling the workers (that belongs to `stages` / `worker`)
21//! - Cross-node routing (future distributed module)
22//! - Semantic understanding of prompt quality (heuristic-only)
23
24pub mod arbitrage;
25pub mod cascade;
26pub mod config;
27pub mod cost_tracker;
28pub mod health;
29pub mod pool_sizer;
30pub mod router;
31pub mod scorer;
32pub mod semantic;
33
34// Re-exports for convenience
35pub use arbitrage::{ArbitrageEngine, ProviderProfile, ProviderSnapshot};
36pub use cascade::{
37 CascadeEntry, CascadeError, CascadeResult, CircuitBreakerConfig, ProviderCascade,
38 CascadeFailover, FailoverExhausted, FailoverResult, FailoverTier,
39};
40pub use config::RoutingConfig;
41pub use cost_tracker::{CostSnapshot, CostTracker, SessionBudgetTracker};
42pub use health::{ProviderHealthBuilder, ProviderHealthSnapshot, ProviderMetrics};
43pub use pool_sizer::{PoolSizer, PoolSizerConfig, ScaleAction, ScaleRecommendation};
44pub use router::{ModelRouter, RoutingDecision};
45pub use scorer::{ComplexityScorer, ScoreBreakdown};
46pub use semantic::{ClassificationResult, RoutingCategory, SemanticRouter, SemanticRouterConfig};