CrewAI Tutorial: Build a Multi-Agent Research Team
Learn how to orchestrate autonomous AI agents using CrewAI. We'll build a team of specialized agents (Researcher, Writer, Editor) to automate content creation.
By AI Mastermind Lab · Published 8 Mar 2026
TL;DR: CrewAI is a framework for orchestrating role-playing, autonomous AI agents. Instead of prompting a single LLM to do everything, you create specialized agents (e.g., a Researcher, a Writer, an Editor), give them tools, and let them collaborate to solve complex tasks. In this tutorial, we will build an automated research team.
While frameworks like LangChain excel at creating single agents, CrewAI focuses entirely on multi-agent orchestration. It allows you to define roles, goals, and backstories for different agents, and then assign them specific tasks to execute sequentially or hierarchically.
In this tutorial, we'll build a "Content Creation Crew" consisting of three agents:
- The Senior Researcher: Searches the web and gathers facts.
- The Tech Writer: Turns the facts into an engaging blog post.
- The Editor: Reviews the post for formatting and clarity.
Prerequisites
pip install crewai langchain-community duckduckgo-search
You will need an OpenAI API key (or you can use Ollama for local models). For this tutorial, we'll use OpenAI.
export OPENAI_API_KEY="your-key-here"
Step 1: Define Your Tools
Agents need tools to interact with the world. We'll give our Researcher the ability to search the web using DuckDuckGo.
from langchain_community.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()
Step 2: Create the Agents
An agent in CrewAI is defined by its role, goal, and backstory. The backstory is crucial—it sets the persona and context for the LLM.
from crewai import Agent
import os
# 1. The Researcher
researcher = Agent(
role='Senior Technology Researcher',
goal='Uncover the latest developments in AI and machine learning',
backstory="""
You are an expert researcher at a top tech magazine. Your skill lies in
finding obscure, cutting-edge facts.
""",
verbose=True,
allow_delegation=False,
tools=[search_tool]
)
# 2. The Writer
writer = Agent(
role='Senior Technical Writer',
goal='Craft engaging, easy-to-understand articles on complex tech topics',
backstory="""
You are a renowned writer known for breaking down complex concepts for
software engineers. You write in a clear, authoritative, yet approachable tone.
""",
verbose=True,
allow_delegation=True # The writer can ask the researcher for more info!
)
# 3. The Editor
editor = Agent(
role='Managing Editor',
goal='Ensure the final content is flawless, properly formatted in Markdown, and ready to publish',
backstory="""
You are a meticulous editor with an eagle eye for detail, grammar, and flow.
You ensure all articles follow proper Markdown formatting.
""",
verbose=True,
allow_delegation=False
)
Step 3: Define the Tasks
Tasks are specific assignments given to agents. You must explicitly state what the expected_output should look like.
from crewai import Task
topic = "The impact of Small Language Models (SLMs) in 2026"
# Task 1: Research
research_task = Task(
description=f"""
Conduct comprehensive research on the topic: {topic}.
Find at least 3 recent developments or specific models.
""",
expected_output="A detailed bulleted list of facts, models, and trends regarding SLMs.",
agent=researcher
)
# Task 2: Write
write_task = Task(
description="""
Using the research provided, write an engaging blog post.
It must have an introduction, body paragraphs, and a conclusion.
""",
expected_output="A draft blog post of at least 500 words.",
agent=writer
)
# Task 3: Edit
edit_task = Task(
description="""
Review the drafted blog post. Fix any grammatical errors and ensure it is
formatted perfectly in Github-flavored Markdown.
""",
expected_output="A final, publication-ready Markdown document.",
agent=editor
)
Step 4: Assemble the Crew and Execute
Now, we bring the agents and tasks together into a Crew. By default, CrewAI executes tasks sequentially.
from crewai import Crew, Process
content_crew = Crew(
agents=[researcher, writer, editor],
tasks=[research_task, write_task, edit_task],
process=Process.sequential, # Execute tasks one after another
verbose=True
)
# Start the process
print("Starting the CrewAI execution...")
result = content_crew.kickoff()
print("######################")
print("FINAL RESULT:")
print("######################")
print(result)
Why CrewAI Works So Well
When you run the script, watch the terminal output. You will see the Researcher searching DuckDuckGo, reading definitions, and compiling notes. Once finished, it hands its output to the Writer, who drafts the post. Finally, the Editor cleans it up.
Key benefits over single-prompting:
- Reduced Hallucinations: Because the Writer isn't trying to remember facts—it's just re-formatting the Researcher's notes—it hallucinates far less.
- Separation of Concerns: Tuning the writing style doesn't interfere with the research logic.
- Delegation: If the Writer realizes the notes are incomplete, because we set
allow_delegation=True, it can dynamically create a sub-task and ask the Researcher to find more details before proceeding.
Using Local Models with CrewAI
You don't have to use OpenAI. You can easily plug in local Ollama models using LangChain's integration:
import os
os.environ["OPENAI_API_BASE"] = 'http://localhost:11434/v1'
os.environ["OPENAI_MODEL_NAME"] ='llama3.3'
os.environ["OPENAI_API_KEY"] ='sk-11111111111111111111111111111111'
Just add those lines to the top of your script, ensure Ollama is running, and your multi-agent crew is now 100% private and free.