Skip to content

serpapi/travel-planning-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Travel Agent

LLM-powered travel planning assistant that combines OpenAI chat models with multiple SerpApi tools (Google Flights, Google Hotels, Google Maps/Local). The agent reasons about user constraints (budget, luxury, flexible dates, etc.), asks clarifying questions, runs searches concurrently, and returns a well-cited answer. It includes an interactive CLI chat for discovery and planning, plus a Python class for programmatic use.


Features

  • Context-aware reasoning about constraints (budget, luxury, season)
  • Multi-tool integration via SerpApi (Flights, Hotels, Maps, Web search)
  • Chat-based CLI for discovery & exploration
  • Footnote-style citations with source links (tools return structured JSON with URLs to support citations)
  • JSON trace output for debugging or auditing

Requirements

  • Python 3.9+
  • Environment variables:
    • OPENAI_API_KEY
    • SERPAPI_API_KEY

Install

git clone https://github.com/your-org/travel-planning-agent
cd travel-planning-agent
pip install -r requirements.txt

Setup API Keys

Export in your shell (recommended):

export OPENAI_API_KEY="sk-..."
export SERPAPI_API_KEY="..."

Or create a .env file and source it in your shell before running:

source .env

Usage

1) Chat mode (interactive)

python travel_planning_agent.py

2) Single-query mode

python travel_planning_agent.py -q "Plan a 5-day luxury trip to Paris in July."

3) With debug logs

python travel_planning_agent.py -q "Find cheap flights to Tokyo in May" --debug

CLI Options

  • -q, --query : Initial travel query (if omitted → chat mode)
  • -m, --model : Model (default: gpt-4o, choices: gpt-4o, gpt-4o-mini)
  • -n, --topn : Number of results per search (default: 10)
  • -o, --outfile : Write full JSON trace to file
  • -d, --debug : Enable debug logs

Behavior

  • Interprets ambiguous dates as future travel:
    • If the current date is past a mentioned month (e.g., today is August and user says "in May"), assume next year's May.
    • For vague phrasing like "mid-May", probe multiple nearby dates (e.g., 13–17 May) rather than a single exact day.
  • Assumes reasonable defaults when details are missing (and surfaces them):
    • Economy cabin, up to 1 stop, 2 adults, flexible +/- 3 days; adjust if tone/budget suggests otherwise.
  • Infers defaults based on query tone:
    • "Luxury" → business/first flights, 5-star hotels
    • "$500 budget" → economy flights, value hotels
  • Asks clarifying questions if info missing (dates, origin, budget) and provides multiple options when uncertain
  • Outputs a concise, actionable plan with links & footnote-style citations

Tooling notes

  • Flights tool requires IATA airport codes:
    • The search_flights tool expects 3-letter IATA codes for departure and destination (e.g., WAW, HAM).
    • The agent should first call search_web to find/verify the IATA codes (e.g., search: "Warsaw IATA code", "Hamburg IATA code"), then call search_flights with those codes.
    • If non-IATA inputs are provided, the tool returns a structured error indicating that IATA codes are required.
  • Hotels and Places tools accept free-text destination queries (cities, neighborhoods) as before.

Project Structure

travel-planning-agent/
├─ travel_planning_agent.py # CLI entrypoint + TravelAgent class
├─ requirements.txt
├─ README.md
└─ LICENSE

Example Queries

  • Budget trip: I want a $500 budget trip to Mexico City in November
  • Discovery: I want a summer beach vacation
  • Luxury honeymoon: Plan a luxury honeymoon in Bali in December

About

Implementation of a Travel Planning Agent using SerpApi Search, Hotels, Flights API + OpenAI models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages