This project demonstrates how to create an automated vacation planner using AI agents and the Crew AI framework. The planner autonomously handles various aspects of vacation planning, such as finding accommodation, planning daily itineraries, and managing the budget.
- Introduction
- Project Structure
- Setup Instructions
- Agents Definition
- Tasks Definition
- Running the Project
- Final Output
This project leverages the Crew AI framework to create a multi-agent system that automates the process of planning a vacation. By defining specialized agents and their respective tasks, the system can efficiently find accommodation, plan daily activities, and manage the budget for a vacation.
travel_agent.py
: Main script that defines agents, tasks, and executes the vacation planning process.utils.py
: Utility functions for fetching API keys.requirements.txt
: List of required Python packages.
Additional Multi-Agent Examples for You to Explore:
python_writer.py
: Describe a task you want implemented in Python and the crew will output the Python code.stock_analysis.py
: Describe a stock you want analyzed in the market and the crew will give feedback on it.resume_builder.py
: Give the crew your current resume in markdown format along with a job posting link and your github. It will tailor the resume to the job you are applying for.fake_resume.md
is included in the repo for you to play around with the code with this resume.
- Python 3.7+
- OpenAI API key
- Serper API key
-
Clone the Repository
git clone https://github.com/techindicium/MultiAgent-CrewAI.git cd MultiAgent-CrewAI
-
Install Required Packages
pip install -r requirements.txt
-
Set Up API Keys
- Create a file named
.env
in the root directory of the project and add your API keys:OPENAI_API_KEY=your_openai_api_key SERPER_API_KEY=your_serper_api_key
- Create a file named
Agents are autonomous units that perform specific roles within the vacation planning process. We define three agents in this project:
- Role: Identify suitable accommodation options.
- Tools:
SerperDevTool
,ScrapeWebsiteTool
- Goal: Find hotels, rental homes, or vacation rentals that meet specified criteria.
rental_coordinator = Agent(
role="Hotel/Rental Coordinator",
goal="Identify an appropriate hotel, rental home, or vacation rental.",
tools=[search_tool, scrape_tool],
verbose=True,
backstory=(
"With a keen sense of space and understanding of vacation logistics, "
"you excel at finding and securing the perfect vacation rental that fits "
"the vacation's location, start and end dates, group size, and budget constraints."
)
)
- Role: Create a detailed itinerary including daily excursions and activities.
- Tools:
SerperDevTool
,ScrapeWebsiteTool
- Goal: Plan activities considering the traveler's interests, budget, and logistics.
itinerary_planner = Agent(
role="Itinerary Planner",
goal="Create a proposed itinerary including daily excursions and activities.",
tools=[search_tool, scrape_tool],
verbose=True,
backstory=(
"With a passion for adventure and local culture, you specialize in planning engaging "
"and budget-friendly itineraries, taking into account the traveler's interests, budget, "
"and logistics like transportation needs."
)
)
- Role: Manage the overall budget for the trip.
- Tools:
SerperDevTool
- Goal: Ensure all aspects of the vacation stay within the allocated budget.
budgeting_agent = Agent(
role="Budgeting Agent",
goal="Manage the overall budget for the trip, considering the cost of accommodation and daily activities.",
tools=[search_tool],
verbose=True,
backstory=(
"With a knack for financial planning, you ensure the vacation remains within budget while maximizing value and enjoyment."
)
)
Tasks define what each agent needs to accomplish. Properly structured tasks are crucial for guiding agents to perform their roles effectively.
hotel_task = Task(
description="Find a hotel or rental in {vacation_city} "
"that meets criteria for {vacation_details}, {budget}, {group_size}, {start_date} and {end_date}.",
expected_output="Details of suitable rental options, including name, address, capacity, price per night, available dates, description, and amenities.",
human_input=True,
output_json=RentalDetails,
output_file="venue_details.json",
agent=rental_coordinator
)
itinerary_task = Task(
description="Plan a full itinerary for the trip in {vacation_city}, considering {vacation_details}, {budget}, and {group_size}. Include daily excursions and local activities, specifying if a rental car is needed.",
expected_output="A detailed itinerary for each day of the trip, including activities, locations, estimated costs, and rental car needs.",
human_input=True,
output_json=FullItinerary,
output_file="itinerary_details.json",
agent=itinerary_planner
)
budgeting_task = Task(
description="Ensure the total cost of the trip, including accommodation and daily activities, stays within the allocated budget of {budget}.",
expected_output="Adjusted itinerary with budget considerations, including the cost of accommodation and daily activities.",
human_input=True,
output_json=FullItinerary,
output_file="final_itinerary.json",
agent=budgeting_agent
)
To run the vacation planner, follow these steps:
-
Initialize the Crew Define the crew with the agents and tasks.
vacation_planning_crew = Crew( agents=[rental_coordinator, itinerary_planner, budgeting_agent], tasks=[hotel_task, itinerary_task, budgeting_task], manager_llm=ChatOpenAI(model="gpt-3.5-turbo", temperature=0.7), process=Process.hierarchical, verbose=True )
-
Kickoff the Process Provide the necessary input data and start the execution.
vacation_details = { 'vacation_city': "Honolulu", 'vacation_details': "A vacation for an adventurous family of 7 who want to explore the island, see the nature, and experience some good Hawaiian food and culture", 'start_date': "2024-06-15", 'end_date': "2024-06-22", 'group_size': 7, 'budget': 10000, } result = vacation_planning_crew.kickoff(inputs=vacation_details)
-
Load and Print the Final Itinerary After the tasks are completed, load the results from the JSON file.
with open('final_itinerary.json') as f: final_itinerary_data = json.load(f) pprint(final_itinerary_data)
The final output will be a detailed itinerary for the vacation, including:
- Accommodation options
- Daily activities and excursions
- Budget management details
This output is saved in final_itinerary.json
and can be printed for review.
By following these steps, you can recreate the automated vacation planner and understand how AI agents interact to achieve the overall goal. This approach demonstrates the power of AI-driven automation in simplifying and streamlining complex processes.