Skip to content

Lesson 2: Switching Model Providers

Play

Watch on YouTube

Code for this lesson: samples/02-model-providers

Different models have different strengths, costs, latency characteristics, and tool-use behavior. Strands abstracts providers behind a common interface so your agent code stays the same regardless of the underlying model. Your tools, system prompt, and orchestration logic don’t change when you swap the model.

All providers follow the same pattern: instantiate a model class, pass it to the agent.

from strands import Agent
from strands.models import BedrockModel
from strands.models.anthropic import AnthropicModel
from strands.models.ollama import OllamaModel
from strands.models.openai import OpenAIModel
import os
# Amazon Bedrock (default if no model specified)
bedrock_model = BedrockModel(
model_id="us.anthropic.claude-opus-5"
)
# Anthropic direct API
anthropic_model = AnthropicModel(
client_args={"api_key": os.environ["ANTHROPIC_API_KEY"]},
model_id="claude-sonnet-5",
max_tokens=1024,
params={"temperature": 0.7},
)
# OpenAI
openai_model = OpenAIModel(
client_args={"api_key": os.environ["OPENAI_API_KEY"]},
model_id="gpt-4o",
params={"max_tokens": 1000, "temperature": 0.7},
)
# Local with Ollama (no cloud APIs needed)
ollama_model = OllamaModel(
host="http://localhost:11434",
model_id="gemma4:latest",
)
# Use any provider. Agent code stays identical.
agent = Agent(model=ollama_model)
agent("Explain the agent loop in one paragraph.")

📂 model_providers.py

ProviderInstallAuth
Bedrock (default)pip install strands-agentsAWS credentials configured
Anthropicpip install "strands-agents[anthropic]"ANTHROPIC_API_KEY
OpenAIpip install "strands-agents[openai]"OPENAI_API_KEY
Ollama (local)pip install "strands-agents[ollama]"None, runs on your machine

In sophisticated systems, different agents use different models:

  • Fast/cheap model for lightweight classification
  • Strong reasoning model for orchestration
  • Specialized model for code generation
  • A different provider entirely for evaluation/verification (avoids same-model bias)

Ollama lets you run models entirely on your machine. Useful for development, offline use, or avoiding API costs.

Terminal window
brew install ollama
ollama serve
ollama pull gemma4:latest