Step-by-step tutorial to create a collaborative AI team that works together to solve complex problems.
Imagine having a team of specialized AI agents working together seamlessly to solve complex problems, each contributing their unique skills to achieve a common goal. This is the power of CrewAI - a framework that enables you to create collaborative AI systems that can accomplish tasks far beyond what a single AI could achieve alone.
In this guide, we’ll walk through creating a research crew that will help us research and analyze a topic, then create a comprehensive report. This practical example demonstrates how AI agents can collaborate to accomplish complex tasks, but it’s just the beginning of what’s possible with CrewAI.
By the end of this guide, you’ll have:
While we’re building a simple research crew in this guide, the same patterns and techniques can be applied to create much more sophisticated teams for tasks like:
Let’s get started building your first crew!
Before starting, make sure you have:
First, let’s create a new CrewAI project using the CLI. This command will set up a complete project structure with all the necessary files, allowing you to focus on defining your agents and their tasks rather than setting up boilerplate code.
This will generate a project with the basic structure needed for your crew. The CLI automatically creates:
CrewAI Framework Overview
Let’s take a moment to understand the project structure created by the CLI. CrewAI follows best practices for Python projects, making it easy to maintain and extend your code as your crews become more complex.
This structure follows best practices for Python projects and makes it easy to organize your code. The separation of configuration files (in YAML) from implementation code (in Python) makes it easy to modify your crew’s behavior without changing the underlying code.
Now comes the fun part - defining your AI agents! In CrewAI, agents are specialized entities with specific roles, goals, and backstories that shape their behavior. Think of them as characters in a play, each with their own personality and purpose.
For our research crew, we’ll create two agents:
Let’s modify the agents.yaml
file to define these specialized agents. Be sure
to set llm
to the provider you are using.
Notice how each agent has a distinct role, goal, and backstory. These elements aren’t just descriptive - they actively shape how the agent approaches its tasks. By crafting these carefully, you can create agents with specialized skills and perspectives that complement each other.
With our agents defined, we now need to give them specific tasks to perform. Tasks in CrewAI represent the concrete work that agents will perform, with detailed instructions and expected outputs.
For our research crew, we’ll define two main tasks:
Let’s modify the tasks.yaml
file:
Note the context
field in the analysis task - this is a powerful feature that allows the analyst to access the output of the research task. This creates a workflow where information flows naturally between agents, just as it would in a human team.
Now it’s time to bring everything together by configuring our crew. The crew is the container that orchestrates how agents work together to complete tasks.
Let’s modify the crew.py
file:
In this code, we’re:
This is where the magic happens - with just a few lines of code, we’ve defined a collaborative AI system where specialized agents work together in a coordinated process.
Now, let’s set up the main script that will run our crew. This is where we provide the specific topic we want our crew to research.
This script prepares the environment, specifies our research topic, and kicks off the crew’s work. The power of CrewAI is evident in how simple this code is - all the complexity of managing multiple AI agents is handled by the framework.
Create a .env
file in your project root with your API keys:
See the LLM Setup guide for details on configuring your provider of choice. You can get a Serper API key from Serper.dev.
Install the required dependencies using the CrewAI CLI:
This command will:
Now for the exciting moment - it’s time to run your crew and see AI collaboration in action!
When you run this command, you’ll see your crew spring to life. The researcher will gather information about the specified topic, and the analyst will then create a comprehensive report based on that research. You’ll see the agents’ thought processes, actions, and outputs in real-time as they work together to complete their tasks.
Once the crew completes its work, you’ll find the final report in the output/report.md
file. The report will include:
Take a moment to appreciate what you’ve accomplished - you’ve created a system where multiple AI agents collaborated on a complex task, each contributing their specialized skills to produce a result that’s greater than what any single agent could achieve alone.
CrewAI offers several other useful CLI commands for working with crews:
What you’ve built in this guide is just the beginning. The skills and patterns you’ve learned can be applied to create increasingly sophisticated AI systems. Here are some ways you could extend this basic research crew:
You could add more specialized agents to your crew:
You could enhance your agents with additional tools:
You could implement more sophisticated processes:
The same patterns can be applied to create crews for:
Now that you’ve built your first crew, you can:
Congratulations! You’ve successfully built your first CrewAI crew that can research and analyze any topic you provide. This foundational experience has equipped you with the skills to create increasingly sophisticated AI systems that can tackle complex, multi-stage problems through collaborative intelligence.
Step-by-step tutorial to create a collaborative AI team that works together to solve complex problems.
Imagine having a team of specialized AI agents working together seamlessly to solve complex problems, each contributing their unique skills to achieve a common goal. This is the power of CrewAI - a framework that enables you to create collaborative AI systems that can accomplish tasks far beyond what a single AI could achieve alone.
In this guide, we’ll walk through creating a research crew that will help us research and analyze a topic, then create a comprehensive report. This practical example demonstrates how AI agents can collaborate to accomplish complex tasks, but it’s just the beginning of what’s possible with CrewAI.
By the end of this guide, you’ll have:
While we’re building a simple research crew in this guide, the same patterns and techniques can be applied to create much more sophisticated teams for tasks like:
Let’s get started building your first crew!
Before starting, make sure you have:
First, let’s create a new CrewAI project using the CLI. This command will set up a complete project structure with all the necessary files, allowing you to focus on defining your agents and their tasks rather than setting up boilerplate code.
This will generate a project with the basic structure needed for your crew. The CLI automatically creates:
CrewAI Framework Overview
Let’s take a moment to understand the project structure created by the CLI. CrewAI follows best practices for Python projects, making it easy to maintain and extend your code as your crews become more complex.
This structure follows best practices for Python projects and makes it easy to organize your code. The separation of configuration files (in YAML) from implementation code (in Python) makes it easy to modify your crew’s behavior without changing the underlying code.
Now comes the fun part - defining your AI agents! In CrewAI, agents are specialized entities with specific roles, goals, and backstories that shape their behavior. Think of them as characters in a play, each with their own personality and purpose.
For our research crew, we’ll create two agents:
Let’s modify the agents.yaml
file to define these specialized agents. Be sure
to set llm
to the provider you are using.
Notice how each agent has a distinct role, goal, and backstory. These elements aren’t just descriptive - they actively shape how the agent approaches its tasks. By crafting these carefully, you can create agents with specialized skills and perspectives that complement each other.
With our agents defined, we now need to give them specific tasks to perform. Tasks in CrewAI represent the concrete work that agents will perform, with detailed instructions and expected outputs.
For our research crew, we’ll define two main tasks:
Let’s modify the tasks.yaml
file:
Note the context
field in the analysis task - this is a powerful feature that allows the analyst to access the output of the research task. This creates a workflow where information flows naturally between agents, just as it would in a human team.
Now it’s time to bring everything together by configuring our crew. The crew is the container that orchestrates how agents work together to complete tasks.
Let’s modify the crew.py
file:
In this code, we’re:
This is where the magic happens - with just a few lines of code, we’ve defined a collaborative AI system where specialized agents work together in a coordinated process.
Now, let’s set up the main script that will run our crew. This is where we provide the specific topic we want our crew to research.
This script prepares the environment, specifies our research topic, and kicks off the crew’s work. The power of CrewAI is evident in how simple this code is - all the complexity of managing multiple AI agents is handled by the framework.
Create a .env
file in your project root with your API keys:
See the LLM Setup guide for details on configuring your provider of choice. You can get a Serper API key from Serper.dev.
Install the required dependencies using the CrewAI CLI:
This command will:
Now for the exciting moment - it’s time to run your crew and see AI collaboration in action!
When you run this command, you’ll see your crew spring to life. The researcher will gather information about the specified topic, and the analyst will then create a comprehensive report based on that research. You’ll see the agents’ thought processes, actions, and outputs in real-time as they work together to complete their tasks.
Once the crew completes its work, you’ll find the final report in the output/report.md
file. The report will include:
Take a moment to appreciate what you’ve accomplished - you’ve created a system where multiple AI agents collaborated on a complex task, each contributing their specialized skills to produce a result that’s greater than what any single agent could achieve alone.
CrewAI offers several other useful CLI commands for working with crews:
What you’ve built in this guide is just the beginning. The skills and patterns you’ve learned can be applied to create increasingly sophisticated AI systems. Here are some ways you could extend this basic research crew:
You could add more specialized agents to your crew:
You could enhance your agents with additional tools:
You could implement more sophisticated processes:
The same patterns can be applied to create crews for:
Now that you’ve built your first crew, you can:
Congratulations! You’ve successfully built your first CrewAI crew that can research and analyze any topic you provide. This foundational experience has equipped you with the skills to create increasingly sophisticated AI systems that can tackle complex, multi-stage problems through collaborative intelligence.