Skip to main content
Agents operating in production need to handle failures gracefully. The Agent class provides built-in mechanisms for retrying failed operations and controlling error propagation.

Retry Configuration

You can control how many times an agent attempts to execute a task before failing.
  • retry: The number of additional attempts after the first failure.
  • mode: How to handle the final failure ("raise" or "return_false").

Basic Retry Logic

Safe Mode (Return False)

If you prefer the agent to return False instead of crashing your application on failure:

Best Practices

  • Network Instability: Set retry >= 2 for agents using web search or external APIs.
  • Production Systems: Use mode="raise" inside a try/catch block to log specific errors while keeping the application running.