How to Build a Local AI Agent with Strands and Ollama

Most AI agent tutorials start with an API key and a cloud bill. This one starts with neither. Strands Agents SDK, the open-source agent framework AWS released in May 2025, runs entirely inside your own Python process, and its Ollama provider lets a local model do the reasoning. Put the two together and you get an agent that calls tools, holds a conversation, and never sends your data to a server you do not own.

The setup takes about 30 minutes, and most of that is the model download. By the end you will have a working agent with two tools and a chat loop you can extend.

Source: AWS Builder Center — the Strands SDK + Ollama learning path, from a first agent to tools, memory, and MCP.

What you need

You need Python 3.10 or newer, Ollama, and about 8 GB of free RAM. The model in this guide is Qwen3 8B, a roughly 5 GB download that handles tool calls well for its size. Qwen's documentation lists agent tool use as one of the model's strengths, and Ollama marks it as tool-capable. On a tight machine, the same steps work with qwen3:4b or llama3.2:3b, though smaller models fumble tool calls more often.

If Ollama is new to you, our Ollama quickstart covers the install on Mac, Windows, and Linux. You do not need an AWS account: Bedrock is Strands' default model provider, but swapping in Ollama is a one-line change and the rest of your agent code stays the same.

Step 1: Pull the model

First, get the model onto your machine and make sure Ollama is serving it:

ollama pull qwen3:8b
ollama serve

Keep the terminal running ollama serve open. Ollama listens on http://localhost:11434 by default, and that is the address Strands will connect to. A quick ollama list in a second terminal should show qwen3:8b in the list.

Step 2: Install Strands with Ollama support

Create a project folder and a virtual environment, then install the SDK with its Ollama extra and the optional tools package:

python -m venv .venv
source .venv/bin/activate
pip install 'strands-agents[ollama]' strands-agents-tools

The [ollama] extra pulls in the Ollama client the provider needs. Skip it and you get a ModuleNotFoundError: No module named 'ollama' the first time you import the model class, which is the single most common setup mistake in this stack.

Step 3: Your first local agent

Save this as agent.py:

from strands import Agent
from strands.models.ollama import OllamaModel

model = OllamaModel(
    host="http://localhost:11434",
    model_id="qwen3:8b",
    temperature=0.3,
)

agent = Agent(
    model=model,
    system_prompt="You are a helpful assistant. Answer clearly and briefly.",
)

print(agent("What can you help me build?"))

Run it with python agent.py. The first reply takes a while because Ollama loads the model into memory; later replies are much faster. Nothing here touches the internet except the Ollama server on your own machine, so the agent works on a plane, in a café, or behind a corporate firewall.

Step 4: Give it a tool

An agent without tools is a chatbot. In Strands, a tool is a plain Python function with the @tool decorator and a docstring, which becomes the description the model reads when it decides to call it:

from strands import Agent, tool
from strands.models.ollama import OllamaModel

@tool
def word_count(text: str) -> int:
    """Count the words in a piece of text."""
    return len(text.split())

model = OllamaModel(host="http://localhost:11434", model_id="qwen3:8b")
agent = Agent(model=model, tools=[word_count])
print(agent("How many words are in this sentence?"))

The model reads the docstring, calls word_count with the sentence, and folds the result into its answer. Write a precise docstring: vague descriptions are the usual reason a model picks the wrong tool or passes it the wrong argument.

Step 5: Add a built-in tool and a chat loop

The strands-agents-tools package ships ready-made tools, including a calculator. Combine it with your own tool and a small loop:

from strands import Agent, tool
from strands.models.ollama import OllamaModel
from strands_tools import calculator

@tool
def word_count(text: str) -> int:
    """Count the words in a piece of text."""
    return len(text.split())

model = OllamaModel(host="http://localhost:11434", model_id="qwen3:8b")
agent = Agent(model=model, tools=[calculator, word_count])

while True:
    user_input = input("You: ")
    if user_input.lower() in ("quit", "exit"):
        break
    print(agent(user_input))

Try it with What is 184 * 37? and then How many words did I just write? The first prompt should route to the calculator, the second to your function. If the agent answers from memory instead of calling a tool, tighten the system prompt: tell it to use the tools whenever a question matches one.

Where to go from here

Swap the model first: any tool-capable model Ollama serves works with the same code, so try qwen3:14b on a stronger machine and compare how often each one calls the right tool. Then connect an MCP server so the agent can reach real services; our guide to building an MCP server in Python pairs directly with Strands' built-in MCP client. And remember that the agent forgets everything when the script exits, so our Mem0 and Ollama memory guide shows how to make it remember across sessions.

Strands also keeps growing on the AWS side. This morning we covered AWS Strands Decider v2, a decision model for agent routing that runs on open weights. The local setup in this guide and that hosted decision layer are two ends of the same idea: the model is one object you hand to the agent, and where it runs is your choice.

Source: DEV — a local-first agent platform: Ollama runs the model, Strands runs the agent loop, and an MCP gateway connects outside services.

Troubleshooting

Connection refused on localhost:11434. Ollama is not running. Start it with ollama serve in its own terminal and leave it there.

ModuleNotFoundError: No module named 'ollama'. The Ollama extra is missing. Run pip install 'strands-agents[ollama]' inside the same virtual environment you run the agent from.

The agent ignores your tools. Two usual causes: the model is too small to follow tool instructions reliably, or the tool docstrings are vague. Move up to qwen3:8b if you started smaller, and rewrite each docstring as a single sentence that says exactly what the tool does and what it returns.

Replies are slow. An 8B model on CPU-only hardware answers in seconds, not milliseconds. Give Ollama your GPU if you have one, or drop to qwen3:4b and accept slightly weaker tool use in exchange for speed.

The agent answers in the wrong language or rambles. Qwen3 has a thinking mode that can leak reasoning into replies. Keep temperature low, around 0.3, and put the behaviour you want in the system prompt rather than in every user message.

Bottom line

Strands is the lightest way we have found to build an agent that stays on your machine. The whole framework is a model, a list of tools, and a loop: no graph to draw, no YAML workflow to maintain, no cloud account to open. Start with the five-line agent above, add one tool that solves a problem you actually have, and you will know within an hour whether local agents fit your work.


Comments

Popular posts from this blog

Open-Source AI Weekly: Bonsai, GigaChat 4 Lead

Claude Claims Proof of Riemann Hypothesis After 167 Years

How to Build an AI Agent with LangGraph in 30 Minutes