get_flight_status to fetch flight status and the Python REPL tool for simple calculations (for example, adding hours to an arrival time to compute when to book a cab).
Prerequisites
- Sign up at FlightAware and create an AeroAPI key: FlightAware AeroAPI.
- Set the
AEROAPI_KEYenvironment variable before running the examples (see callout below). - Basic familiarity with Python and LangChain (see references at the end).



Set your FlightAware API key in the environment before running the code. For example, on macOS/Linux:
- Implement a
get_flight_statusLangChain tool that:- Calls the AeroAPI for flights on the current day.
- Picks the best available timestamps using the priority estimated > actual > scheduled.
- Converts UTC timestamps to the local timezone of origin/destination.
- Returns a human-readable status string.
- Register the tool along with the Python REPL tool.
- Create a ReAct-style agent prompt so the agent plans (Thought), calls tools (Action), observes results, and provides a final answer.
- Use the Python REPL tool for follow-up computations (e.g., add hours to arrival time).
- Save the following implementation as
flight_agent.py. This function uses requests to call the AeroAPI, chooses the best time fields, converts times from UTC to local timezones viapytz, and returns a readable status string.
- With
AEROAPI_KEYset and network available, you can call the tool directly:
- Register the two tools (custom flight tool + Python REPL) and construct a ReAct prompt that directs the agent to think, act, observe, and repeat until it produces the final answer.
- Send a flight query to the agent executor. The ReAct loop will call
get_flight_status, observe the API result, optionally perform follow-up calculations via the Python REPL, and then produce a final answer.
- When
agent_executorruns in verbose mode it logs the Thought/Action/Observation steps. Example:
- The Python REPL tool is useful for follow-up computations, such as determining the time to book a cab after arrival.
Best practices and production considerations
- Always set your
AEROAPI_KEYenvironment variable before running the agent. - The timestamp selection prioritizes
estimatedoveractualoverscheduled. - Handle HTTP/network errors and JSON parsing gracefully in production (the example raises errors for clarity).
- Be mindful of API quotas and rate limits—use caching or debounce frequent queries when appropriate.
- Extend the agent with additional tools (weather, maps, booking APIs) to support richer interactions.
FlightAware’s free tier may have limitations on calls and data. Monitor usage in the AeroAPI dashboard and upgrade if you need higher quotas or commercial support.