English
Week 3: Multi-Agent
01. CrewAI

05. Multi-Agent with CrewAI

Overview

In this session, we replace manual multi-agent orchestration with CrewAI—a high-level framework that handles role-playing, task delegation, and workflow management out of the box.

What is CrewAI?

CrewAI is a framework for orchestrating role-playing autonomous AI agents. Think of it as assembling a virtual team where each agent has a specific role, goal, and backstory.

Why CrewAI?

Manual OrchestrationCrewAI
Pass strings between agents manuallyAutomatic message passing
Build your own supervisor logicBuilt-in Sequential/Hierarchical processes
No persona managementRich role, goal, backstory system
DIY tool sharingSeamless tool delegation

Core Concepts

1. Agents

Agents are the workers in your crew. Each has a distinct personality and purpose.

from crewai import Agent
 
researcher = Agent(
    role='Senior Researcher',
    goal='Uncover groundbreaking technologies in AI',
    backstory="""You are a leading tech researcher.
    You're expert at finding latest news and papers.""",
    verbose=True,
    allow_delegation=False  # Can this agent delegate to others?
)
 
writer = Agent(
    role='Tech Content Strategist',
    goal='Craft compelling content on tech advancements',
    backstory="""You are a renowned Content Strategist,
    known for simplifying complex topics.""",
    verbose=True,
    allow_delegation=False
)

Pro Tip: The backstory field is crucial! It shapes how the agent "thinks" and responds. A well-crafted backstory leads to more consistent, in-character outputs.

2. Tasks

Tasks are specific assignments given to agents.

from crewai import Task
 
task1 = Task(
    description="""Analyze the latest trends in 'AI Agents' for 2024.
    Identify key pros and cons.""",
    expected_output="A bullet list summary of top 3 trends.",
    agent=researcher  # Assign to specific agent
)
 
task2 = Task(
    description="""Using the insights provided, write a short LinkedIn post.
    Keep it punchy and professional.""",
    expected_output="A LinkedIn post with hashtags.",
    agent=writer
)

3. Crew

The Crew orchestrates everything—managing workflow and communication.

from crewai import Crew, Process
 
crew = Crew(
    agents=[researcher, writer],
    tasks=[task1, task2],
    verbose=True,
    process=Process.sequential  # or Process.hierarchical
)
 
# One line to run the entire team!
result = crew.kickoff()

Process Types

Sequential Process: Tasks run one after another. Output from Task 1 becomes input for Task 2.

Best for: Linear workflows where each step depends on the previous one.

Adding Tools to Agents

CrewAI agents can use tools just like our ReAct agents:

from crewai_tools import SerperDevTool, WebsiteSearchTool
 
search_tool = SerperDevTool()
web_tool = WebsiteSearchTool()
 
researcher = Agent(
    role='Research Analyst',
    goal='Find accurate information',
    backstory='Expert researcher with access to the web',
    tools=[search_tool, web_tool],  # Attach tools here
    verbose=True
)

Hands-on Practice

In the notebook, you will:

Install CrewAI

pip install crewai crewai-tools

Define Your Agents

Create specialized agents with unique roles and backstories

Create Tasks

Assign specific objectives to each agent

Form the Crew

Combine agents and tasks with a process type

Kickoff!

Run the crew and observe the collaboration

Real-World Applications

Use CaseCrew Setup
Content PipelineResearcher → Writer → Editor → Publisher
Code ReviewDeveloper → Reviewer → Security Analyst
Customer SupportClassifier → Specialist → QA Agent
Market ResearchData Collector → Analyst → Report Writer

CrewAI vs LangGraph

AspectCrewAILangGraph
Abstraction LevelHigh (role-based)Low (graph-based)
Learning CurveGentleSteeper
FlexibilityOpinionatedHighly flexible
Best ForTeam simulationsCustom workflows
State ManagementAutomaticManual control
⚠️

When to use what?

  • Use CrewAI when you want quick multi-agent setups with role-playing
  • Use LangGraph when you need fine-grained control over state and transitions

References & Further Reading

Academic Papers

Next Steps

In the Weekend Project, you'll build a Virtual Startup Team where a CEO, CTO, and CMO collaborate to create a business pitch!