pub struct DefaultModelRetryStrategy { /* private fields */ }Expand description
Retries model calls that fail with an error the SDK classifies as retryable
(DefaultModelRetryStrategy).
ModelThrottledError and
ModelNetworkError are retryable; set
DefaultModelRetryStrategyOptions::is_retryable to change the set. Backoff state belongs to
a retry budget and resets on each budget’s first attempt. One instance tracks its own state, so
give each agent its own instance.
use strands::{DefaultModelRetryStrategy, DefaultModelRetryStrategyOptions};
let strategy = DefaultModelRetryStrategy::new(
DefaultModelRetryStrategyOptions::builder().max_attempts(4).build(),
)
.unwrap();
assert_eq!(strategy.max_attempts(), 4);Implementations§
Source§impl DefaultModelRetryStrategy
impl DefaultModelRetryStrategy
Sourcepub const NAME: &'static str = "strands:default-model-retry-strategy"
pub const NAME: &'static str = "strands:default-model-retry-strategy"
The strategy’s name (name).
Sourcepub fn new(options: DefaultModelRetryStrategyOptions) -> Result<Self>
pub fn new(options: DefaultModelRetryStrategyOptions) -> Result<Self>
Sourcepub fn max_attempts(&self) -> u32
pub fn max_attempts(&self) -> u32
Total model attempts before giving up.
Sourcepub fn is_default_retryable(error: &Error) -> bool
pub fn is_default_retryable(error: &Error) -> bool
Whether the default classifier retries error: a throttle or a network failure.
Sourcepub fn is_retryable(&self, error: &Error) -> bool
pub fn is_retryable(&self, error: &Error) -> bool
Whether error is retried: the configured classifier, or the default one.
Trait Implementations§
Source§impl Debug for DefaultModelRetryStrategy
impl Debug for DefaultModelRetryStrategy
Source§impl Default for DefaultModelRetryStrategy
impl Default for DefaultModelRetryStrategy
Source§impl ModelRetryStrategy for DefaultModelRetryStrategy
impl ModelRetryStrategy for DefaultModelRetryStrategy
Source§fn compute_retry_decision<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
context: &'life1 ModelRetryContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<RetryDecision>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn compute_retry_decision<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
context: &'life1 ModelRetryContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<RetryDecision>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Decides whether to retry the failed model call and how long to wait first. Read more
Source§fn on_first_model_attempt(&self)
fn on_first_model_attempt(&self)
Called when
attempt_count is 1, at the start of a fresh retry budget: a new turn, or a
model router switching candidates. Strategies with per-budget state
clear it here; the default does nothing.Auto Trait Implementations§
impl !Freeze for DefaultModelRetryStrategy
impl !RefUnwindSafe for DefaultModelRetryStrategy
impl !UnwindSafe for DefaultModelRetryStrategy
impl Send for DefaultModelRetryStrategy
impl Sync for DefaultModelRetryStrategy
impl Unpin for DefaultModelRetryStrategy
impl UnsafeUnpin for DefaultModelRetryStrategy
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§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> ⓘ
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 moreCreates a shared type from an unshared type.