CrewAI Tutorial: Build a
Multi-Agent Workflow in 30 Minutes
TL;DR
- CrewAI is a Python framework for role-based multi-agent collaboration built on top of LangChain.
- Three building blocks: Agents (roles), Tasks (what to do), Tools (what agents can use).
- This tutorial builds a 3-agent research-to-report pipeline in under 30 minutes.
- Production tips for async execution, error handling, and cost control are included at the end.
Agentic AI moved from hype to production faster than almost any prior AI paradigm. The reason: frameworks like CrewAI made it practical to ship multi-agent systems without rebuilding the coordination layer from scratch for every project. This tutorial gets you from zero to a working 3-agent pipeline — researcher, analyst, writer — in about 30 minutes.
Prerequisites
- Python 3.11 or later
- An OpenAI API key (or any LiteLLM-supported model key)
- Basic Python familiarity — no prior LangChain or LLM experience needed
Install CrewAI and the tools package:
pip install crewai crewai-toolsSet your API key as an environment variable:
export OPENAI_API_KEY="sk-..."What We're Building
A market research pipeline with three specialist agents:
- Researcher — searches the web for recent information on a topic
- Analyst — synthesises findings into structured insights
- Writer — turns insights into a polished executive summary
Each agent has a defined role, goal, and backstory. Each has a task. They run sequentially, with each agent's output feeding the next.
Step 1 — Define Your Agents
Agents are the workers in your crew. Each agent gets a role (what it is), a goal (what it's trying to achieve), and a backstory (context that shapes its reasoning style).
from crewai import Agent
researcher = Agent(
role="Senior Market Researcher",
goal="Find the most relevant and recent information about {topic}",
backstory=(
"You are an expert researcher with 10 years of experience in "
"technology markets. You excel at finding credible, up-to-date "
"sources and extracting the key facts that matter to business decisions."
),
verbose=True,
allow_delegation=False,
)
analyst = Agent(
role="Strategic Business Analyst",
goal="Synthesise research findings into structured, actionable insights about {topic}",
backstory=(
"You are a senior analyst who turns raw research into clear business "
"intelligence. You identify patterns, risks, and opportunities that "
"others miss. Your analysis is always evidence-backed."
),
verbose=True,
allow_delegation=False,
)
writer = Agent(
role="Executive Communications Specialist",
goal="Write a concise, compelling executive summary based on the analysis",
backstory=(
"You write for C-suite audiences. Your summaries are clear, brief, "
"and decision-oriented. You never use jargon without explanation. "
"Your work is read and acted on, not filed."
),
verbose=True,
allow_delegation=False,
)The allow_delegation=False setting prevents agents from reassigning tasks to each other — useful when you want deterministic task assignment. Set it to True for more autonomous orchestration.
Step 2 — Define Tasks
Tasks specify exactly what each agent should produce. The expected_output field is critical — it's what the LLM optimises toward.
from crewai import Task
research_task = Task(
description=(
"Research {topic}. Find: recent market developments (last 6 months), "
"key players and their market positions, major use cases, and "
"emerging trends. Use web search to find current data."
),
expected_output=(
"A structured research report with: 1) Market overview (2-3 paragraphs), "
"2) Key players list with brief descriptions, 3) Top 5 use cases, "
"4) 3 emerging trends with evidence."
),
agent=researcher,
)
analysis_task = Task(
description=(
"Analyse the research report on {topic}. Identify: the most significant "
"business opportunity, the top 2 risks, and a recommendation for "
"a mid-market technology company considering this space."
),
expected_output=(
"A structured analysis with: 1) Primary opportunity (1 paragraph), "
"2) Risk matrix (2 rows), 3) Recommendation with rationale (1 paragraph)."
),
agent=analyst,
context=[research_task], # analyst sees researcher output
)
write_task = Task(
description=(
"Write an executive summary about {topic} suitable for a CEO briefing. "
"Use the research and analysis provided. Max 300 words. "
"No jargon without explanation. End with a clear recommended next step."
),
expected_output=(
"A 200-300 word executive summary with: headline, 3-sentence situation "
"summary, opportunity/risk balance, and one recommended next step."
),
agent=writer,
context=[research_task, analysis_task],
)Notice context=[research_task] on the analysis task — this passes the researcher's output as context to the analyst. This is how information flows between agents.
Step 3 — Assemble the Crew and Run
from crewai import Crew, Process
crew = Crew(
agents=[researcher, analyst, writer],
tasks=[research_task, analysis_task, write_task],
process=Process.sequential, # tasks run in order
verbose=True,
)
result = crew.kickoff(inputs={"topic": "agentic AI for enterprise software"})
print(result.raw)Run it:
python crew.pyYou'll see each agent working through its task, with the final output being the writer's executive summary.
Shipping a multi-agent system to production?
We've built and deployed agentic AI workflows for enterprises across fintech, healthcare, and SaaS — with real error handling, observability, and security.
Agentic AI ServicesTalk to an EngineerStep 4 — Add Web Search with SerperDevTool
Without tools, agents can only use their training data. Add SerperDevTool to give your researcher live web search capability:
# pip install crewai-tools
# export SERPER_API_KEY="your-serper-key" # serper.dev free tier: 2,500 searches/month
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
researcher = Agent(
role="Senior Market Researcher",
goal="Find the most relevant and recent information about {topic}",
backstory="...",
tools=[search_tool], # give search capability to researcher only
verbose=True,
allow_delegation=False,
)Only assign tools to agents that need them. Giving all agents all tools increases token usage and can cause confusion about which tool to use when.
Step 5 — Production Tips
Use async execution for parallel tasks
Sequential execution is simple but slow. For tasks that don't depend on each other, use Process.hierarchical or run tasks with async_execution=True:
# Tasks that can run in parallel
task_a = Task(..., async_execution=True)
task_b = Task(..., async_execution=True)
# task_c depends on both — runs after they complete
task_c = Task(..., context=[task_a, task_b])Set max_iter to control runaway agents
researcher = Agent(
...
max_iter=5, # max tool-use + reasoning loops per task
max_rpm=10, # max LLM requests per minute (rate limiting)
)Use cheaper models for simpler agents
from langchain_openai import ChatOpenAI
# Use GPT-4o for complex reasoning
analyst = Agent(
...
llm=ChatOpenAI(model="gpt-4o", temperature=0.1),
)
# Use GPT-4o-mini for formatting/writing
writer = Agent(
...
llm=ChatOpenAI(model="gpt-4o-mini", temperature=0.3),
)Add memory for long-running workflows
crew = Crew(
agents=[researcher, analyst, writer],
tasks=[research_task, analysis_task, write_task],
process=Process.sequential,
memory=True, # enables short-term, long-term, and entity memory
embedder={
"provider": "openai",
"config": {"model": "text-embedding-3-small"},
},
)CrewAI vs LangGraph: When to Use Which
CrewAI's role-based model excels when your workflow maps naturally to human team structures — researcher, analyst, writer, reviewer. It's optimised for readability and speed of development. For pipelines with complex conditional routing, retries on failure, human-in-the-loop checkpoints, or fine-grained state management at each step, LangGraph gives you more control. Many production systems we build at Inventiple use LangGraph as the outer orchestrator with CrewAI crews as inner workers for role-based subtasks.
Frequently Asked Questions
What is CrewAI?
CrewAI is an open-source Python framework for building multi-agent AI systems. It lets you define a "crew" of LLM-powered agents, each with a specific role, goal, and backstory, and assign them tasks that they execute collaboratively. CrewAI handles agent orchestration, task delegation, and result aggregation — so you can focus on defining what agents should do, not how to coordinate them.
How does CrewAI differ from LangChain agents?
LangChain agents are single-agent constructs that use a ReAct or tool-use loop to accomplish a task. CrewAI is a multi-agent framework built on top of LangChain that adds role-based collaboration, memory sharing between agents, and structured task delegation. LangChain gives you the building blocks; CrewAI gives you the team coordination layer. For simple tasks, a LangChain agent is sufficient. When you need specialists with different context and tools working together, CrewAI adds genuine value.
Is CrewAI production-ready in 2026?
CrewAI is production-ready for well-defined workflows with bounded scope. It works reliably for content research and generation pipelines, data analysis workflows, customer support triage, and document processing. It is less suited for open-ended tasks, workflows requiring sub-second response times (LLM round-trips add latency), or systems where explainability of every reasoning step is a compliance requirement. At Inventiple, we run CrewAI workflows in production with async task execution and result caching for deterministic subtasks.
What LLMs does CrewAI support?
CrewAI supports any LLM accessible via LiteLLM, which covers virtually the entire landscape: OpenAI GPT-4o, Anthropic Claude, Google Gemini, AWS Bedrock models, Azure OpenAI, Mistral, Groq, Ollama (local models), and more. Each agent in a crew can use a different LLM — a common pattern is using a powerful model (GPT-4o or Claude Opus) for complex reasoning agents and a faster, cheaper model (GPT-4o-mini or Haiku) for simpler extraction or formatting agents.
How much does a CrewAI workflow cost to run?
Cost depends on the number of agents, task complexity, and LLM choice. A typical 3-agent research workflow (researcher + analyst + writer) with GPT-4o costs approximately $0.05–$0.15 per run using 5,000–15,000 tokens. With GPT-4o-mini, the same workflow costs $0.003–$0.01. For high-volume workflows, use cheaper models for structured extraction tasks and reserve premium models for the final synthesis step. At 1,000 runs/day, GPT-4o-mini saves roughly $50–100/day vs GPT-4o for equivalent output quality on routine tasks.