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 delay128 seconds
Retryable errorsModelThrottledException only

Custom configuration

python
from elsai import Agent
from elsai.event_loop._retry import ModelRetryStrategy

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

Disabling retries

python
agent = Agent(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

agent = Agent(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.