How to Configure OpenAI, Anthropic, and Ollama Model Providers in Agno

Agno configures AI backends using a <provider>:<model_id> string format that resolves to provider-specific classes via the get_model() utility, enabling seamless switching between OpenAI, Anthropic, and local Ollama instances without modifying agent logic.

The agno-agi/agno framework abstracts every LLM service behind a unified Model interface, allowing you to configure different model providers like OpenAI, Anthropic, and Ollama in Agno using simple string identifiers. This design decouples your agent logic from vendor-specific implementation details, letting you swap GPT-4o for Claude or a local Llama model by changing a single configuration string.

Understanding the Provider String Format

Agno identifies every model using a colon-delimited syntax: <provider>:<model_id>. The provider prefix determines which backend class instantiates the connection, while the model ID specifies the exact model variant to invoke.

String Provider Model ID
openai:gpt-4o OpenAI gpt-4o
anthropic:claude-3-5-sonnet Anthropic claude-3-5-sonnet
ollama:llama3.1:8b Ollama llama3.1:8b

If you omit the provider prefix, Agno defaults to OpenAI, raising a clear error if the openai package is not installed.

Core Architecture and Model Resolution

The get_model() Dispatcher

The central entry point for model resolution resides in libs/agno/agno/models/utils.py. The get_model() function parses the configuration string, normalizes the provider name, and delegates instantiation to a provider-specific factory:


# libs/agno/agno/models/utils.py (lines 256-270)

def get_model(model: Union[Model, str, None]) -> Optional[Model]:
    if isinstance(model, Model):
        return model
    if not model:
        return None
    parts = model.split(":")
    if len(parts) != 2:
        raise ValueError(...)
    model_provider, model_id = parts
    model_provider = model_provider.strip().lower()
    return _get_model_class(model_id, model_provider)

The internal _get_model_class() function maintains a dispatch table mapping normalized provider names to concrete model implementations.

Provider-Specific Implementations

Each supported backend lives in its own sub-package under libs/agno/agno/models/:

These classes handle authentication, request formatting, and response parsing. The reasoning manager (libs/agno/agno/reasoning/ollama.py and libs/agno/agno/reasoning/anthropic.py) detects provider types at runtime to route streaming and reasoning hooks appropriately.

Configuration Examples

Configuring OpenAI Models

Import get_model and pass an openai: prefixed string to instantiate the OpenAIChat class. The prefix is optional if you rely on the OpenAI default.

from agno.models.utils import get_model
from agno.agent import Agent

openai_model = get_model("openai:gpt-4o")
agent = Agent(name="OpenAI Agent", model=openai_model)

response = agent.run("Explain quantum entanglement in two sentences.")
print(response.content)

Configuring Anthropic Claude Models

Switching to Anthropic requires only changing the configuration string. The Claude class in libs/agno/agno/models/anthropic/claude.py handles the underlying API calls.

anthropic_model = get_model("anthropic:claude-3-5-sonnet")
agent = Agent(name="Claude Agent", model=anthropic_model)

print(agent.run("Write a short haiku about sunrise.").content)

Configuring Local Ollama Models

For local inference, use the ollama: prefix. The Ollama class supports both streaming and non-streaming modes, with the reasoning manager automatically invoking Ollama-specific helpers when detected.

ollama_model = get_model("ollama:llama3.1:8b")
agent = Agent(name="Local Agent", model=ollama_model)

# Streaming and reasoning work transparently

result = agent.run("Generate a JSON summary of the following text.")
print(result.content)

Dynamic Provider Switching

You can override the model at runtime without reconstructing the agent. The run() method accepts a model parameter that temporarily supersedes the agent's default:

from agno.models.utils import get_model
from agno.team import Team

# Default configuration uses OpenAI

team = Team(name="Eval Team", model=get_model("openai:gpt-4o"))

# Override with Anthropic for a specific evaluation

eval_result = team.run(
    "Assess the factual accuracy of this claim.",
    model=get_model("anthropic:claude-3-5-sonnet")
)

Advanced Configuration Patterns

YAML-Based Configuration

Externalize provider selection to configuration files for environment-specific deployments:


# config.yaml

model: "anthropic:claude-3-5-sonnet"
import yaml
from agno.models.utils import get_model
from agno.agent import Agent

with open("config.yaml") as f:
    cfg = yaml.safe_load(f)

model = get_model(cfg["model"])
agent = Agent(name="Configured Agent", model=model)

Runtime Model Overrides

The get_model() utility integrates with Agno's evaluation and memory systems. When using libs/agno/agno/utils/streamlit.py, the helper get_model_with_provider() wraps this logic for UI layers, ensuring consistent provider resolution across CLI and web interfaces.

Summary

  • String Format: Use <provider>:<model_id> syntax (e.g., openai:gpt-4o, anthropic:claude-3-5-sonnet, ollama:llama3.1:8b) to specify backends.
  • Central Dispatcher: The get_model() function in libs/agno/agno/models/utils.py parses strings and routes to provider classes like OpenAIChat, Claude, or Ollama.
  • Default Behavior: Omitting the provider prefix defaults to OpenAI; missing packages trigger helpful error messages.
  • Unified Interface: Agents, Teams, and Memory managers accept any Model subclass, ensuring code remains agnostic to whether the backend is cloud-hosted or local.
  • Extensibility: Adding new providers requires only a new sub-package implementing the Model interface and an entry in the _get_model_class dispatch table.

Frequently Asked Questions

What is the default model provider in Agno?

If you provide a model string without a provider prefix (e.g., gpt-4o instead of openai:gpt-4o), Agno assumes OpenAI as the default provider. The framework attempts to instantiate OpenAIChat from libs/agno/agno/models/openai/chat.py and raises a clear ValueError or import error if the openai Python package is not installed.

How does Agno handle missing provider packages?

When get_model() resolves a provider prefix, it attempts to import the corresponding model class. If the required vendor SDK (e.g., anthropic or ollama) is missing from your environment, Agno raises an informative error at instantiation time rather than at import, allowing you to install only the dependencies you need for your chosen providers.

Can I use multiple different providers in the same Agno application?

Yes. Because get_model() returns concrete Model instances that share the same base interface, you can initialize multiple agents or teams with different providers within the same process. For example, you can run an OpenAI agent alongside an Ollama agent, or dynamically switch providers during evaluation runs by passing different model instances to the run() method.

Does Agno support streaming for all model providers?

Agno supports streaming for OpenAI, Anthropic, and Ollama, but the implementation details vary by provider. The reasoning manager detects the provider type (via checks like is_ollama_reasoning_model()) and routes to provider-specific streaming helpers in libs/agno/agno/reasoning/ollama.py or libs/agno/agno/reasoning/anthropic.py. All providers expose the same streaming interface to your application code, ensuring consistent behavior regardless of the backend.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →