How to Build a Multi-Agent Crew with CrewAI and Ollama
What CrewAI does, and why run it locally
CrewAI is an open-source Python framework for teams of AI agents. You define agents with a role, a goal, and a backstory, give each one tasks with a clear expected output, then let the crew pass work from one agent to the next. A researcher gathers facts while a writer turns them into a finished document.
Pairing CrewAI with Ollama keeps the whole system on your own machine. There is no API key to manage, no per-token bill, and your prompts never leave your network. The trade-off is speed: a local 8B model answers more slowly than a hosted frontier model, and it needs clearer instructions. For learning the framework and for private work, that trade is usually worth it.
This guide builds a working two-agent crew in about 30 minutes. A researcher agent collects facts about a topic, a writer agent turns them into a 300-word briefing, and the result lands in a file called briefing.md. If you already have Ollama running, skip to step 2. If you want a single-agent starting point first, our single-agent LangGraph tutorial covers that path.
Source: Medium — a CrewAI crew with a manager agent, worker agents, and tasks.
What you need
- Python 3.10 to 3.13. CrewAI 1.15, the current release line, supports that range.
- Ollama installed, with the
qwen3:8bmodel pulled. Our Ollama setup guide walks through the install if you have not done it yet. - About 6 GB of free disk space for the model, and 16 GB of RAM for comfortable runs.
Step 1: Get Ollama running
Pull the model the crew will use, then check that the Ollama server answers:
ollama pull qwen3:8b
ollama list
If ollama list shows qwen3:8b, the server is up.
Step 2: Install CrewAI
Create a project folder and a virtual environment, then install CrewAI with its tools extra:
mkdir crew-demo && cd crew-demo
python3 -m venv .venv
source .venv/bin/activate
pip install "crewai[tools]"
On Windows, activate the environment with .venv\Scripts\activate instead. If you prefer uv, uv venv --python 3.12 followed by uv pip install "crewai[tools]" does the same job.
CrewAI sends anonymous usage telemetry unless you switch it off. Add this line to your shell profile or a .env file if you want it off:
export CREWAI_DISABLE_TELEMETRY=true
Step 3: Point CrewAI at your local model
CrewAI talks to Ollama through Ollama's OpenAI-compatible endpoint. One LLM object holds the connection, and every agent in the crew shares it:
from crewai import LLM
local_llm = LLM(
model="ollama/qwen3:8b",
base_url="http://localhost:11434",
temperature=0.2,
)
The ollama/ prefix tells CrewAI which provider to use, and base_url points at the Ollama server on your machine. A low temperature like 0.2 keeps research and writing factual instead of creative. Swap models later by changing one string.
Step 4: Define two agents
Each agent gets a role, a goal, and a backstory. The backstory is not decoration — it shapes how the model approaches its work, so keep it specific:
from crewai import Agent
researcher = Agent(
role="Senior Research Analyst",
goal="Find accurate, current facts about a topic and note the sources",
backstory="You are a careful analyst who checks claims before passing them on.",
llm=local_llm,
verbose=True,
allow_delegation=False,
)
writer = Agent(
role="Technical Writer",
goal="Turn research notes into a clear 300-word briefing",
backstory="You write short briefings that busy engineers can read in two minutes.",
llm=local_llm,
verbose=True,
allow_delegation=False,
)
Setting allow_delegation=False keeps the researcher from handing its own task to the writer mid-run. verbose=True prints each agent's reasoning to the terminal, which is the fastest way to see where a crew goes wrong.
Step 5: Define the tasks
A task needs two things: a description of the work, and an expected_output that states what "done" looks like. Vague tasks are the most common reason a crew produces vague results, so write the output format into the task itself:
from crewai import Task
research_task = Task(
description=(
"Research the topic 'open-weight vision models that run on a laptop'. "
"List three models, what hardware each needs, and one source per model."
),
expected_output="A bullet list of three models with hardware needs and sources.",
agent=researcher,
)
writing_task = Task(
description=(
"Write a 300-word briefing from the research notes. "
"Keep the hardware numbers and sources exactly as the researcher wrote them."
),
expected_output="A 300-word briefing saved to briefing.md.",
agent=writer,
output_file="briefing.md",
)
The writing task carries one guardrail: keep the researcher's numbers unchanged. Small local models tend to round numbers or invent cleaner ones, and a one-line instruction is the cheapest fix.
Source: Another Coding Blog — how CrewAI agents map to tasks.
Step 6: Assemble the crew and run it
The Crew object ties agents and tasks together. Process.sequential runs the tasks in order, so the writer only starts once the researcher has finished:
from crewai import Crew, Process
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
process=Process.sequential,
)
result = crew.kickoff()
print(result)
Save everything as main.py and run python main.py. The first run takes a few minutes on CPU-only hardware, and when it finishes, briefing.md sits in the project folder.
Step 7 (optional): Let a manager run the crew
Sequential crews suit fixed pipelines. For open-ended work, Process.hierarchical adds a manager agent that plans the job and assigns tasks on the fly. Give the manager a larger model than the workers, since planning is the hardest part of the job.
manager_llm = LLM(
model="ollama/qwen3:14b",
base_url="http://localhost:11434",
temperature=0.1,
)
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
process=Process.hierarchical,
manager_llm=manager_llm,
)
Hierarchical crews make more model calls than sequential ones, so expect longer runs. Start with sequential, and switch only when the workflow itself needs deciding at run time.
Troubleshooting
- Connection refused on port 11434: Ollama is not running. Start it with
ollama servein a separate terminal, then run the crew again. - Model not found: the model name in the
LLMobject does not match a pulled model. Runollama listand copy the name exactly, tag included. - ImportError mentioning LiteLLM: install the optional extra with
pip install "crewai[litellm]". Some CrewAI versions still route Ollama through LiteLLM. - The crew is very slow: drop to a smaller model such as
qwen3:8b, or run Ollama with GPU acceleration. Each agent call is a full model run, so two agents cost roughly twice the time of one. - The writer invents numbers: tighten the task description and keep
temperatureat 0.2 or below. If that is not enough, move the writer to a 14B model.
When a crew is overkill
Two agents are not always better than one. A crew of five agents means roughly five times the tokens and five chances for a run to go sideways, and a single prompt with a loop handles many jobs just as well. Use a crew when the work splits into genuinely different skills, such as research plus writing, coding plus review, or planning plus execution. If one agent could do the whole job by calling tools, start there instead. Our guide to giving a local model tools shows what a single capable agent can already do.
Once this crew runs, the next steps are cheap: add a third agent that checks the briefing against the sources, or attach a web-search tool so the researcher stops relying on training data. The pattern stays the same, and the crew grows one agent at a time.


Comments
Post a Comment