Lesson 2: Switching Model Providers
Code for this lesson: samples/02-model-providers
Model Choice Is an Architecture Decision
Section titled “Model Choice Is an Architecture Decision”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.
Configuring Providers
Section titled “Configuring Providers”All providers follow the same pattern: instantiate a model class, pass it to the agent.
from strands import Agentfrom strands.models import BedrockModelfrom strands.models.anthropic import AnthropicModelfrom strands.models.ollama import OllamaModelfrom strands.models.openai import OpenAIModelimport os
# Amazon Bedrock (default if no model specified)bedrock_model = BedrockModel( model_id="us.anthropic.claude-opus-5")
# Anthropic direct APIanthropic_model = AnthropicModel( client_args={"api_key": os.environ["ANTHROPIC_API_KEY"]}, model_id="claude-sonnet-5", max_tokens=1024, params={"temperature": 0.7},)
# OpenAIopenai_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.")| Provider | Install | Auth |
|---|---|---|
| Bedrock (default) | pip install strands-agents | AWS credentials configured |
| Anthropic | pip install "strands-agents[anthropic]" | ANTHROPIC_API_KEY |
| OpenAI | pip install "strands-agents[openai]" | OPENAI_API_KEY |
| Ollama (local) | pip install "strands-agents[ollama]" | None, runs on your machine |
Multi-Model Architectures
Section titled “Multi-Model Architectures”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 Setup
Section titled “Ollama Setup”Ollama lets you run models entirely on your machine. Useful for development, offline use, or avoiding API costs.
brew install ollamaollama serveollama pull gemma4:latest