Module 8 Lesson 4: Agent Collaboration Models
Sequential vs. Hierarchical. Choosing the right organizational structure for your agent team.
Collaboration Models: Managing the Crew
How should your agents talk to each other? Should Agent A always finish before Agent B starts? Or should there be a "Manager" who decides the order? In CrewAI, this is defined by the Process.
1. The Sequential Process (Standard)
The tasks are executed one after the other.
- Pattern: A -> B -> C.
- Best for: Linear workflows like research and writing.
- Advantage: Very easy to debug. You know exactly where the project failed.
2. The Hierarchical Process (Advanced)
In this model, you don't define the order. You define a Manager Agent.
- The Manager receives the goal.
- The Manager reviews the team's roles.
- The Manager assigns tasks dynamically.
- The Manager reviews the output and decides if it needs to be sent back for a rewrite.
graph TD
User[Project Goal] --> Manager[Manager Agent]
Manager <--> W1[Worker: Researcher]
Manager <--> W2[Worker: Writer]
Manager <--> W3[Worker: Designer]
Manager --> Final[Final Result]
Why use a Hierarchical model?
It handles Cycles and Validation automatically. The Manager acts as the "Validator" we studied in Module 3.
3. Consensual Collaboration
While not a native "Process" keyword, you can build consensual patterns where Agent A and Agent B must both "Approve" an output before it moves to Task 3.
- Example: A Technical review + A Financial review must both pass before a project is greenlit.
4. Code Example: Defining the Process
from crewai import Crew, Process
# 1. Sequential (The Default)
crew = Crew(
agents=[researcher, writer],
tasks=[task1, task2],
process=Process.sequential
)
# 2. Hierarchical (Requires a Manager LLM)
crew = Crew(
agents=[researcher, writer],
tasks=[task1, task2],
process=Process.hierarchical,
manager_llm=manager_llm # The brain that organizes the work
)
5. Summary Matrix: Which to Choose?
| Task Complexity | Recommendation | Why? |
|---|---|---|
| Straightforward | Sequential | Fast, low cost, easy to track. |
| Ambiguous | Hierarchical | The Manager handles the exploration. |
| High Quality | Hierarchical | Built-in review and revision cycles. |
Key Takeaways
- Sequential is the "Conveyor Belt" of task management.
- Hierarchical is the "Office" of task management.
- The Manager Agent acts as a dynamic router and quality checker.
- Choosing the right model depends on the Predictability of your workflow.