VOOZH about

URL: https://www.geeksforgeeks.org/artificial-intelligence/crewai-collaboration/

⇱ CrewAI Collaboration - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CrewAI Collaboration

Last Updated : 14 Apr, 2026

CrewAI is a framework that enables multiple autonomous agents to collaborate and achieve complex tasks together. By defining agents, tasks and processes we can design workflows that mimic real-world teamwork. CrewAI supports different types of collaboration, primarily include:

  • Sequential Collaboration: Tasks are executed in a defined order, where one agent’s output becomes another’s input.
  • Hierarchical Collaboration: A manager agent who oversees the process, delegating tasks dynamically to other agents.

Installing CrewAI

Before using CrewAI, install it in our environment. We will install CrewAI using pip:

pip install crewai

After installation, we can set up the API key and import the needed classes:

This gives us access to the Agent, Task, Crew and Process classes required to define and run multi-agent workflows.

1. Sequential Process

In a Sequential Process, tasks are executed in a strict order, where each task depends on the output of the previous one. This ensures a structured workflow, making it suitable for step-by-step tasks like cooking or reporting.

This type of process works best in situations like cooking, research or reporting where each stage builds directly on the last. We will implement an example of a Chef and a Food Critic.

Step 1: Defining Agents

We will define our two agents , the Chef and the Food Critic.

  • Agent: Represents a role with a goal and backstory.
  • Verbose: Enables detailed logs of the process.

Step 2: Defining Tasks

We will now define the tasks for the chef and the food critic.

  • Task: Defines what needs to be done and by whom.
  • Context: Ensures that the critic waits for the chef’s task to finish.

Step 3: Defining Crew

We will bring the agents and tasks together into a crew and set the process to sequential.

  • Crew: Brings agents and tasks together.
  • Process.sequential: Runs tasks one after another.
  • kickoff(): Starts the crew, activating all agents and executing tasks according to the selected process.

Output:

👁 sequential
Sequential Process

2. Hierarchical Process

Hierarchical Process introduces a manager agent who oversees the process, assigning tasks to the right agents. Instead of tasks being locked in a fixed sequence, the manager looks at the situation and assigns tasks to the right agents. This makes the workflow more flexible and allows the crew to adjust as needed.

It works best in larger or more complex projects where many different roles are involved and coordination is important. We will implement an example of a Construction Crew:

Step 1: Defining Agents

We will define three specialized agents: Foundation Builder, Wall Builder and Roof Builder.

  • Agent: Represents a role with a goal and backstory.
  • Verbose: Enables detailed logs of the process.

Step 2: Defining Tasks

We will now define the tasks for constructing the foundation, walls and roof.

  • Task: Defines what needs to be done and by whom.
  • Context: Ensures that the critic waits for the chef’s task to finish.

Note: Tasks do not specify agents directly, the manager assigns them.

Step 3: Defining Crew with Manager

We will now create the crew, set the process to hierarchical and assign a manager LLM.

  • Process.hierarchical: Allows a manager to delegate tasks dynamically.
  • manager_llm: Specifies the language model that acts as the manager.
  • kickoff(): Starts the crew, activating all agents and executing tasks according to the selected process.

Output:

👁 hirerchial
Hierarchical Process

Difference Between Sequential and Hierarchical Processess

This table highlights the main differences between the two processes and when each is most suitable.

FeatureSequential ProcessHierarchical Process
Task FlowLinear, tasks run in a fixed orderManager decides order dynamically
DependenciesEach task may depend on previous task outputManager oversees dependencies
FlexibilityLess flexible, strictly orderedMore flexible, allows dynamic decision making
Manager RoleNot requiredRequired (via manager agent or LLM)
Best Use CaseWhen tasks strictly depend on each otherWhen tasks need coordination and oversight
Comment

Explore