Retry
Review retry settings and why invalid model IDs cannot reliably exercise the retry path.
This example assumes an invalid model ID triggers the configured retries. Invalid-model responses commonly use terminal 400 or 404 statuses, which Agno does not retry. Do not run this source as a retry test.
"""Example demonstrating how to set up retries with Google Gemini."""
from agno.agent import Agent
from agno.models.google import Gemini
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# We will use a deliberately wrong model ID, to trigger retries.
wrong_model_id = "gemini-wrong-id"
agent = Agent(
model=Gemini(
id=wrong_model_id,
retries=3, # Number of times to retry the request.
delay_between_retries=1, # Delay between retries in seconds.
exponential_backoff=True, # If True, the delay between retries is doubled each time.
),
)
agent.print_response("What is the capital of France?")
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passCurrent Alternative
Configure retries, delay_between_retries, and exponential_backoff as shown in Retry Model Requests. Test the retry path with a controlled transient 429, connection failure, or 5xx response.
Full source: cookbook/90_models/google/gemini/retry.py