Skip to main content

RetryProvider

Struct RetryProvider 

Source
pub struct RetryProvider<I> { /* private fields */ }
Expand description

Retry wrapper: implements Provider and retries inner failures per RetryPolicy.

Streaming semantics: only when stream_chat returns Err (connection setup failure) is the whole call retried; errors inside the stream are passed through verbatim and never retried — once the stream is established this implementation cannot tell an “interruption before the first event” from an “interruption after part of the output was delivered”, and retrying would duplicate or corrupt output. Hence “retry before the first event” only covers method-level failures; interruptions within the stream (including after setup but before the first event) are left to the caller (the Agent) to handle.

Timeouts are the inner provider’s (for example OpenAiProvider) responsibility: each attempt may hit the inner Timeout error, and Retryable::Default includes Timeout, so “timeouts are retried too” falls out naturally.

§Errors

After retries are exhausted, the last error is returned (neither the first nor an aggregate); non-retryable errors are returned immediately on the first failure.

§Cancellation semantics

Dropping the future while waiting on backoff cancels the whole call; no further attempts are made. An already-issued inner request is cancelled together with the future (whether the network request continues at the transport layer depends on the underlying client).

Implementations§

Source§

impl<I> RetryProvider<I>

Source

pub fn new(inner: I) -> RetryProvider<I>

Wraps with the default policy (3 attempts / exponential backoff + jitter / default retry judgment).

Source

pub fn with_policy(self, policy: RetryPolicy) -> RetryProvider<I>

Replaces the retry policy.

§Examples

For tests / local simulation: fixed short waits, at most 2 attempts, ignoring the vendor’s Retry-After:

use std::time::Duration;
use molo::{Backoff, FakeProvider, RetryPolicy, RetryProvider};

let provider = RetryProvider::new(FakeProvider::new([])).with_policy(
    RetryPolicy::default()
        .with_max_attempts(2)
        .with_backoff(Backoff::Fixed(Duration::from_millis(10)))
        .with_respect_retry_after(false),
);

Trait Implementations§

Source§

impl<I> Debug for RetryProvider<I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<I> Provider for RetryProvider<I>
where I: Provider + Send + Sync,

Source§

fn model(&self) -> Option<&str>

Model identifier exposed by this provider, when known. Read more
Source§

fn capabilities(&self) -> ProviderCapabilities

Capability metadata for this provider instance.
Source§

fn chat<'life0, 'async_trait>( &'life0 self, request: ChatRequest, ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, ProviderError>> + Send + 'async_trait>>
where 'life0: 'async_trait, RetryProvider<I>: 'async_trait,

Sends one turn of conversation and returns the model’s reply (text, or a request to call tools). Read more
Source§

fn chat_with_context<'life0, 'life1, 'async_trait>( &'life0 self, request: ChatRequest, context: &'life1 ProviderRequestContext, ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, ProviderError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, RetryProvider<I>: 'async_trait,

Sends one turn with request-scoped provider context. Read more
Source§

fn stream_chat<'life0, 'async_trait>( &'life0 self, request: ChatRequest, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamEvent, ProviderError>> + Send>>, ProviderError>> + Send + 'async_trait>>
where 'life0: 'async_trait, RetryProvider<I>: 'async_trait,

Streams one turn of conversation for direct provider use. Read more
Source§

fn stream_chat_with_context<'life0, 'life1, 'async_trait>( &'life0 self, request: ChatRequest, context: &'life1 ProviderRequestContext, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamEvent, ProviderError>> + Send>>, ProviderError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, RetryProvider<I>: 'async_trait,

Streams one turn with request-scoped provider context. Read more

Auto Trait Implementations§

§

impl<I> !RefUnwindSafe for RetryProvider<I>

§

impl<I> !UnwindSafe for RetryProvider<I>

§

impl<I> Freeze for RetryProvider<I>
where I: Freeze,

§

impl<I> Send for RetryProvider<I>
where I: Send,

§

impl<I> Sync for RetryProvider<I>
where I: Sync,

§

impl<I> Unpin for RetryProvider<I>
where I: Unpin,

§

impl<I> UnsafeUnpin for RetryProvider<I>
where I: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more