Skip to content
👥

CrewAI

CrewAI Inc.

A framework for orchestrating role-playing AI agents, enabling multiple agents to collaborate on complex tasks.

By EZ4Code Team
Visit Official Site

Overview

CrewAI is an open-source framework developed by Joao Moura, focused on multi-agent collaboration. Unlike single-agent systems, CrewAI lets multiple AI agents play different roles, such as researcher, writer, reviewer, etc., to collaboratively complete complex tasks. Each agent has a unique role, goal, backstory, and toolset. CrewAI supports both sequential and parallel execution modes, and agents can delegate tasks and share information with each other.

Installation

CrewAI is installed via pip and requires Python 3.10+. After installation, you need to configure an LLM API key. CrewAI supports multiple LLM backends, including OpenAI, Anthropic, and local models.

# Install CrewAI
pip install crewai
pip install 'crewai[tools]'

# Configure API
export OPENAI_API_KEY=your-key-here

# Or use uv (recommended)
uv add crewai
uv add 'crewai[tools]'

Creating Crews

Crew is the core concept of CrewAI, consisting of agents, tasks, and processes. Creating a Crew requires defining the agent list, task list, and execution process. The Crew manages collaboration and task assignment among agents.

from crewai import Crew, Process

crew = Crew(
    agents=[researcher, writer, editor],
    tasks=[research_task, writing_task, editing_task],
    process=Process.sequential,
    verbose=True
)

result = crew.kickoff()

Agents

Agent is the basic unit in CrewAI. Each agent has a role, goal, backstory, and tools. The role defines the agent's area of expertise, the goal guides the agent's behavior, and the backstory shapes the agent's personality and style. Agents can use tools to perform operations.

from crewai import Agent

researcher = Agent(
    role='Senior Research Analyst',
    goal='In-depth analysis of the latest AI technology trends',
    backstory='You are an experienced technology analyst skilled at researching and summarizing complex technical topics.',
    tools=[search_tool, web_scraper],
    verbose=True
)

Tasks

Task is a specific unit of work assigned to an agent. Each task has a description, expected output, and responsible agent. Tasks can set dependency relationships and support sequential and parallel execution. Task outputs can be passed to subsequent tasks.

from crewai import Task

research_task = Task(
    description='Research the most important AI agent frameworks of 2024',
    expected_output='A detailed report, including framework comparisons and usage recommendations',
    agent=researcher,
    output_file='research_report.md'
)

Tools

CrewAI provides a rich set of tools, including search, web scraping, file operations, database queries, and more. Tools extend agents' capabilities, enabling them to interact with the outside world. Custom tool development is supported.

from crewai_tools import SerperDevTool, WebsiteSearchTool

search_tool = SerperDevTool()
web_tool = WebsiteSearchTool()

# Custom tool
from crewai.tools import BaseTool

class MyTool(BaseTool):
    name: str = "My Tool"
    description: str = "Custom tool description"
    
    def _run(self, argument: str) -> str:
        return f"Result: {argument}"

Processes

CrewAI supports two execution processes: Sequential and Hierarchical. The sequential process executes tasks in the order of the task list, while the hierarchical process dynamically assigns tasks by a manager agent. The choice of process affects how agents collaborate and the execution efficiency.

# Sequential process
crew = Crew(agents=agents, tasks=tasks, process=Process.sequential)

# Hierarchical process (requires a manager agent)
crew = Crew(
    agents=agents, 
    tasks=tasks, 
    process=Process.hierarchical,
    manager_llm=ChatOpenAI(model="gpt-4")
)

Memory

CrewAI supports short-term memory, long-term memory, and entity memory. Short-term memory maintains session context, long-term memory stores information across sessions, and entity memory tracks specific entities (people, organizations, etc.). The memory system uses a vector database for semantic search.

crew = Crew(
    agents=agents,
    tasks=tasks,
    memory=True,
    embedder={
        "provider": "openai",
        "config": {"model": "text-embedding-3-small"}
    }
)

Collaboration

The core of CrewAI is multi-agent collaboration. Agents can delegate tasks, share information, and review each other. By designing reasonable roles and processes, you can build highly collaborative agent teams. Collaboration modes include division of labor, review and improvement, iterative optimization, and more.

Deployment

CrewAI supports multiple deployment methods, including local running, Docker containers, and cloud platform deployment. CrewAI+ provides managed services, supporting API calls and monitoring. It can be integrated into existing applications as an AI backend service.

# Deploy as a FastAPI service
from fastapi import FastAPI
from crewai import Crew

app = FastAPI()
crew = Crew(agents=agents, tasks=tasks)

@app.post("/run")
async def run_crew(input: str):
    result = crew.kickoff(inputs={"topic": input})
    return {"result": result}

Deploy the crew behind a FastAPI endpoint to call it from existing apps.

Configuration

CrewAI is configured in Python code and via environment variables. Set LLM API keys (OPENAI_API_KEY, ANTHROPIC_API_KEY) as env vars. Each Crew takes agents, tasks, a process (sequential/hierarchical), and optional memory with an embedder config. Tools are attached per agent. A .env file is the standard place for secrets.

# .env
OPENAI_API_KEY=your-key
ANTHROPIC_API_KEY=your-key

# Python config
from crewai import Crew, Process, Agent, Task

researcher = Agent(
    role='Researcher',
    goal='Analyze AI trends',
    backstory='Experienced analyst.',
    tools=[search_tool],
    llm='gpt-4o'  # or a ChatOpenAI instance
)

crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    process=Process.sequential,
    memory=True,
    embedder={"provider": "openai",
              "config": {"model": "text-embedding-3-small"}}
)

Use hierarchical process with a manager_llm when tasks need dynamic delegation; sequential is simpler for linear flows.

FAQ

Common questions cover model choice, cost, custom tools, process selection, and memory. CrewAI supports any LLM via LiteLLM (OpenAI, Anthropic, Ollama, etc.). Sequential process runs tasks in order; hierarchical uses a manager agent to delegate.

Q: Which LLMs are supported?
A: Any provider supported by LiteLLM: OpenAI, Anthropic, Google, Ollama,
   and more. Set the key as an env var and pass the model name to Agent(llm=).

Q: How do I cut costs?
A: Use a smaller model for simple agents, disable memory when not needed,
   and limit verbose logging.

Q: Sequential or hierarchical process?
A: Sequential runs tasks in list order (simpler). Hierarchical uses a
   manager agent to delegate (better for dynamic, complex workflows).

Q: How do I add custom tools?
A: Subclass BaseTool and implement _run(); attach the tool to an Agent.

Q: Does memory persist across runs?
A: Long-term memory can persist across sessions using a vector store;
   short-term memory is per-crew-run.

Design roles with clear, non-overlapping goals—conflicting agent goals cause delegation thrash.

More AI Guides