Retry

Understand the native Ollama retry limitation and configure retries through its compatible endpoint.

At the linked revision, the native Ollama adapter passes SDK HTTP and connection errors through without converting them into Agno's retryable model errors. Its retries settings do not repeat those failures, including 429 and 5xx errors. The invalid-ID source below does not test retries.

retry.py
"""Example demonstrating how to set up retries with Ollama."""

from agno.agent import Agent
from agno.models.ollama import Ollama

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

# We will use a deliberately wrong model ID, to trigger retries.
wrong_model_id = "ollama-wrong-id"

agent = Agent(
    model=Ollama(
        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__":
    pass

Current Alternative

Follow the local basic example's setup, including clearing the cloud key, starting Ollama and pulling llama3.1:8b. Also install openai with uv pip install openai. Save this program as ollama_retry.py and run python ollama_retry.py.

This uses Ollama's OpenAI-compatible Chat endpoint. Its generic adapter translates HTTP/connection errors so Agno can apply retries. The dummy client key is for the unauthenticated local server. OpenAI SDK retries are disabled to avoid multiplying attempts; Agno still excludes terminal 400/404 errors. A successful request does not prove retries; test using a controlled transient failure.

ollama_retry.py
from agno.agent import Agent
from agno.models.openai.like import OpenAILike

agent = Agent(
    model=OpenAILike(
        id="llama3.1:8b",
        base_url="http://localhost:11434/v1",
        api_key="ollama",
        client_params={"max_retries": 0},
        retries=1,
        delay_between_retries=1,
    )
)
agent.print_response("What is the capital of France?")

Full source: cookbook/90_models/ollama/chat/retry.py