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 Nexus."""
from agno.agent import Agent
from agno.models.nexus import Nexus
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# We will use a deliberately wrong model ID, to trigger retries.
wrong_model_id = "nexus-wrong-id"
agent = Agent(
model=Nexus(
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
Complete the basic example's two-terminal setup. Keep Nexus running with its Anthropic key in the first terminal; in the activated client terminal, save this as nexus_retry.py and run python nexus_retry.py.
The dummy bearer applies only to that unauthenticated loopback configuration. OpenAI SDK retries are disabled; Nexus/provider policies can independently retry upstream requests. Agno excludes terminal 400/404 errors. A successful call does not exercise retries; test with a controlled transient failure.
from agno.agent import Agent
from agno.models.nexus import Nexus
agent = Agent(
model=Nexus(
id="anthropic/claude-sonnet-4-6",
api_key="nexus-local",
client_params={"max_retries": 0},
retries=3,
delay_between_retries=1,
exponential_backoff=True,
)
)
agent.print_response("What is the capital of France?")Full source: cookbook/90_models/nexus/retry.py