Retry
Review retry settings and why invalid model IDs cannot reliably exercise the retry path.
At the linked revision, LlamaOpenAI fails in its formatter before sending a request. The wrong model ID below cannot test retries. Use the working compatible adapter in the Current Alternative.
"""Example demonstrating how to set up retries with Meta Llama (using OpenAI-compatible endpoint)."""
from agno.agent import Agent
from agno.models.meta import LlamaOpenAI
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# We will use a deliberately wrong model ID, to trigger retries.
wrong_model_id = "llama-wrong-id"
agent = Agent(
model=LlamaOpenAI(
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
Follow the compatible basic example's setup for dependencies and LLAMA_API_KEY, and confirm account access to the selected model. Save this complete program as meta_retry.py and run python meta_retry.py.
The generic compatible adapter preserves HTTP status codes: terminal 400/404 errors are not retryable. client_params={"max_retries": 0} disables the underlying OpenAI SDK retries, leaving Agno's retry settings to control attempts. A successful call does not exercise retries; use a controlled transient failure to test them.
from agno.agent import Agent
from os import getenv
from agno.models.openai.like import OpenAILike
def llama_model(**kwargs):
return OpenAILike(
api_key=getenv("LLAMA_API_KEY"),
base_url="https://api.llama.com/compat/v1/",
supports_native_structured_outputs=False,
supports_json_schema_outputs=True,
**kwargs,
)
agent = Agent(
model=llama_model(
id="Llama-4-Maverick-17B-128E-Instruct-FP8",
retries=3,
delay_between_retries=1,
exponential_backoff=True,
client_params={"max_retries": 0},
)
)
agent.print_response("What is the capital of France?")Full source: cookbook/90_models/meta/retry.py