What Is CrewAI?
CrewAI is a Python framework for building multi-agent AI systems where each agent has a defined role, goal, and backstory. Rather than writing a single monolithic prompt, you decompose complex work into a crew of specialized agents that collaborate sequentially or hierarchically.
The mental model is close to a real team: a researcher, a writer, and an editor each do distinct work, hand off results, and produce a final output that none could produce alone.
Core Concepts
Agent - defined by role (job title), goal (what it optimizes for), and backstory (context that shapes its behavior). The backstory is surprisingly powerful for steering tone and expertise level.
Task - a discrete unit of work assigned to an agent, with a description, expected output, and optional context from previous tasks.
Crew - the collection of agents and tasks, plus a process (sequential or hierarchical) that defines execution order.
from crewai import Agent, Task, Crew, Process
researcher = Agent(
role="Senior Research Analyst",
goal="Uncover cutting-edge developments in AI and data science",
backstory="You work at a leading tech think tank. Your expertise lies in "
"identifying emerging trends and synthesizing complex information.",
verbose=True,
allow_delegation=False,
)
writer = Agent(
role="Tech Content Strategist",
goal="Craft compelling content on tech advancements",
backstory="You are a renowned Content Strategist, known for your insightful "
"and engaging articles. You transform complex concepts into clear prose.",
verbose=True,
allow_delegation=True,
)
research_task = Task(
description="Conduct a comprehensive analysis of the latest advancements in AI. "
"Identify key trends, breakthrough technologies, and potential industry impacts.",
expected_output="Full analysis report with trends, technologies, and impacts",
agent=researcher,
)
write_task = Task(
description="Using the researcher's findings, develop an engaging blog post "
"that highlights the most significant AI advancements.",
expected_output="Full blog post of at least 4 paragraphs",
agent=writer,
)
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential,
verbose=True,
)
result = crew.kickoff()