Retry
Review retry settings and why invalid model IDs cannot reliably exercise the retry path.
This source uses an invalid model ID and does not reliably test retries. The native LiteLLM adapter passes SDK exceptions through without converting them to Agno's retryable ModelProviderError, so Agno's retries, delay and backoff settings do not control these failures.
"""Example demonstrating how to set up retries with LiteLLM."""
from agno.agent import Agent
from agno.models.litellm import LiteLLM
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# We will use a deliberately wrong model ID, to trigger retries.
wrong_model_id = "litellm-wrong-id"
agent = Agent(
model=LiteLLM(
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
Install agno and litellm, then use the OpenAI credentials from the basic example. Save this program as litellm_retry.py and run python litellm_retry.py.
num_retries configures LiteLLM SDK retries. For this OpenAI-backed example, max_retries=0 disables the underlying OpenAI SDK retries so they do not multiply attempts. Agno's delay/backoff fields do not configure this layer. A successful request does not demonstrate a retry; verify retry behavior with a controlled transient failure.
from agno.agent import Agent
from agno.models.litellm import LiteLLM
agent = Agent(
model=LiteLLM(
id="gpt-5.6-luna",
temperature=None,
top_p=None,
request_params={"num_retries": 1, "max_retries": 0},
)
)
agent.print_response("What is the capital of France?")Full source: cookbook/90_models/litellm/retry.py