Travel Planning
This is from AG2’s Build with AG2 repository, find the source files and more use cases there!
Here’s a trip planning Swarm, to create an itinerary together with a customer, that you can build upon for your needs. The end result will be an itinerary that has route times and distances calculated between activities.
Details
The following diagram outlines the key components of the Swarm, with highlights being:
- FalkorDB agent using a GraphRAG database of restaurants and attractions
- Structured Output agent that will enforce a strict format for the accepted itinerary
- Routing agent that utilises the Google Maps API to calculate distances between activities
- Swarm orchestration utilising context variables
Installation
-
Clone and navigate to the folder:
-
Install the required dependencies:
The dependency is ag2 with graphrag option.
-
Set up a FalkorDB graph database. Please refer to https://docs.falkordb.com/. After the database is running, please adjust FalkorDB host and port accordingly (line 74-75 in
main.py
). A quick way is to set up docker and run this command:Note: You need to have a FalkorDB graph database running. If you are running one in a Docker container, please ensure your Docker network is setup to allow access to it.
Run the code
1. Google Maps API Key
To use Google’s API to calculate travel times, you will need to have enabled the Directions API
in your Google Maps Platform. You can get an API key and free quota, see here and here for more details.
Once you have your API key, set your environment variable GOOGLE_MAP_API_KEY
to the key.
2. Set Configuration and OpenAI API Key
Please modify the config_list
in the main.py
file (line 35). Read more about configurations here. This configuration will be used to set up ag2 agents.
By default, FalkorDB uses OpenAI LLMs and that requires an OpenAI key in your environment variable OPENAI_API_KEY
. We will extract the key from the configuration you set (line 49). If you are not using OpenAI in config_list
, you may comment out the line and read from your environment variable directly.
3. Run the code
You can now interact with the system through the command line to plan a trip to Rome! You can also modify the initial message to plan a trip to another city.
Note: after first run of the code, the db will be initialized and you can switch to connect_db
in line 82 and 85 in main.py
for faster rerun.