Skip to content

Retry Strategies

elsai agents automatically retry throttling and transient errors using exponential backoff. No configuration is required — it works out of the box.

Default behaviour

ParameterDefault
Total attempts6 (1 original + 5 retries)
Initial delay4 seconds
Maximum delay240 seconds
Retryable errorsModelThrottledException only

Custom configuration

python
from elsai import Agent
from elsai.agent import AgentConfig, ModelRetryStrategy

agent = Agent(
    config=AgentConfig(
        retry_strategy=ModelRetryStrategy(
            max_attempts=6,      # total attempts including the first
            initial_delay=4,     # seconds before first retry
            max_delay=240,       # cap on backoff delay
        ),
    ),
)

Disabling retries

python
agent = Agent(config=AgentConfig(retry_strategy=None))

Custom retry logic via hooks

Override retry decisions at runtime using AfterModelCallEvent:

python
from elsai.hooks import AfterModelCallEvent
import asyncio

def custom_retry(event: AfterModelCallEvent) -> None:
    if event.exception and "rate limit" in str(event.exception).lower():
        event.retry = True   # signal the loop to retry

from elsai.agent import AgentConfig

agent = Agent(config=AgentConfig(hooks=[custom_retry]))

Retryable errors

Only ModelThrottledException is retried by default. All other exceptions propagate immediately.

ErrorRetried
Throttling / rate limitYes
Network timeoutYes (if raised as throttle error)
Invalid requestNo
Context window overflowNo — handled by conversation manager
Tool execution errorNo

Exponential backoff

Delay between attempts grows exponentially: initial_delay × 2ⁿ, capped at max_delay.

Copyright © 2026 elsai foundry.