Crews
Learn to orchestrate multi-agent workflows with sequential and hierarchical processes, memory systems, planning, and advanced crew configuration.
Sequential Process
In a sequential process, tasks execute one after another in order. Each task can receive the output of previous tasks as context:
from crewai import Crew, Process crew = Crew( agents=[researcher, writer, editor], tasks=[research_task, writing_task, editing_task], process=Process.sequential, # Task 1 → Task 2 → Task 3 verbose=True ) result = crew.kickoff() # Sequential flow: # 1. Researcher completes research_task # 2. Writer receives research output, completes writing_task # 3. Editor receives writing output, completes editing_task # → Final result = editing_task output
Hierarchical Process
In a hierarchical process, a manager agent coordinates the crew, delegating tasks and reviewing results:
crew = Crew(
agents=[researcher, writer, editor],
tasks=[research_task, writing_task, editing_task],
process=Process.hierarchical, # Manager delegates tasks
manager_llm="gpt-4o", # LLM for the manager agent
verbose=True
)
result = crew.kickoff()
# Hierarchical flow:
# 1. Manager analyzes all tasks
# 2. Manager delegates research_task to researcher
# 3. Manager reviews output, delegates writing_task to writer
# 4. Manager may request revisions or re-delegation
# 5. Manager delegates editing_task to editor
# → Final result curated by manager
Sequential vs Hierarchical
| Feature | Sequential | Hierarchical |
|---|---|---|
| Task Order | Fixed, in list order | Manager decides dynamically |
| Coordination | Automatic (output flows to next) | Manager coordinates |
| Flexibility | Predictable, linear | Adaptive, can re-delegate |
| Cost | Lower (no manager LLM calls) | Higher (manager overhead) |
| Best For | Linear workflows, pipelines | Complex, dynamic workflows |
Memory
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
process=Process.sequential,
memory=True, # Enable memory across runs
verbose=True
)
# Memory types:
# Short-term: conversation within a single crew run
# Long-term: persisted across multiple crew runs
# Entity: remembers key entities and facts
# First run - crew learns about the topic
result1 = crew.kickoff(inputs={"topic": "AI in Healthcare"})
# Second run - crew remembers previous research
result2 = crew.kickoff(inputs={"topic": "AI in Healthcare Updates"})
Dynamic Inputs
# Use {placeholders} in task descriptions research_task = Task( description="Research {topic} for the {market} market.", expected_output="Detailed report on {topic}.", agent=researcher ) crew = Crew( agents=[researcher, writer], tasks=[research_task, writing_task], process=Process.sequential ) # Pass inputs at runtime result = crew.kickoff(inputs={ "topic": "Electric Vehicles", "market": "European" })
Real-World Example: Content Creation Crew
from crewai import Agent, Task, Crew, Process from crewai_tools import SerperDevTool # Agents researcher = Agent( role="SEO Research Specialist", goal="Find trending topics and keywords for {topic}", backstory="Expert in SEO research and trend analysis.", tools=[SerperDevTool()], ) writer = Agent( role="Senior Content Writer", goal="Write SEO-optimized articles that rank and engage", backstory="Award-winning writer specializing in tech content.", ) editor = Agent( role="Chief Editor", goal="Ensure all content is accurate, engaging, and polished", backstory="Former newspaper editor with an eye for detail.", ) # Tasks research = Task( description="Research {topic}. Find 5 key angles, trending keywords, and competitor content.", expected_output="Research brief with angles, keywords, and sources.", agent=researcher, ) write = Task( description="Write a 1000-word article on {topic} using the research. Include H2 headings, code examples, and a call-to-action.", expected_output="A complete article in markdown format.", agent=writer, context=[research], ) edit = Task( description="Edit the article for grammar, accuracy, SEO, and readability. Ensure claims match the research.", expected_output="Final polished article ready for publication.", agent=editor, context=[write, research], output_file="output/article.md", ) # Crew content_crew = Crew( agents=[researcher, writer, editor], tasks=[research, write, edit], process=Process.sequential, verbose=True, ) result = content_crew.kickoff(inputs={"topic": "AI Code Assistants"})
What's Next?
In the final lesson, we will cover best practices, real-world patterns, debugging strategies, cost control, and production deployment.
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX