CrewAI Basics
Master CrewAI framework for orchestrating role-playing autonomous AI agents
Your Progress
0 / 5 completedPutting It All Together: Building Crews
Now that you have agents (roles) and tasks (jobs), you combine them into a Crew. The Crew object orchestrates everything: assigns tasks to agents, manages execution flow, and returns final output.
🚀 Creating a Crew
from crewai import Crew, Process
# Define your crew
crew = Crew(
agents=[researcher, writer, analyst], # List of agents
tasks=[research_task, writing_task, review_task], # List of tasks
process=Process.sequential, # How to execute tasks
verbose=True # Show detailed logs
)
# Kick off the crew
result = crew.kickoff()
print(result) # Final output from last taskInteractive: Crew Execution Simulator
⚙️ Crew Configuration Options
process (Process enum)
How tasks are executed: Process.sequential (one at a time) or Process.hierarchical (manager coordinates).
💡 Start with sequential - it's simpler and uses fewer tokens
verbose (boolean)
Set to True to see detailed logs of agent thinking and tool usage. Great for debugging, but can be noisy.
💡 Use verbose=2 for even more detailed output
manager_llm (LLM object)
For hierarchical process, specify which LLM the manager agent should use. Can be different from worker agents' LLMs.
💡 Example: Use GPT-4 for manager, GPT-3.5 for workers to save costs
memory (boolean)
Enable agents to remember previous interactions across multiple crew runs. Useful for iterative workflows and maintaining context.
💡 Set to True for conversational or multi-session workflows
📦 Complete Example
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool
# 1. Define Agents
researcher = Agent(
role='Senior Researcher',
goal='Uncover cutting-edge AI developments',
backstory='You work at a leading tech think tank',
tools=[SerperDevTool()],
verbose=True
)
writer = Agent(
role='Tech Content Strategist',
goal='Craft compelling content on tech advancements',
backstory='You are a renowned content creator',
verbose=True
)
# 2. Define Tasks
research_task = Task(
description='Research latest AI trends for 2024',
expected_output='3-paragraph report on AI trends',
agent=researcher
)
writing_task = Task(
description='Write engaging blog post about AI trends',
expected_output='4-paragraph blog post in markdown',
agent=writer,
context=[research_task] # Can access research output
)
# 3. Create Crew
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
process=Process.sequential,
verbose=True
)
# 4. Run Crew
result = crew.kickoff()
print(result)🎯 CrewAI Best Practices
- •Match agents to tasks: Assign tasks to agents with relevant roles and expertise
- •Start simple: Begin with 2-3 agents and sequential process before adding complexity
- •Use verbose for debugging: Set verbose=True to understand agent behavior and troubleshoot
- •Leverage context: Use task context to pass information between agents efficiently
- •Test iteratively: Run crew with small tasks first to validate agent behavior before scaling