Appearance
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
| Parameter | Default |
|---|---|
| Total attempts | 6 (1 original + 5 retries) |
| Initial delay | 4 seconds |
| Maximum delay | 128 seconds |
| Retryable errors | ModelThrottledException 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.
| Error | Retried |
|---|---|
| Throttling / rate limit | Yes |
| Network timeout | Yes (if raised as throttle error) |
| Invalid request | No |
| Context window overflow | No — handled by conversation manager |
| Tool execution error | No |
Exponential backoff
Delay between attempts grows exponentially: initial_delay × 2ⁿ, capped at max_delay.