Introduction and Overview

Welcome to this lesson on working with multiple specialized agents and tasks in CrewAI. In our previous lessons, we explored the foundational concepts of CrewAI, including creating agents, defining tasks, and using placeholders to make tasks flexible. Today, we will build on that knowledge by learning how to manage multiple agents with specialized roles and interdependent tasks. By the end of this lesson, you will understand how to coordinate agents like a travel researcher and an itinerary planner to create a seamless travel planning process. This will enhance your ability to design complex workflows in CrewAI, preparing you for more advanced applications.

Building a Team of Specialized Travel Agents

In this lesson, we'll build a travel planning crew with specialized agents working together to create the perfect vacation itinerary:

  • Travel Researcher: Our destination expert who hunts down the most interesting attractions, hidden gems, and must-see spots in any city.
  • Itinerary Planner: Our organizational wizard who transforms a list of attractions into a coherent, efficient travel plan.

Together, these specialized agents combine their unique skills to deliver a comprehensive travel experience that neither could create alone.

Creating a Workflow with Connected Tasks

Our travel planning crew will complete two interconnected tasks that flow naturally from one to the next:

  • Research Task: The Travel Researcher will investigate attractions in the target city, providing rich descriptions of each location.
  • Planning Task: The Itinerary Planner will take the researcher's findings and craft them into a day-by-day schedule.

To connect these tasks, we use the context=[research_task] parameter when defining our planning task. This parameter tells CrewAI that the planning task needs information from the research task to do its job properly. Think of it as passing the research results directly to the planner so they have all the information they need to create a great itinerary.

Assembling the Travel Planning Crew

With our travel experts defined and their tasks outlined, it's time to bring everything together into a cohesive travel planning team:

This crew setup creates our complete travel planning workflow:

  • We provide a list of all our agents (researcher and planner) so the crew knows who's available to work
  • We include all the tasks (research_task and planning_task) that need to be completed
  • We set process=Process.sequential to ensure tasks run in order - this is crucial since our planning task depends on the results from the research task

The Process.sequential parameter is particularly important for our travel planning workflow. It tells CrewAI to execute tasks one after another in the order they appear in the tasks list. This ensures the Travel Researcher completes their work before the Itinerary Planner begins, maintaining our logical workflow from research to planning.

Running the Crew and Analyzing Results

Once the crew is assembled, we can set up dynamic inputs and execute the crew to see how the agents work together. In our example, we calculate the total number of attractions based on the number of days and attractions per day, then pass these values as inputs to the crew:

The output will be a detailed itinerary for a 2-day trip to Barcelona, including 4 researched attractions (2 per day), timing, transportation tips, and meal suggestions.

Summary and Next Steps

In this lesson, you learned how to work with multiple specialized agents and tasks in CrewAI. We explored the benefits of agent specialization, defined interdependent tasks using the context parameter, and assembled a crew to execute a travel planning process. By understanding how to manage interdependencies and context between agents, you can create more complex and efficient workflows. As you move forward, you'll have the opportunity to practice these concepts through hands-on exercises. Keep exploring CrewAI, and you'll soon be proficient in designing dynamic and adaptable workflows.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal