pub struct ModelRouter { /* private fields */ }Expand description
Intelligent model router.
Combines prompt complexity scoring, threshold-based routing, adaptive threshold adjustment, and cost tracking into a single entry point.
Thread-safe: all mutable state uses atomics or interior RwLock.
§Panics
This type and its methods never panic.
Implementations§
Source§impl ModelRouter
impl ModelRouter
Sourcepub fn new(config: RoutingConfig) -> Self
pub fn new(config: RoutingConfig) -> Self
Create a new router with the given configuration.
§Arguments
config— Routing thresholds, cost rates, and adaptive settings.
§Returns
A new ModelRouter ready to route prompts.
§Panics
This function never panics.
Sourcepub fn route(&self, prompt: &str) -> RoutingDecision
pub fn route(&self, prompt: &str) -> RoutingDecision
Route a prompt to the appropriate worker.
§Arguments
prompt— The raw prompt text to analyse and route.
§Returns
A RoutingDecision indicating which worker(s) to use.
§Panics
This function never panics.
Sourcepub fn record_outcome(
&self,
decision: &RoutingDecision,
success: bool,
tokens: u64,
)
pub fn record_outcome( &self, decision: &RoutingDecision, success: bool, tokens: u64, )
Record the outcome of a routing decision.
For RoutingDecision::LocalWithFallback outcomes, this feeds the
adaptive threshold algorithm. When enough samples accumulate and the
local failure rate exceeds adaptive.failure_ceiling, the effective
cloud threshold is lowered (sending more requests directly to cloud).
§Arguments
decision— The routing decision that was made.success— Whether the primary worker succeeded.tokens— Number of tokens processed (for cost tracking).
§Panics
This function never panics.
Sourcepub fn cost_tracker(&self) -> &CostTracker
pub fn cost_tracker(&self) -> &CostTracker
Sourcepub fn effective_cloud_threshold(&self) -> f64
pub fn effective_cloud_threshold(&self) -> f64
Return the current effective cloud threshold.
This may differ from config.cloud_threshold if adaptive adjustment
has been triggered.
§Panics
This function never panics.
Sourcepub fn scorer(&self) -> &ComplexityScorer
pub fn scorer(&self) -> &ComplexityScorer
Return a reference to the scorer for external breakdown queries.
§Panics
This function never panics.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ModelRouter
impl RefUnwindSafe for ModelRouter
impl Send for ModelRouter
impl Sync for ModelRouter
impl Unpin for ModelRouter
impl UnsafeUnpin for ModelRouter
impl UnwindSafe for ModelRouter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request