CrewAI
CrewAI builds teams of AI agents with roles, goals and tasks, plus event-driven Flows for production control. Learn crews, processes, flows and when to use them.
Overview
CrewAI is an open-source Python framework for building teams of AI agents. Each agent is described like a team member, with a role, a goal and a short backstory. You give the team a list of tasks, choose how the work is organised, and start the run. The agents work through the tasks, use tools, and pass results to each other until the team produces a final output.
CrewAI has two main layers. Crews are the autonomous part: agents with roles collaborate on tasks, and the model decides many details. Flows are the controlled part: event-driven workflows written in Python that decide exactly what runs when, keep state, and call crews or single model calls as steps. Most production systems use both: a flow for the overall shape and crews inside it for the open-ended work.
An everyday comparison is a small film crew. The director, camera operator and editor each have a clear role and goal. The shooting schedule says which scene is filmed first (the tasks and process). The producer's call sheet, which says "after the location is confirmed, start filming; if it rains, switch to the indoor scene", is the flow. The crew handles the creative work; the call sheet keeps the day on track.
What it is
CrewAI is published under the MIT licence. Its maintainers describe it as built from scratch and independent of other agent frameworks such as LangChain, although it can use LangChain tools.
| Part | What it does |
|---|---|
| Agent | A model with a role, goal, backstory, tools and settings such as delegation |
| Task | A unit of work with a description, an expected output and an assigned agent |
| Crew | A group of agents and tasks that run together |
| Process | How tasks are organised: sequential or hierarchical |
| Tools | Functions agents can call, from CrewAI's tool library, custom code or MCP servers |
| Memory | Short-term, long-term and entity memory so agents remember context |
| Knowledge | Documents and data sources agents can draw on |
| Flow | An event-driven Python workflow with state that coordinates steps and crews |
| Guardrails | Checks on task output that can force a retry |
Agents can produce structured output: a task can require its result to match a Pydantic model, so later steps receive typed data. See structured outputs.
Where it came from
João Moura published CrewAI on 14 November 2023. It quickly became one of the most popular open-source multi-agent frameworks, because its "team of specialists" metaphor was easy to grasp. Early versions built on parts of LangChain. The project was later rewritten so that it no longer depends on LangChain or other agent frameworks.
In 2024 a company, CrewAI Inc., was formed around the project, and Flows were added to give developers precise, event-driven control alongside autonomous crews. Other additions included memory, knowledge sources, agent training, task guardrails and MCP tool support. The company also offers a commercial platform for deploying, monitoring and managing crews.
How it works
Step 1: Define agents
Each agent gets a role ("Senior market analyst"), a goal ("Find reliable figures on the market size") and a backstory ("You have ten years in industry research and distrust unsourced claims"). These fields become part of the agent's prompt and shape its behaviour. You also choose its model and tools, and whether it may delegate work to other agents.
Step 2: Define tasks
Each task has a description of what to do, an expected output that says what "done" looks like, and an agent to do it. A task can take context from earlier tasks, write to a file, require a Pydantic output model, or run asynchronously.
Step 3: Choose a process
- Sequential: tasks run in the listed order, and each task's output is available to later tasks.
- Hierarchical: a manager agent, either generated or supplied by you, plans the work, assigns tasks to agents, reviews results and decides when the job is done.
Step 4: Kick off the crew
from crewai import Agent, Task, Crew, Process
analyst = Agent(
role="Market analyst",
goal="Summarise the main competitors in a market",
backstory="You are careful and always name your sources.",
)
summary = Task(
description="List the five main competitors in {market}.",
expected_output="A table with name, product and one-line note.",
agent=analyst,
)
crew = Crew(agents=[analyst], tasks=[summary], process=Process.sequential)
result = crew.kickoff(inputs={"market": "e-bikes in Spain"})
Inside each task, the agent runs a reason-and-act loop: it thinks, calls tools, reads results and repeats until it can give the expected output. See the ReAct loop.
Step 5: Wrap crews in flows
A flow is a Python class whose methods are steps. A method marked @start() runs first. A method marked @listen(...) runs when another step finishes, receiving its output. A method marked @router(...) returns a label that decides which branch runs next. Flows hold typed state, so values persist across steps. A step can be plain code, a single model call or a whole crew. This gives you predictable control over cost, order and error handling.
Step 6: Remember and improve
Memory lets agents recall earlier parts of a run and lessons from past runs. Knowledge sources give them documents to consult. Task guardrails check outputs and send them back for another try if they fail.
Key concepts and terms
| Term | Meaning |
|---|---|
| Agent | A model with a role, goal, backstory and tools |
| Role | The job title that frames the agent's behaviour |
| Goal | What the agent is trying to achieve |
| Backstory | Context that sets the agent's expertise and style |
| Task | A piece of work with an expected output |
| Expected output | A description of what a finished task should contain |
| Crew | A team of agents and tasks |
| Sequential process | Tasks run in order |
| Hierarchical process | A manager agent delegates and reviews |
| Flow | Event-driven workflow with state and explicit steps |
@listen and @router |
Flow decorators for triggering and branching steps |
| Delegation | An agent asking another agent to do part of the work |
A worked example
This scenario is illustrative. A small consultancy builds a weekly competitor report.
- A flow starts every Monday with a
@start()step that loads a list of 12 competitors. - A crew of three agents runs for each competitor: a "researcher" with a web search tool, an "analyst" that compares findings with last week's notes from memory, and a "writer" that produces a 150-word update. The process is sequential.
- A task guardrail rejects any update that does not cite at least one source, and the writer retries.
- A
@router()step checks whether any update mentions a price change. If so, it sends the report to a partner for review, following a human-in-the-loop pattern. Otherwise it emails the report automatically. - In the first month the team logs cost per run. Each competitor takes about 20 model calls, so 12 competitors take about 240. They move the researcher to a cheaper model and keep the writer on a stronger one.
Strengths and limitations
Strengths:
- The role, goal and task model is intuitive and quick to prototype.
- Flows add precise control, state and branching for production use.
- Good fit for content, research and analysis pipelines with clear roles.
- Built-in memory, knowledge, guardrails and structured outputs.
- Large community and many examples.
Limitations:
- Role prompts can produce long, chatty exchanges that cost more than a direct design.
- The hierarchical process adds a manager's model calls and can be less predictable.
- Python only.
- Fine-grained control over each model call is less direct than in lower-level frameworks.
- Quality still depends on good task descriptions, tools and evaluation.
How it compares with alternatives
| Option | Strength | Trade-off |
|---|---|---|
| CrewAI | Intuitive role-based crews plus flows | Can be verbose and costly |
| LangGraph | Explicit graphs, checkpoints, fine control | Steeper learning curve |
| Microsoft Agent Framework | Typed workflows in Python and .NET | Best inside Microsoft's stack |
| OpenAI Agents SDK | Minimal primitives with handoffs | Fewer workflow features |
| Pydantic AI | Type-safe single agents and graphs | Less role-based structure |
Practical guidance and best practices
- Start with one agent and one task; add agents only when roles really differ.
- Write concrete expected outputs, including format and length.
- Prefer the sequential process until you have a clear reason for a manager.
- Use flows for anything with branching, schedules, retries or approvals.
- Require Pydantic output models for tasks whose results feed code.
- Give each agent only the tools its role needs.
- Choose models per agent by difficulty to control cost.
- Track cost and latency per run and keep a test set of past jobs as evals.
Common mistakes
- Creating many agents with overlapping roles that repeat each other's work.
- Writing vague expected outputs such as "a good report".
- Using a hierarchical crew for a simple, fixed sequence.
- Letting crews run without a limit on iterations or cost; see cost and latency budgets.
- Skipping flows and trying to make a crew do deterministic routing.
Frequently asked questions
What is CrewAI?
CrewAI is an open-source Python framework for building teams of AI agents with roles, goals and tasks, plus Flows for event-driven, controlled workflows.
Who created CrewAI?
João Moura published it in November 2023. A company, CrewAI Inc., now maintains it and offers a commercial platform.
Does CrewAI depend on LangChain?
No. Its maintainers rewrote it to be independent of LangChain and other agent frameworks, although it can still use LangChain tools.
What is the difference between a crew and a flow?
A crew is an autonomous team of agents working on tasks. A flow is an explicit, event-driven workflow with state that decides what runs and when, and can call crews as steps.
When should I use the hierarchical process?
When tasks are not known in advance and you want a manager agent to plan and assign them. For known sequences, the sequential process is cheaper and more predictable.
Can CrewAI use MCP tools?
Yes. Agents can use tools from MCP servers as well as CrewAI's own tools and custom functions. See MCP.
Glossary
- Crew: a team of agents working on tasks.
- Agent: a model with a role, goal and tools.
- Task: a unit of work with an expected output.
- Process: the rule for ordering tasks.
- Manager agent: the coordinator in a hierarchical process.
- Flow: an event-driven workflow with state.
- Router: a flow step that picks the next branch.
- Task guardrail: a check that can force a retry.
- Knowledge source: documents an agent can consult.
Summary
CrewAI lets you build teams of role-based agents that work through tasks, and wrap them in Flows for explicit, stateful control. It was released by João Moura in November 2023 and is now independent of other frameworks. Its strength is a clear, human-like model of teamwork; its risk is verbose, costly runs. Keep roles distinct, expected outputs concrete, processes simple and flows in charge of anything that must be predictable.
Related
It belongs to Frameworks in my stack, under Agentic AI. Others in the same group: