pub struct ModelRetry { /* private fields */ }Available on crate feature
tool-loop only.Expand description
How a loop retries a turn the provider refused as rate limited
(ModelError::RateLimited); set with
ToolLoop::with_model_retry.
No other failure is retried. Each wait is:
- the provider’s
Retry-After, lengthened by up to a quarter at random, so loops refused together do not come back together, and never more thanmax_delay; aRetry-Afterlonger thanmax_delayis not waited for, and the run fails with the 429; - with no
Retry-After,base_delaydoubled for each retry already made, at mostmax_delay, and then between half and all of that at random.
A wait longer than the budget’s remaining time (ADR 0023) is not made either: the run fails with the 429 then, rather than after the deadline.
use std::time::Duration;
use a2a_protocol_server::tool_loop::ModelRetry;
let retry = ModelRetry::new()
.with_max_retries(5)
.with_max_delay(Duration::from_secs(10));
assert_eq!(retry.max_retries(), 5);
assert_eq!(retry.base_delay(), Duration::from_millis(500));Implementations§
Source§impl ModelRetry
impl ModelRetry
Sourcepub const fn new() -> ModelRetry
pub const fn new() -> ModelRetry
Three retries, from 500 ms, waiting at most 30 s each.
Sourcepub const fn with_max_retries(self, max_retries: u32) -> ModelRetry
pub const fn with_max_retries(self, max_retries: u32) -> ModelRetry
Sets how many times one turn may be sent again.
Sourcepub const fn with_base_delay(self, base_delay: Duration) -> ModelRetry
pub const fn with_base_delay(self, base_delay: Duration) -> ModelRetry
Sets the first wait when the provider gave no Retry-After.
Sourcepub const fn with_max_delay(self, max_delay: Duration) -> ModelRetry
pub const fn with_max_delay(self, max_delay: Duration) -> ModelRetry
Sets the longest wait.
Sourcepub const fn max_retries(&self) -> u32
pub const fn max_retries(&self) -> u32
How many times one turn may be sent again.
Sourcepub const fn base_delay(&self) -> Duration
pub const fn base_delay(&self) -> Duration
The first wait when the provider gave no Retry-After.
Trait Implementations§
Source§impl Clone for ModelRetry
impl Clone for ModelRetry
Source§fn clone(&self) -> ModelRetry
fn clone(&self) -> ModelRetry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ModelRetry
Source§impl Debug for ModelRetry
impl Debug for ModelRetry
Source§impl Default for ModelRetry
impl Default for ModelRetry
Source§fn default() -> ModelRetry
fn default() -> ModelRetry
impl Eq for ModelRetry
Source§impl PartialEq for ModelRetry
impl PartialEq for ModelRetry
impl StructuralPartialEq for ModelRetry
Auto Trait Implementations§
impl Forget for ModelRetry
impl Freeze for ModelRetry
impl Move for ModelRetry
impl RefUnwindSafe for ModelRetry
impl Send for ModelRetry
impl Sync for ModelRetry
impl Unpin for ModelRetry
impl UnsafeUnpin for ModelRetry
impl UnwindSafe for ModelRetry
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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<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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§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].