🚢 CrewAI Overview
CrewAI is a framework for orchestrating role-playing AI agents that work together as a cohesive unit. It enables you to build sophisticated multi-agent systems where each agent has a specific role, goal, and backstory that guides their behavior.
Role-Playing
Agents with personalities and expertise
Collaborative
Agents work together towards goals
Autonomous
Self-directed task execution
Core Concepts
Role-Based Agents
Agents with specific roles, goals, and backstories
Each agent has a defined role (title), goal (objective), and backstory (context) that shapes their behavior and expertise.
Task Dependencies
Tasks can depend on outputs from other tasks
CrewAI manages task dependencies automatically, passing outputs from prerequisite tasks as context to dependent tasks.
Process Types
Sequential, hierarchical, or custom execution flows
Sequential executes tasks in order, hierarchical uses a manager agent to coordinate, and custom allows defining your own process.
Tool Integration
Agents can use tools for web search, APIs, and more
CrewAI provides pre-built tools and supports custom tool creation for extending agent capabilities.
Delegation
Agents can delegate tasks to other agents
When enabled, agents can identify when another agent is better suited for a subtask and delegate accordingly.
Memory Systems
Short-term and long-term memory for context retention
Memory allows crews to maintain context across executions, enabling more coherent long-running projects.
Implementation Patterns
Basic Crew Setup
Create a simple crew with researcher and writer agents
from crewai import Agent, Task, Crew, Process
from langchain.llms import OpenAI
# Initialize LLM
llm = OpenAI(temperature=0.7)
# Define agents with roles and goals
researcher = Agent(
role='Senior Research Analyst',
goal='Uncover cutting-edge developments in AI',
backstory="""You work at a leading tech think tank.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data.""",
verbose=True,
allow_delegation=False,
llm=llm
)
writer = Agent(
role='Tech Content Strategist',
goal='Craft compelling content on tech advancements',
backstory="""You are a renowned Content Strategist.
You transform complex concepts into engaging narratives.""",
verbose=True,
allow_delegation=True,
llm=llm
)
# Create tasks for the agents
research_task = Task(
description="""Conduct research on the latest AI trends.
Identify key breakthroughs and their implications.""",
expected_output="Detailed research report with citations",
agent=researcher
)
write_task = Task(
description="""Using the research, create an engaging blog post.
Make it accessible to a tech-savvy audience.""",
expected_output="A 500-word blog post",
agent=writer,
context=[research_task] # Depends on research task
)
# Create and run the crew
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential,
verbose=True
)
result = crew.kickoff()
print(result)
Execution Processes
Sequential Process
Tasks are executed one after another in a defined order
- • Simple and predictable execution flow
- • Each task can access outputs from previous tasks
- • Best for linear workflows with clear dependencies
Hierarchical Process
A manager agent coordinates and delegates tasks
- • Manager decides task assignment and order
- • Allows for dynamic task allocation
- • Suitable for complex projects with multiple paths
Parallel Process
Multiple tasks execute simultaneously for efficiency
- • Tasks run concurrently when possible
- • Reduces overall execution time
- • Ideal for independent research or analysis tasks
Best Practices
✅ Do's
- • Define clear, specific roles for each agent
- • Write detailed backstories for better context
- • Set explicit expected outputs for tasks
- • Use context parameter for task dependencies
- • Enable memory for long-running projects
- • Test crew behavior with different inputs
- • Monitor token usage and costs
- • Version control crew configurations
❌ Don'ts
- • Don't create overly complex crew hierarchies
- • Don't ignore task dependencies
- • Don't use vague role descriptions
- • Don't skip output validation
- • Don't enable delegation without testing
- • Don't mix incompatible process types
- • Don't forget error handling
- • Don't overlook rate limits