Skip to content

CrewAI

Overview

CrewAI makes it easy to build teams of AI agents that work together on complex tasks.

Each agent has a role, specific tasks, and can use tools.


Building a Crew

from crewai import Agent, Task, Crew

class ResearchCrew:
 """Build a team of research agents"""

 def __init__(self):
 # Define agents
 self.researcher = Agent(
 role="Research Analyst",
 goal="Find and analyze information",
 backstory="You are an expert research analyst",
 tools=[WebSearchTool(), PaperAnalyzer()]
)

 self.writer = Agent(
 role="Technical Writer",
 goal="Write clear technical content",
 backstory="You are an expert technical writer",
 tools=[WritingAssistandTool()]
)

 # Define tasks
 self.research_task = Task(
 description="Research the topic: {topic}",
 agent=self.researcher
)

 self.writing_task = Task(
 description="Write a report based on: {research}",
 agent=self.writer,
 depends_on=[self.research_task]
)

 # Create crew
 self.crew = Crew(
 agents=[self.researcher, self.writer],
 tasks=[self.research_task, self.writing_task]
)

 def execute(self, topic):
 """Run the crew"""
 result = self.crew.kickoff(
 inputs={"topic": topic}
)
 return result

Hierarchical Processes

Manager Agent

class HierarchicalTeam:
 """Team with manager coordination"""

 def __init__(self):
 self.manager = Agent(
 role="Project Manager",
 goal="Coordinate team effectively",
 backstory="You are an experienced project manager"
)

 self.agents = [
 # Various team members
]

 self.tasks = [
 # Various tasks
]

 self.crew = Crew(
 agents=[self.manager] + self.agents,
 tasks=self.tasks,
 manager_agent=self.manager,
 process="hierarchical" # Manager coordinates
)

Memory & Learning

Agent Memory

class LearningSystem:
 """Crew that learns over time"""

 def __init__(self):
 self.agent = Agent(
 role="Learner",
 memory=True, # Enable memory
 memory_config={
 'type': 'short_term', # Conversation memory
 'size': 50 # Remember last 50 messages
 }
)

3 Warnings

Warning 1: Task Dependencies

# WRONG
# Circular dependencies
task_a.depends_on([task_b])
task_b.depends_on([task_a])
# Deadlock!

# RIGHT
# Linear or DAG dependencies
task_1  task_2  task_3

Warning 2: Agent Conflicts

# WRONG
# Agents with conflicting goals
agent_1.goal = "Maximize speed"
agent_2.goal = "Maximize accuracy"
# They fight each other

# RIGHT
# Aligned goals
agent_1.goal = "Complete task efficiently"
agent_2.goal = "Ensure quality"
# Can work together

Warning 3: Token Waste

# WRONG
# Each agent re-processes everything
# Information passed multiple times

# RIGHT
# Pass refined results between agents
# Reduce redundant processing

-

Last Updated: August 9, 2026