Skip to main content

Agent Retry Strategies

Implementing robust retry strategies is crucial for building resilient multi-agent systems that can handle transient failures gracefully. This guide covers various retry patterns and their implementation.
PraisonAI has built-in LLM retry support — enabled by default on every Agent(). See Agent Retry for the API reference and for the retry=False opt-out before implementing custom retry logic.
The on_retry hook fires identically on agent.chat() and await agent.achat() — the examples below work for both.

Retry Strategy Fundamentals

When to Retry

  1. Transient Network Errors: Temporary connectivity issues
  2. Rate Limiting: API throttling responses
  3. Temporary Resource Unavailability: Database locks, service restarts
  4. Timeout Errors: Slow responses that exceed limits
  5. Partial Failures: When part of an operation succeeds

When NOT to Retry

  1. Authentication Failures: Invalid credentials
  2. Authorization Errors: Insufficient permissions
  3. Invalid Input: Malformed requests
  4. Business Logic Errors: Domain-specific failures
  5. Resource Not Found: 404 errors

Retry Patterns

1. Exponential Backoff with Jitter

Prevent thundering herd problems with randomized delays:
PraisonAI now ships a built-in tool circuit breaker that wraps every tool call automatically. See Tool Circuit Breaker. The examples below show how to extend or customise that pattern.

2. Circuit Breaker with Retry

Combine circuit breaker pattern with intelligent retry:

3. Adaptive Retry Strategy

Adjust retry behavior based on success patterns:

4. Retry with Fallback

Implement retry with progressive fallback options:

5. Contextual Retry Strategy

Different retry strategies based on context:

Advanced Retry Patterns

1. Bulkhead Retry Pattern

Isolate retry resources to prevent cascade failures:

2. Hedged Requests Pattern

Send multiple requests and use the first successful response:

Monitoring and Metrics

Retry Metrics Collector

Best Practices

  1. Idempotency: Ensure operations can be safely retried
  2. Retry Budgets: Limit total retry time
  3. Error Classification: Retry only appropriate errors

Testing Retry Strategies

Built-in Task Guardrail Retries

PraisonAI provides built-in retry functionality specifically for guardrail validation failures, distinct from the generic ExponentialBackoffRetry patterns above.
Guardrail retries are handled automatically by the executor when Task(guardrail=..., max_retries=...) is configured. This is separate from manual retry implementations.
This differs from manual retry strategies as it’s integrated into the task execution workflow and handles the retry loop at the executor level.

Conclusion

Implementing robust retry strategies is essential for building resilient multi-agent systems. By choosing the appropriate retry pattern and configuring it correctly, you can handle transient failures gracefully while avoiding issues like retry storms and cascading failures.