Open In App

What is CrewAI?

Last Updated : 25 Aug, 2025
Comments
Improve
Suggest changes
1 Likes
Like
Report

CrewAI is an open-source framework that enables multiple AI agents to work together to complete complex tasks. Each agent has a specific role and they collaborate to achieve the task efficiently.

crew
CrewAI

Imagine a group of people organizing a party: one person handles the planning, another handles food and drinks, while someone else manages decorations. CrewAI does the same but with AI agents. It can be used in event planning, content creation, software development and customer support to make tasks more efficient.

CrewAI uses features like memory retention and context awareness which ensures tasks are executed smoothly and decisions are made with the right context. It can be used in areas like event planning, content generation, research and software development.

Setting Up Environment

To begin using CrewAI, we need to set up our environment and install the necessary package. Here's how we can do it:

1. Installing the CrewAI Package

We will install the crewai package using pip to make all the necessary functionality available:

!pip install crewai

2. Setting the API Key

We will set our API key for external services like OpenAI:

Python
import os
os.environ["OPENAI_API_KEY"] = "your-api-key-here"

Implementation of CrewAI

In this section, we will see how to use CrewAI by setting up a team of agents to work together on a party planning task.

1. Importing Necessary Libraries

Before we start working with CrewAI, we need to import the required libraries. These libraries provide the essential functions to define agents, tasks and crews.

  • Agent: Defines the individual agents that perform tasks.
  • Task: Describes the tasks assigned to agents.
  • Crew: Groups agents and tasks together for execution.
Python
from crewai import Agent, Task, Crew

2. Defining Agents

Agents in CrewAI are the entities that perform specific tasks. They are defined by three key aspects:

  • Role: What the agent does (e.g., planning, food coordination).
  • Goal: The outcome the agent works toward (e.g., creating a party plan, managing food).
  • Backstory: Context or skills that describe the agent's abilities.
  • allow_delegation: Determines whether the agent can assign tasks to other agents. If set to False, the agent must handle tasks themselves.
  • verbose: When True, the agent provides detailed explanations about its actions and reasoning which helps in understanding what it’s doing step by step.

We will define agents for different roles such as party planner, food coordinator, decorator and entertainment manager.

Python
party_planner = Agent(
    role="Party Planner",
    goal="Create the party plan, including the theme, timeline, and guest list.",
    backstory=(
        "You organize the vision for the party, create a timeline, and ensure all aspects are planned. "
        "You send out invitations and coordinate with the other agents."
    ),
    allow_delegation=False,
    verbose=True
)

food_beverage_coordinator = Agent(
    role="Food & Beverage Coordinator",
    goal="Organize the food and drinks for the party, ensuring there’s enough variety for all guests.",
    backstory=(
        "You handle the food and drink preparations, whether it’s cooking, ordering, or working with caterers. "
        "You make sure guests have plenty to eat and drink throughout the event."
    ),
    allow_delegation=False,
    verbose=True
)

decorator = Agent(
    role="Decorator",
    goal="Make the party venue look great, fitting the theme and making it fun for guests.",
    backstory=(
        "You decorate the venue to match the theme and create a welcoming and festive environment. "
        "You ensure the venue is ready when the guests arrive."
    ),
    allow_delegation=False,
    verbose=True
)

entertainment_guest_relations = Agent(
    role="Entertainment & Guest Relations Coordinator",
    goal="Organize entertainment, games, and manage guest interactions to ensure a fun party.",
    backstory=(
        "You make sure the guests have fun, whether it’s through music, games, or other activities. "
        "You also help guests with seating and ensure the event flows smoothly."
    ),
    allow_delegation=False,
    verbose=True
)

3. Assigning Tasks

Each agent is given specific tasks to complete. Tasks range from planning the party to organizing food and drinks. Tasks are linked to agents and each agent performs their task according to their goal.

We will assign each agent a task, like creating the party plan or setting up the decorations.

Python
party_plan_task = Task(
    description="Create a party plan including theme, timeline, and guest list.",
    expected_output="Complete party plan with theme, timeline, and invitations.",
    agent=party_planner
)

food_task = Task(
    description="Organize food and drinks menu and set up food stations.",
    expected_output="Food and drinks ready for the party.",
    agent=food_beverage_coordinator
)

decor_task = Task(
    description="Decorate the venue according to the theme.",
    expected_output="Venue decorated and ready for guests.",
    agent=decorator
)

entertainment_task = Task(
    description="Organize music, games, and manage guest interactions.",
    expected_output="A fun and engaging atmosphere with happy guests.",
    agent=entertainment_guest_relations
)

4. Creating and Managing a Crew

A Crew is a group of agents working together on the same goal. We will create a Crew by grouping our agents and tasks together. This allows them to collaborate on the overall party planning process. We will combine the agents and tasks to create the party planning Crew.

Python
party_crew = Crew(agents=[party_planner, food_beverage_coordinator, decorator, entertainment_guest_relations], 
                  tasks=[party_plan_task, food_task, decor_task, entertainment_task], verbose=True)

5. Executing the Workflow

Once the Crew is set up, we start the task execution. The agents begin working on their respective tasks. We will kick off the party planning process and the agents will carry out their roles. We will run the Crew to start the planning tasks.

Python
party_result = party_crew.kickoff(inputs={})

Output:

crewai_output
Sample Output of CrewAI

When we run the crew, the output can be quite large because verbose mode shows the step-by-step working of each agent. For clarity, we are only showing a small sample snippet of the result

Applications of CrewAI

CrewAI can be applied in several areas where tasks require collaboration between specialized agents:

  • Event Planning: AI agents plan the event, handle food and drinks, decorate the venue and manage guest entertainment.
  • Content Creation: AI agents gather information, write articles and review content.
  • Software Development: AI agents write and review code, ensuring it meets requirements.
  • Market Research: AI agents gather data on trends, competitors and insights, creating reports based on findings.

Explore