Skip to main content

Amadeus

This notebook walks you through connecting LangChain to the Amadeus travel APIs.

This Amadeus toolkit allows agents to make decision when it comes to travel, especially searching and booking trips with flights.

To use this toolkit, you will need to have your Amadeus API keys ready, explained in the Get started Amadeus Self-Service APIs. Once you’ve received a AMADEUS_CLIENT_ID and AMADEUS_CLIENT_SECRET, you can input them as environmental variables below.

Note: Amadeus Self-Service APIs offers a test enviornment with free limited data. This allows developers to build and test their applications before deploying them to production. To access real-time data, you will need to move to the production environment.

!pip install --upgrade amadeus > /dev/null

Assign Environmental Variables​

The toolkit will read the AMADEUS_CLIENT_ID and AMADEUS_CLIENT_SECRET environmental variables to authenticate the user so you need to set them here. You will also need to set your OPENAI_API_KEY to use the agent later.

# Set environmental variables here
import os

os.environ["AMADEUS_CLIENT_ID"] = "CLIENT_ID"
os.environ["AMADEUS_CLIENT_SECRET"] = "CLIENT_SECRET"
os.environ["OPENAI_API_KEY"] = "API_KEY"
# os.environ["AMADEUS_HOSTNAME"] = "production" or "test"

Create the Amadeus Toolkit and Get Tools​

To start, you need to create the toolkit, so you can access its tools later.

from langchain_community.agent_toolkits.amadeus.toolkit import AmadeusToolkit

toolkit = AmadeusToolkit()
tools = toolkit.get_tools()

Use Amadeus Toolkit within an Agent​

from langchain.agents import AgentType, initialize_agent
from langchain_openai import OpenAI
llm = OpenAI(temperature=0)
agent = initialize_agent(
tools=tools,
llm=llm,
verbose=False,
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
)
agent.run("What is the name of the airport in Cali, Colombia?")
'The closest airport to Cali, Colombia is Alfonso Bonilla AragΓ³n International Airport (CLO).'
agent.run(
"What is the departure time of the cheapest flight on August 23, 2023 leaving Dallas, Texas before noon to Lincoln, Nebraska?"
)
'The cheapest flight on August 23, 2023 leaving Dallas, Texas before noon to Lincoln, Nebraska has a departure time of 16:42 and a total price of 276.08 EURO.'
agent.run(
"At what time does earliest flight on August 23, 2023 leaving Dallas, Texas to Lincoln, Nebraska land in Nebraska?"
)
'The earliest flight on August 23, 2023 leaving Dallas, Texas to Lincoln, Nebraska lands in Lincoln, Nebraska at 16:07.'
agent.run(
"What is the full travel time for the cheapest flight between Portland, Oregon to Dallas, TX on October 3, 2023?"
)
'The cheapest flight between Portland, Oregon to Dallas, TX on October 3, 2023 is a Spirit Airlines flight with a total price of 84.02 EURO and a total travel time of 8 hours and 43 minutes.'
agent.run(
"Please draft a concise email from Santiago to Paul, Santiago's travel agent, asking him to book the earliest flight from DFW to DCA on Aug 28, 2023. Include all flight details in the email."
)
'Dear Paul,\n\nI am writing to request that you book the earliest flight from DFW to DCA on Aug 28, 2023. The flight details are as follows:\n\nFlight 1: DFW to ATL, departing at 7:15 AM, arriving at 10:25 AM, flight number 983, carrier Delta Air Lines\nFlight 2: ATL to DCA, departing at 12:15 PM, arriving at 2:02 PM, flight number 759, carrier Delta Air Lines\n\nThank you for your help.\n\nSincerely,\nSantiago'