Skip to main content

RetryStrategy

Trait RetryStrategy 

Source
pub trait RetryStrategy: Send + Sync {
    // Required methods
    fn should_retry(&self, error: &AgentError, attempt: u32) -> bool;
    fn delay(&self, attempt: u32) -> Duration;
    fn as_any(&self) -> &dyn Any;
}
Expand description

Determines whether a failed model call should be retried and, if so, how long to wait before the next attempt.

Implementations must be object-safe (Send + Sync) so that the strategy can be stored as Box<dyn RetryStrategy> inside loop configuration.

Required Methods§

Source

fn should_retry(&self, error: &AgentError, attempt: u32) -> bool

Returns true if error on the given attempt number should be retried. Attempt numbering starts at 1.

This is the sole decision point for retryability — the agent loop delegates entirely to this method. Custom implementations can retry any error variant (e.g., AgentError::Plugin) without being gated by AgentError::is_retryable().

Source

fn delay(&self, attempt: u32) -> Duration

Returns the duration to wait before attempt number attempt. Attempt numbering starts at 1.

Source

fn as_any(&self) -> &dyn Any

Downcast helper for type-safe access to concrete strategy types.

Used by AgentOptions::to_config to extract serializable parameters from DefaultRetryStrategy.

Implementors§