CrewAI - Multi-Agent AI Framework
Table of Contents
Introduction
CrewAI is a cutting-edge framework for orchestrating autonomous AI agents that work together as a collaborative team. Inspired by real-world crew dynamics, it enables developers to create sophisticated multi-agent systems where each agent has a specific role, expertise, and set of tools.
Key features of CrewAI:
- Role-based agents: Define agents with specific roles, goals, and backstories
- Task management: Create structured tasks with expected outputs and dependencies
- Flexible orchestration: Sequential, parallel, and hierarchical execution modes
- Tool ecosystem: Rich set of built-in tools plus custom tool creation
- Memory systems: Short-term, long-term, and entity memory for context persistence
- Delegation: Agents can delegate tasks to other agents when appropriate
Multi-agent systems outperform single-agent approaches for complex tasks because they allow specialization, parallel processing, and collaborative problem-solving — much like a human team.
In this tutorial, you will learn how to create agents, define tasks, orchestrate crews, integrate tools, and build real-world multi-agent applications.
Prerequisites
- Python 3.10 or higher
- An OpenAI API key (or other supported LLM provider)
- Basic understanding of Large Language Models (LLMs)
- Familiarity with Python async patterns (for parallel execution)
Installation and Setup
# Install CrewAI with all tools
pip install crewai[tools]
Or minimal installation
pip install crewai
Set up environment variables
export OPENAIAPIKEY="your-openai-api-key"
Optional: for other LLM providers
export ANTHROPICAPIKEY="your-anthropic-key"
Verify the installation:
import crewai
print(f"CrewAI version: {crewai.version}")
from crewai import Agent, Task, Crew
print("All core components imported successfully")
Core Concepts
CrewAI is built around three core abstractions:
from crewai import Agent, Task, Crew, Process
The simplest possible crew
agent = Agent(
role="Greeting Agent",
goal="Greet the user warmly",
backstory="You are a friendly agent that welcomes users.",
verbose=True,
)
task = Task(
description="Greet the user and wish them a productive day.",
expectedoutput="A warm, personalized greeting message.",
agent=agent,
)
crew = Crew(
agents=[agent],
tasks=[task],
process=Process.sequential,
verbose=True,
)
result = crew.kickoff()
print(result)
Creating Agents
Agents are the core workers in CrewAI. Each agent should have a clearly defined role and area of expertise.
from crewai import Agent
from crewaitools import SerperDevTool, WebsiteSearchTool
Research analyst agent
researchanalyst = Agent(
role="Senior Research Analyst",