Skip to main content

Module routing

Module routing 

Source
Expand description

§Stage: Model Routing Intelligence

§Responsibility

Automatically route prompts to the optimal worker backend based on complexity scoring. Simple prompts go to the free local model (llama.cpp / Mistral); complex prompts go directly to the paid cloud model (Claude API). Prompts in the middle zone try local first with cloud fallback.

§Guarantees

  • Deterministic: the same prompt text always produces the same complexity score and initial routing decision.
  • Thread-safe: all state (CostTracker, adaptive threshold) uses atomics or interior locking — safe under concurrent pipeline access.
  • Non-blocking: route() is a pure O(n) scan over the prompt with no I/O, allocation-free hot path.
  • Bounded: adaptive threshold adjustment is clamped between local_threshold and 1.0, so it can never oscillate unboundedly.

§NOT Responsible For

  • Actually calling the workers (that belongs to stages / worker)
  • Cross-node routing (future distributed module)
  • Semantic understanding of prompt quality (heuristic-only)

Re-exports§

pub use arbitrage::ArbitrageEngine;
pub use arbitrage::ProviderProfile;
pub use arbitrage::ProviderSnapshot;
pub use cascade::CascadeEntry;
pub use cascade::CascadeError;
pub use cascade::CascadeResult;
pub use cascade::CircuitBreakerConfig;
pub use cascade::ProviderCascade;
pub use cascade::CascadeFailover;
pub use cascade::FailoverExhausted;
pub use cascade::FailoverResult;
pub use cascade::FailoverTier;
pub use config::RoutingConfig;
pub use cost_tracker::CostSnapshot;
pub use cost_tracker::CostTracker;
pub use cost_tracker::SessionBudgetTracker;
pub use health::ProviderHealthBuilder;
pub use health::ProviderHealthSnapshot;
pub use health::ProviderMetrics;
pub use pool_sizer::PoolSizer;
pub use pool_sizer::PoolSizerConfig;
pub use pool_sizer::ScaleAction;
pub use pool_sizer::ScaleRecommendation;
pub use router::ModelRouter;
pub use router::RoutingDecision;
pub use scorer::ComplexityScorer;
pub use scorer::ScoreBreakdown;
pub use semantic::ClassificationResult;
pub use semantic::RoutingCategory;
pub use semantic::SemanticRouter;
pub use semantic::SemanticRouterConfig;

Modules§

arbitrage
Provider Arbitrage Engine
cascade
Multi-provider cascade fallback.
config
Routing configuration types.
cost_tracker
Cost tracking and savings computation.
health
Provider health dashboard snapshot.
pool_sizer
Adaptive Worker Pool Sizer
router
Model routing logic.
scorer
Prompt complexity scoring.
semantic
Semantic prompt router using keyword-based heuristics.