pub struct ProviderCascade { /* private fields */ }Expand description
A configurable chain of LLM providers that tries primary → secondary → tertiary on failure.
Unlike the binary LocalWithFallback routing decision, ProviderCascade
supports an arbitrary number of providers and maintains per-provider
circuit breakers, latency telemetry, and Prometheus counters.
§Clone behaviour
ProviderCascade is cheap to clone — all clones share the same underlying
Arc<Mutex<Vec<CascadeEntry>>> and its contained CircuitBreaker / atomic
state.
§Examples
use std::time::Duration;
use tokio_prompt_orchestrator::config::WorkerKind;
use tokio_prompt_orchestrator::routing::cascade::{CascadeEntry, CircuitBreakerConfig, ProviderCascade};
let cascade = ProviderCascade::new(vec![
CascadeEntry::new(WorkerKind::LlamaCpp, CircuitBreakerConfig::default()),
CascadeEntry::new(WorkerKind::OpenAi, CircuitBreakerConfig::default()),
]);
assert_eq!(cascade.len(), 2);Implementations§
Source§impl ProviderCascade
impl ProviderCascade
Sourcepub fn new(entries: Vec<CascadeEntry>) -> Self
pub fn new(entries: Vec<CascadeEntry>) -> Self
Create a new ProviderCascade from an ordered list of cascade entries.
The first entry is the primary provider; subsequent entries are tried in order on failure.
§Panics
This function does not panic.
Sourcepub async fn call<F, Fut, T, E>(
&self,
f: F,
) -> Result<CascadeResult<T>, CascadeError<E>>
pub async fn call<F, Fut, T, E>( &self, f: F, ) -> Result<CascadeResult<T>, CascadeError<E>>
Try each provider in order, returning the first successful result.
Open circuit breakers are skipped. For each attempted provider,
Prometheus counters cascade_attempts_total and
cascade_failures_total are updated. Per-entry latency and success
rate atomics are also updated.
§Arguments
f— An async factory that receives aWorkerKindand returns aFuture<Output = Result<T, E>>. It will be called once per attempted provider.
§Errors
Returns CascadeError::EmptyCascade when no entries are configured,
or CascadeError::AllFailed when every provider either had an open
breaker or returned an error.
§Panics
This function does not panic.
Sourcepub fn snapshot(&self) -> Vec<CascadeEntry>
pub fn snapshot(&self) -> Vec<CascadeEntry>
Return a point-in-time snapshot of all cascade entries.
Useful for health-check endpoints and dashboards.
§Panics
This function does not panic.
Trait Implementations§
Source§impl Clone for ProviderCascade
impl Clone for ProviderCascade
Source§fn clone(&self) -> ProviderCascade
fn clone(&self) -> ProviderCascade
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ProviderCascade
impl RefUnwindSafe for ProviderCascade
impl Send for ProviderCascade
impl Sync for ProviderCascade
impl Unpin for ProviderCascade
impl UnsafeUnpin for ProviderCascade
impl UnwindSafe for ProviderCascade
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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