pub struct RetryingProvider<P> { /* private fields */ }Expand description
Wraps any LlmProvider with automatic retry + exponential backoff.
Retries on:
- HTTP 429 (rate limit)
- HTTP 500, 502, 503, 529 (server errors)
- Network errors (
Error::Http)
Does NOT retry on:
- HTTP 400, 401, 403, 404 (client errors — retrying won’t help)
- JSON/SSE parse errors (deterministic failures)
- Agent/Config/Memory/Store errors (not LLM-related)
Implementations§
Source§impl<P> RetryingProvider<P>
impl<P> RetryingProvider<P>
Sourcepub fn new(inner: P, config: RetryConfig) -> Self
pub fn new(inner: P, config: RetryConfig) -> Self
Wrap inner with the given retry configuration.
Sourcepub fn with_defaults(inner: P) -> Self
pub fn with_defaults(inner: P) -> Self
Wrap a provider with default retry config (3 retries, 500ms base delay).
Sourcepub fn with_on_retry(self, callback: Arc<OnRetry>) -> Self
pub fn with_on_retry(self, callback: Arc<OnRetry>) -> Self
Set a callback invoked before each retry attempt.
The callback receives (attempt, max_retries, delay_ms, error_class).
Trait Implementations§
Source§impl<P: LlmProvider> LlmProvider for RetryingProvider<P>
impl<P: LlmProvider> LlmProvider for RetryingProvider<P>
Source§async fn complete(
&self,
request: CompletionRequest,
) -> Result<CompletionResponse, Error>
async fn complete( &self, request: CompletionRequest, ) -> Result<CompletionResponse, Error>
Send a completion request and wait for the full response.
Source§async fn stream_complete(
&self,
request: CompletionRequest,
on_text: &OnText,
) -> Result<CompletionResponse, Error>
async fn stream_complete( &self, request: CompletionRequest, on_text: &OnText, ) -> Result<CompletionResponse, Error>
Stream a completion, calling
on_text for each text delta as it arrives. Read moreAuto Trait Implementations§
impl<P> Freeze for RetryingProvider<P>where
P: Freeze,
impl<P> !RefUnwindSafe for RetryingProvider<P>
impl<P> Send for RetryingProvider<P>where
P: Send,
impl<P> Sync for RetryingProvider<P>where
P: Sync,
impl<P> Unpin for RetryingProvider<P>where
P: Unpin,
impl<P> UnsafeUnpin for RetryingProvider<P>where
P: UnsafeUnpin,
impl<P> !UnwindSafe for RetryingProvider<P>
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
Source§impl<P> DynLlmProvider for Pwhere
P: LlmProvider,
impl<P> DynLlmProvider for Pwhere
P: LlmProvider,
Source§fn complete<'a>(
&'a self,
request: CompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, Error>> + Send + 'a>>
fn complete<'a>( &'a self, request: CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, Error>> + Send + 'a>>
Boxed-future version of
LlmProvider::complete for object-safe dispatch.Source§fn stream_complete<'a>(
&'a self,
request: CompletionRequest,
on_text: &'a (dyn Fn(&str) + Sync + Send + 'static),
) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, Error>> + Send + 'a>>
fn stream_complete<'a>( &'a self, request: CompletionRequest, on_text: &'a (dyn Fn(&str) + Sync + Send + 'static), ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, Error>> + Send + 'a>>
Boxed-future version of
LlmProvider::stream_complete for object-safe dispatch.Source§fn model_name(&self) -> Option<&str>
fn model_name(&self) -> Option<&str>
Return the model identifier, if known.