pub struct ResilientLlmProvider<P: LlmProvider> {
inner: P,
config: LlmResilienceConfig,
breaker: Mutex<CircuitBreaker>,
budget: Mutex<BudgetTracker>,
}Expand description
LLM provider wrapper with circuit breaker and budget instrumentation.
Fields§
§inner: P§config: LlmResilienceConfig§breaker: Mutex<CircuitBreaker>§budget: Mutex<BudgetTracker>Implementations§
Source§impl<P: LlmProvider> ResilientLlmProvider<P>
impl<P: LlmProvider> ResilientLlmProvider<P>
Sourcepub fn new(inner: P, config: LlmResilienceConfig) -> Self
pub fn new(inner: P, config: LlmResilienceConfig) -> Self
Creates a new resilient LLM provider wrapper.
fn execute<T, F>(&self, operation: &'static str, call: F) -> Result<T>
fn record_success( &self, provider: &'static str, operation: &'static str, elapsed: Duration, )
fn handle_failure( &self, provider: &'static str, operation: &'static str, err: Error, elapsed: Duration, attempts: u32, max_attempts: u32, ) -> FailureAction
fn record_failure( &self, provider: &'static str, operation: &'static str, elapsed: Duration, is_timeout: bool, retryable: bool, )
fn record_breaker_success_state(&self) -> u8
fn record_request_metrics( &self, provider: &'static str, operation: &'static str, elapsed: Duration, is_error: bool, is_timeout: bool, )
fn record_budget_metrics( &self, provider: &'static str, operation: &'static str, ratio: f64, )
fn record_breaker_state(provider: &'static str, breaker_state: u8)
Sourcefn calculate_retry_delay(base_delay_ms: u64, attempt: u32) -> u64
fn calculate_retry_delay(base_delay_ms: u64, attempt: u32) -> u64
Calculates retry delay with exponential backoff and jitter (CHAOS-CRIT-001/002/003).
Formula: base_delay * 2^(attempt-1) + jitter
- Exponential growth prevents overwhelming a recovering service
- Jitter (0-50% of delay) prevents thundering herd problem
- Maximum delay capped at 10 seconds
Sourcefn calculate_jitter(delay_ms: u64) -> u64
fn calculate_jitter(delay_ms: u64) -> u64
Calculates jitter for retry backoff using system time as pseudo-random source.
Trait Implementations§
Source§impl<P: LlmProvider> LlmProvider for ResilientLlmProvider<P>
impl<P: LlmProvider> LlmProvider for ResilientLlmProvider<P>
Source§fn complete(&self, prompt: &str) -> Result<String>
fn complete(&self, prompt: &str) -> Result<String>
Generates a completion for the given prompt. Read more
Source§fn complete_with_system(&self, system: &str, user: &str) -> Result<String>
fn complete_with_system(&self, system: &str, user: &str) -> Result<String>
Generates a completion with a system prompt. Read more
Source§fn analyze_for_capture(&self, content: &str) -> Result<CaptureAnalysis>
fn analyze_for_capture(&self, content: &str) -> Result<CaptureAnalysis>
Analyzes content for memory capture. Read more
Source§fn analyze_for_capture_extended(
&self,
content: &str,
existing_memories: Option<&str>,
) -> Result<ExtendedCaptureAnalysis>
fn analyze_for_capture_extended( &self, content: &str, existing_memories: Option<&str>, ) -> Result<ExtendedCaptureAnalysis>
Analyzes content for memory capture with extended security analysis. Read more
Source§fn classify_search_intent(&self, prompt: &str) -> Result<ExtendedSearchIntent>
fn classify_search_intent(&self, prompt: &str) -> Result<ExtendedSearchIntent>
Classifies search intent with namespace weights. Read more
Source§fn analyze_for_consolidation(
&self,
memories: &str,
) -> Result<ConsolidationAnalysis>
fn analyze_for_consolidation( &self, memories: &str, ) -> Result<ConsolidationAnalysis>
Analyzes memories for consolidation. Read more
Auto Trait Implementations§
impl<P> !Freeze for ResilientLlmProvider<P>
impl<P> RefUnwindSafe for ResilientLlmProvider<P>where
P: RefUnwindSafe,
impl<P> Send for ResilientLlmProvider<P>
impl<P> Sync for ResilientLlmProvider<P>
impl<P> Unpin for ResilientLlmProvider<P>where
P: Unpin,
impl<P> UnwindSafe for ResilientLlmProvider<P>where
P: UnwindSafe,
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
Mutably borrows from an owned value. Read more
§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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].