Lesson 1 of 5 · CrewAI
What Is CrewAI?
What CrewAI is: a Python framework for teams of role-playing AI agents. Agents, tasks, crews, processes and Flows, the prompt it builds and your first crew.
- 7 min read
- Intermediate
- Reviewed
- Explain what CrewAI is and the idea of role-based agent teams
- Name its building blocks: agents, tasks, crews, processes and Flows
- Describe how an agent's role, goal and backstory become a prompt
- Install CrewAI and run a first crew
- Compare CrewAI with LangGraph
A team of specialists
Some work is naturally done by a team: a researcher gathers facts, a writer drafts, an editor checks. CrewAI lets you describe AI agents the same way, as team members with jobs, and have them work through a list of tasks together.
The building blocks:
| Concept | What it is |
|---|---|
| Agent | A team member: a role, a goal, a backstory, a model, and optionally tools |
| Task | A piece of work: a description, an expected_output, and the agent who does it |
| Crew | A team: its agents, its tasks and a process |
| Process | How tasks are run: sequential (in order) or hierarchical (a manager agent delegates) |
| Flow | Event-driven orchestration that combines crews and plain code with explicit steps and state |
Your first crew
from crewai import LLM, Agent, Crew, Task
llm = LLM(model="anthropic/MODEL_NAME", temperature=0.7) # provider/model; reads ANTHROPIC_API_KEY
copywriter = Agent(
role="Copywriter",
goal="Write short, memorable slogans that make people want to ride",
backstory="You write marketing copy for Velamuvi Bikes, a small e-bike shop in Lisbon.",
llm=llm,
)
slogan = Task(
description="Write a slogan for {product}.", # {product} is filled in at kickoff
expected_output="One slogan, under 8 words.",
agent=copywriter,
)
crew = Crew(agents=[copywriter], tasks=[slogan])
result = crew.kickoff(inputs={"product": "a folding city e-bike"})
print(result.raw)Fold it. Ride it. Love Lisbon.
LLM(model="anthropic/MODEL_NAME") chooses the provider and model with a provider/model string; replace MODEL_NAME with a current model name from your provider's documentation. The {product} placeholder in the task is filled in from kickoff(inputs=...), so the same crew works for any product. The result is a CrewOutput; .raw holds the final text.
What role, goal and backstory become
Role, goal and backstory aren't magic: CrewAI turns them into the system message, and the task into the user message. Here's a plain-Python model of the prompt CrewAI 1.15 builds, with a two-agent crew where the first task's output becomes context for the second:
# What CrewAI does with an agent and a task: it turns them into the messages the model receives.
# (This mirrors the prompt CrewAI 1.15 builds; the stand-in "model" replaces a real LLM call.)
class Agent:
def __init__(self, role, goal, backstory, model):
self.role, self.goal, self.backstory, self.model = role, goal, backstory, model
class Task:
def __init__(self, description, expected_output, agent):
self.description, self.expected_output, self.agent = description, expected_output, agent
def messages_for(task, inputs, context=""):
a = task.agent
system = f"You are {a.role}. {a.backstory}\nYour personal goal is: {a.goal}"
user = (f"Current Task: {task.description.format(**inputs)}\n\n"
f"This is the expected criteria for your final answer: {task.expected_output}")
if context:
user += f"\n\nThis is the context you're working with:\n{context}"
return [("system", system), ("user", user)]
def kickoff(tasks, inputs): # a sequential crew: each output becomes context
context = ""
for task in tasks:
msgs = messages_for(task, inputs, context)
context = task.agent.model(msgs)
print(f"[{task.agent.role}] {context}")
return context
researcher = Agent("Researcher", "Find accurate facts", "You check product sheets.",
model=lambda m: "Folds in 10 seconds; 16 kg; 50 km range.")
copywriter = Agent("Copywriter", "Write memorable slogans", "You write for Velamuvi Bikes.",
model=lambda m: "Fold it in ten. Ride it for fifty.")
tasks = [Task("List three facts about {product}.", "3 short facts", researcher),
Task("Write a slogan for {product} using the facts.", "One slogan, under 8 words", copywriter)]
for role, text in messages_for(tasks[1], {"product": "a folding e-bike"}, "Folds in 10 seconds; ..."):
print(f"--- {role} ---\n{text}")
print()
kickoff(tasks, {"product": "a folding e-bike"})Seeing the prompt explains how to write good agents and tasks. A specific backstory gives the model useful context. A precise expected_output (“One slogan, under 8 words”) shapes the answer far more than a vague one (“A slogan”).
Installing and setting up
pip install crewai # Python 3.10 to 3.13
pip install "crewai[anthropic]" # the extra for your model provider, if asked for
export ANTHROPIC_API_KEY="..."For larger projects, crewai create crew my_project scaffolds a project where agents and tasks live in YAML files (config/agents.yaml, config/tasks.yaml), separate from the Python code, and crewai run runs it.
CrewAI or LangGraph?
Both build multi-agent systems, at different levels:
- CrewAI starts from people-like roles and tasks. It's quick to describe a team and get a result, with sensible defaults for prompts, delegation and tool use.
- LangGraph starts from state, nodes and edges. It takes more code but gives precise control over every step, loop, pause and handoff (see the LangGraph course).
CrewAI's Flows narrow the gap by adding explicit, event-driven control around crews (lesson 4).
Common mistakes
Turn an agent's role, backstory and goal into the system message the model receives.
agent = {"role": "Editor", "goal": "Catch every mistake before publishing",
"backstory": "You check every article on the shop's blog."}
# Build the system message the way CrewAI does, on two lines:
# You are <role>. <backstory>
# Your personal goal is: <goal>
# Then print it.
In CrewAI, what does an agent's role, goal and backstory become?
Summary
- CrewAI builds teams of AI agents from agents, tasks, crews and processes, plus Flows for event-driven control.
- An agent's role, goal and backstory become its system message; a task's description and expected output become the request.
kickoff(inputs=...)fills placeholders; the result's.rawholds the final text.- Install with
pip install crewai, choose models withLLM("provider/model"), and consider turning off telemetry. - CrewAI is high-level and quick; LangGraph gives low-level control.
Next: agents, tasks and crews in depth.
Finished reading? Tick it off to track your progress.