Coordinating Teams of AI Agents with CrewAI in Python

CrewAI in Python: Coordinating Teams of AI Agents

by Farah Abdou 0 Comments intermediate ai

Have you ever asked ChatGPT to research something, analyze the findings, and then write a polished report, all in one prompt? You probably got something back, but it wasn’t great. That’s because you’re asking a single model to wear way too many hats at once. CrewAI is a Python framework that solves this by letting you build a crew of specialized AI agents, each focusing on one part of the job.

For example, instead of cramming research, validation, and writing into a single prompt, you create a team. One agent researches, another validates, and a third writes. Each focuses on what it does best, working together to complete the task.

By the end of this tutorial, you’ll understand that:

  • CrewAI coordinates teams where each agent has a specific role, goal, and backstory that influence its behavior.
  • Sequential workflows automatically pass outputs from one agent to the next, making coordinated pipelines straightforward.
  • The context parameter gives you fine-grained control over which task outputs feed into other tasks.
  • You can equip agents with tools like web scraping to expand what they can do beyond text generation.
  • API costs multiply quickly since each agent makes separate LLM calls, and verbose logging helps you debug agent behavior.

Before you invest time learning CrewAI, you should understand when it’s the right tool for your project. This comparison highlights the key trade-offs:

Use Case Pick CrewAI Pick LangGraph Pick AG2 / AutoGen
You need structured, role-based workflows - -
You want minimal boilerplate to go from prototype to production - -
You need complex state machines with conditional branching - -
Your agents need conversational, chat-driven coordination - -

CrewAI’s sweet spot is workflows where agents have clear responsibilities and work in a predictable sequence. If you need fine-grained state management with branching logic, LangGraph gives you more control. If your agents need conversational back-and-forth, AG2—the community fork of AutoGen—supports chat-driven coordination patterns and may be a better fit.

Microsoft AutoGen is now in maintenance mode, so new projects typically choose AG2 or Microsoft Agent Framework.

Take the Quiz: Test your knowledge with our interactive “CrewAI in Python: Coordinating Teams of AI Agents” quiz. You’ll receive a score upon completion to help you track your learning progress:


Interactive Quiz

CrewAI in Python: Coordinating Teams of AI Agents

Check your understanding of CrewAI in Python. Review how to define agent roles, assign tasks, add tools, and coordinate multi-agent workflows.

Get Started With CrewAI in Python

Before you dive into building multi-agent systems with CrewAI, you’ll need to install it and set up an API key for your chosen language model provider. This tutorial uses Google’s Gemini model, which you can access for free through Google AI Studio.

You can install CrewAI from PyPI using pip. Before running the command below, you should create and activate a virtual environment. CrewAI requires Python 3.10 to 3.13, so run python --version first—installing on Python 3.14 or later will silently resolve to a much older CrewAI release and then fail to build:

Language: Shell
$ python -m pip install 'crewai[tools,google-genai]'

This installs CrewAI’s core framework, the native Google Gemini provider, and prebuilt tools like web scraping that agents can use during their work.

You’ll need a Gemini API key to run the examples in this tutorial. If you don’t have one yet, then head over to Google AI Studio to sign in with your Google account and generate an API key for free.

Once you have your API key, set it as an environment variable:

Language: Windows PowerShell
PS> $ENV:GEMINI_API_KEY = "your-gemini-api-key-here"
Language: Shell
$ export GEMINI_API_KEY="your-gemini-api-key-here"

With your environment variable set, CrewAI is ready to connect to Gemini in your projects.

To get started with CrewAI, you can create a single agent that acts as a travel advisor:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Article

Already a member? Sign-In

Locked learning resources

The full article is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Article

Already a member? Sign-In

About Farah Abdou

Farah is an avid Pythonista and Real Python contributor.

» More about Farah

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

What Do You Think?

What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.

Commenting Tips: The most useful comments are those written with the goal of learning from or helping out other students. Get tips for asking good questions and get answers to common questions in our support portal.


Looking for a real-time conversation? Visit the Real Python Community Chat or join the next “Office Hours” Live Q&A Session. Happy Pythoning!

Become a Member to join the conversation.

Keep Learning

Related Topics: intermediate ai