
Building AI Agents with Strands: Part 4 - Alternative Model Providers
Learn how to use different AI models with the Strands Agents SDK, including models from Amazon Bedrock and OpenAI, as well as local models with Ollama.
Dennis Traub
Amazon Employee
Published May 27, 2025
Last Modified May 28, 2025
Welcome to the fourth part of our series on building AI agents with Strands!
In the previous tutorials, we built a computer science subject expert agent (Part 1), enhanced it with custom tools (Part 2), and connected it to external services using MCP (Part 3).
So far, we've been using the default model configuration with Amazon Bedrock. But one of Strands Agents' greatest strengths is its model provider flexibility. You can easily switch between different models and providers based on your specific needs, preferences, or performance requirements.
Today, we'll explore this flexibility through hands-on examples, starting simple and building up to more advanced scenarios.
By the end of this tutorial, you'll know how to:
- Switch between different Bedrock models and AWS Regions
- Connect your agent to OpenAI and other providers
- Set up local model development with Ollama
- Understand when to use each approach
- Handle common issues when switching model providers
Before we begin, ensure you have:
- Completed Part 1: Creating Your First Agent
- The Strands Agents SDK and tools installed (
pip install strands-agents
)
One of the most powerful aspects of Strands Agents is that your agent code remains almost identical regardless of which model provider you use. Let me show you what I mean.
Here's our basic agent from Part 1:
You can switch to completely different models - and even model providers, by only adding a few lines of code. This flexibility lets you experiment with different models, optimize for cost or performance, and even switch between cloud and local deployment - all without rewriting your agent logic.
Let's start with the simplest change: using a different model on Amazon Bedrock. Maybe you want to try Amazon's Nova Pro model, or you need to deploy in a specific AWS Region.
Refer to the Amazon Bedrock User Guide for the available model IDs.
For additional
BedrockModel
configuration parameters, check out the Strands documentation.Important: You'll need to request access to specific models in your Bedrock console before using them.
Strands supports several cloud model providers beyond Amazon Bedrock. Here's how to OpenAI's GPT:
Other supported providers:
- Anthropic - Direct API access to Claude models hosted by Anthropic
- Llama API - Access to Llama models on Meta's own API service
- LiteLLM - Aunified interface for multiple providers
Now for our main focus today: running models locally. This is incredibly valuable during development because it gives you:
- Zero API costs while you're experimenting
- Offline capability - work without internet connection
- Faster iteration - no API rate limits
Let's set this up step by step.
Visit ollama.ai and follow the installation instructions for your platform. This typically involves downloading and running an installer.
Once Ollama is installed, download a model. We'll use Llama 3.2 with 3 billion parameters - it's capable but small enough to run on most development machines:
Ollama runs as a server that your agent will connect to. Open a new terminal and start it:
Keep this terminal running! You should see output like:
Note: If the port is in use, change it with the
OLLAMA_HOST
environment variable.In your original terminal (not the one running
ollama serve
):Now create a local version of our subject expert. Save this as
local_subject_expert.py
:Run your agent:
Now you have a fully functional agent running entirely on your local machine!
Local models are fantastic for development, but it's important to understand their limitations:
Strengths:
- ✅ No API costs during development
- ✅ No rate limits
- ✅ Works offline
Limitations:
- ⚠️ May struggle with complex agentic workflows compared to larger models
- ⚠️ May not follow complex multi-step instructions as reliably
- ⚠️ Require significant local hardware resources
- ⚠️ Can have difficulty with tool execution
This trade-off is often worthwhile for development and testing, but you may want to use cloud models for production agentic applications.
For highly specialized needs, you can create custom model providers by extending Strands' base
Model
class. This might be useful for:- Custom API endpoints
- Internal company models
- Specialized fine-tuned models
- Unique authentication requirements
For detailed instructions, see the Custom Model Provider documentation.
In this tutorial, we've explored Strands Agents' model provider flexibility:
- ✅ Switched Bedrock models and regions for specific requirements
- ✅ Connected to OpenAI and other cloud providers for different capabilities
- ✅ Set up local development with Ollama for cost-free experimentation
- ✅ Understood trade-offs between local and cloud models
- ✅ Learned when to use each approach based on your needs
The key insight is that Strands abstracts away model provider complexity, letting you focus on building great agents rather than managing API differences.
In the upcoming Part 5, we'll explore Conversation Management & Memory, showing you how to maintain state and context across conversations to create more engaging and personalized agent experiences.
While you wait, try these experiments:
- Compare responses from the same prompt across different models
- Test tool usage with local vs. hosted models to see the differences
- Set up multiple local models and switch between them based on query type
- Benchmark performance for your specific use cases
Here are some resources to help you deepen your understanding:
- 📚 Strands Model Providers - Comprehensive guides on all supported providers
- 🖥️ Ollama - For local model deployment
What's your preferred model provider for development vs. production? Share your experiences in the comments below!
Ollama Connection Issues:
- Ensure
ollama serve
is running in a separate terminal before starting your agent - Check that port 11434 isn't blocked by firewall settings
- If the port is in use, change it with the
OLLAMA_HOST
environment variable, e.g.,OLLAMA_HOST=127.0.0.1:8080
Model Access Problems:
- For Bedrock models, confirm you've requested access in the AWS console for the specific region(s)
- For other providers, verify your API key is valid and you haven't exceeded usage limits
- Double-check that model IDs match exactly what's supported by each provider
Performance Issues:
- Local models require significant RAM (8GB+ recommended for larger models)
- Start with smaller models like
llama3.2:1b
if you have limited resources - Cloud models typically respond faster but have per-token costs
- If local models seem slow, try reducing the
max_tokens
parameter
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.