What Is CrewAI?
CrewAI is an open-source Python framework for orchestrating multi-agent AI systems. Inspired by how human teams work, it lets you create a "crew" of specialized agents — each with a distinct role, backstory, and set of tools — that collaborate to complete complex tasks no single agent could handle well alone.
Why Multi-Agent?
A single agent doing everything can:
- Lose context with too many responsibilities
- Mix up roles (researcher vs writer vs critic)
- Struggle to parallelize independent work
A crew of specialists:
- Each agent focuses on what it's best at
- Tasks can run in parallel or depend on each other
- Agents can review and critique each other's work
Core Abstractions
| Concept | Description |
|---|---|
| Agent | An LLM with a role, goal, backstory, and tools |
| Task | A specific unit of work assigned to an agent |
| Crew | A team of agents working on a list of tasks |
| Tool | A function an agent can call (search, code, API) |
| Process | How tasks are executed: sequential or hierarchical |
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
from langchain_anthropic import ChatAnthropic
# Initialize the LLM (CrewAI works with any LangChain-compatible LLM)
llm = ChatAnthropic(model="claude-sonnet-4-6", temperature=0)
# Search and scrape tools
search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()
# -------------------------------------------------------
# AGENT 1: The Researcher
# -------------------------------------------------------
researcher = Agent(
role="Senior Research Analyst",
goal=(
"Find comprehensive, accurate, and up-to-date information on the given topic. "
"Focus on primary sources, statistics, and expert opinions."
),
backstory=(
"You are a veteran research analyst with 15 years of experience in tech journalism. "
"You are known for your thorough fact-checking and ability to synthesize complex topics. "
"You always cite sources and flag uncertain information."
),
tools=[search_tool, scrape_tool],
llm=llm,
verbose=True,
allow_delegation=False, # this agent does its own work
)
# -------------------------------------------------------
# AGENT 2: The Writer
# -------------------------------------------------------
writer = Agent(
role="Technical Content Writer",
goal=(
"Transform research findings into clear, engaging, well-structured articles "
"that are accessible to a technical audience."
),
backstory=(
"You are a technical writer who has authored documentation for major open-source projects. "
"You excel at structuring complex information hierarchically and making it scannable. "
"You always write in an active voice with concrete examples."
),
tools=[], # the writer works from research, no external tools needed
llm=llm,
verbose=True,
allow_delegation=False,
)
# -------------------------------------------------------
# AGENT 3: The Editor
# -------------------------------------------------------
editor = Agent(
role="Senior Editor",
goal=(
"Review and refine the draft article for accuracy, clarity, structure, "
"and consistency. Catch factual errors and improve readability."
),
backstory=(
"You have edited publications for The Verge and Wired. "
"Your editorial instincts are sharp: you immediately spot vague claims, "
"logical gaps, and jargon that needs explaining."
),
tools=[search_tool], # can verify facts if needed
llm=llm,
verbose=True,
allow_delegation=True, # can reassign to researcher if facts need checking
)# -------------------------------------------------------
# TASK 1: Research
# -------------------------------------------------------
research_task = Task(
description=(
"Research the current state of agentic AI frameworks in 2024. "
"Cover: (1) the top 5 frameworks and their key features, "
"(2) adoption trends, (3) production use cases, "
"(4) technical limitations and how teams are working around them. "
"Produce a structured research document with citations."
),
expected_output=(
"A detailed research report (800-1000 words) with sections for each framework, "
"adoption data with sources, and a summary of key trade-offs."
),
agent=researcher,
)
# -------------------------------------------------------
# TASK 2: Write (depends on research_task)
# -------------------------------------------------------
write_task = Task(
description=(
"Using the research report, write a comprehensive article titled "
"'The State of Agentic AI Frameworks in 2024'. "
"The article should: introduce the topic for a developer audience, "
"compare the frameworks with a feature matrix, discuss real use cases, "
"and end with recommendations for choosing a framework."
),
expected_output=(
"A polished article of 1200-1500 words with a clear structure: "
"intro, framework comparison, use cases, recommendations, and conclusion."
),
agent=writer,
context=[research_task], # writer receives researcher's output
)
# -------------------------------------------------------
# TASK 3: Edit (depends on write_task)
# -------------------------------------------------------
edit_task = Task(
description=(
"Review the article draft. Check for: factual accuracy, "
"clarity of explanations, logical flow, and appropriate tone. "
"Make improvements directly in the text and add an editor's note "
"summarizing what was changed and why."
),
expected_output=(
"The final, polished article with all improvements applied, "
"followed by a brief editor's note explaining key changes."
),
agent=editor,
context=[write_task],
)
# -------------------------------------------------------
# CREW: Assemble and run
# -------------------------------------------------------
crew = Crew(
agents=[researcher, writer, editor],
tasks=[research_task, write_task, edit_task],
process=Process.sequential, # tasks run in order
verbose=True,
)
# Kick off the crew
result = crew.kickoff()
print(result)Hierarchical Process
For complex tasks where you want a "manager" agent to orchestrate workers dynamically, use Process.hierarchical:
# A manager agent decides which worker to delegate to
crew = Crew(
agents=[researcher, writer, data_analyst, fact_checker],
tasks=[complex_task],
process=Process.hierarchical,
manager_llm=llm, # the orchestrating LLM
verbose=True,
)
The manager agent breaks down the task, assigns sub-tasks to appropriate workers, collects results, and synthesizes the final output — without you hard-coding the delegation logic.
Custom Tools in CrewAI
You can give agents any function as a tool using the @tool decorator:
from crewai_tools import BaseTool
from pydantic import BaseModel, Field
import requests
class StockPriceInput(BaseModel):
ticker: str = Field(description="Stock ticker symbol e.g. AAPL")
class StockPriceTool(BaseTool):
name: str = "get_stock_price"
description: str = (
"Get the current stock price and daily change for a given ticker symbol. "
"Use when you need real-time market data."
)
args_schema: type[BaseModel] = StockPriceInput
def _run(self, ticker: str) -> str:
# Replace with a real API like Yahoo Finance or Alpha Vantage
response = requests.get(
f"https://query1.finance.yahoo.com/v8/finance/chart/{ticker}",
headers={"User-Agent": "Mozilla/5.0"}
)
data = response.json()
price = data["chart"]["result"][0]["meta"]["regularMarketPrice"]
prev_close = data["chart"]["result"][0]["meta"]["chartPreviousClose"]
change_pct = ((price - prev_close) / prev_close) * 100
return f"{ticker}: ${price:.2f} ({change_pct:+.2f}%)"
# Attach to an agent
market_analyst = Agent(
role="Market Analyst",
goal="Analyze stock market data and provide investment insights",
backstory="You are a CFA with 20 years of equity research experience.",
tools=[StockPriceTool()],
llm=llm,
)Real-World CrewAI Use Cases
1. Content Marketing Pipeline
- Researcher finds trending topics and gathers data
- SEO Analyst identifies keywords and optimization opportunities
- Writer produces the draft
- Editor refines for brand voice
- Publisher formats and schedules
2. Software Development Crew
- Product Manager agent breaks down requirements
- Architect designs the solution
- Developer writes the code
- QA Engineer writes and runs tests
- DevOps agent deploys to staging
3. Investment Research Crew
- Data Analyst pulls financial metrics
- News Analyst scans recent developments
- Fundamental Analyst assesses business quality
- Risk Manager identifies risks
- Portfolio Manager makes the final recommendation
Key Configuration Options
| Option | Values | Effect |
|---|---|---|
verbose | True/False | Show agent reasoning |
allow_delegation | True/False | Agent can assign to peers |
max_iter | int | Max reasoning iterations |
memory | True/False | Enable cross-task memory |
cache | True/False | Cache tool results |
Knowledge check
In CrewAI, what is the difference between Process.sequential and Process.hierarchical?
Summary
CrewAI makes multi-agent orchestration intuitive by mapping naturally to how human teams work:
- Agents = team members with specialized roles and expertise
- Tasks = work items with clear deliverables and expected outputs
- Crew = the team configured with a workflow process
- Tools = capabilities agents use to interact with the world
In the next chapter, we'll explore LangGraph — a different approach that models agents as state machines, giving you fine-grained control over complex, conditional workflows.