Skip to main content

Overview

The AI Travel Agent is a Streamlit-based application that automates the process of researching, planning, and organizing personalized travel itineraries. Using OpenAI’s GPT-4o and the Agno framework, it creates intelligent travel plans complete with activities, accommodations, and calendar integration.

Features

Multi-Agent Architecture

  • Researcher Agent: Generates search terms and finds relevant activities and accommodations using SerpAPI
  • Planner Agent: Creates personalized itineraries based on research results and user preferences

Smart Itinerary Generation

  • Customizable duration (1-30 days)
  • Personalized recommendations for activities, dining, and accommodations
  • Detailed day-by-day planning

Calendar Integration

  • Export itineraries as .ics calendar files
  • Compatible with Google Calendar, Apple Calendar, Outlook
  • Each day appears as an all-day event with full details

Flexible Deployment

  • Cloud version with OpenAI GPT-4o
  • Local version with Ollama for privacy
  • Web-based interface with Streamlit

How It Works

1

User Input

Users specify their destination and travel duration (1-30 days)
2

Research Phase

The Researcher agent generates search terms and queries SerpAPI for:
  • Popular activities and attractions
  • Accommodation options
  • Dining recommendations
  • Local experiences
3

Planning Phase

The Planner agent synthesizes research into a comprehensive itinerary:
  • Day-by-day activity schedules
  • Restaurant suggestions
  • Accommodation recommendations
  • Practical travel tips
4

Calendar Export

Users can download the itinerary as a .ics file for seamless calendar integration

Setup

1

Clone the Repository

git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
cd awesome-llm-apps/starter_ai_agents/ai_travel_agent
2

Install Dependencies

pip install -r requirements.txt
Required packages:
  • streamlit - Web interface
  • agno>=2.2.10 - Agent framework
  • openai - OpenAI API integration
  • google-search-results - SerpAPI for web search
  • icalendar - Calendar file generation
3

Get API Keys

OpenAI API Key:SerpAPI Key:
  • Sign up at SerpAPI
  • Get your API key for web search functionality
4

Run the Application

For cloud version (OpenAI GPT-4o):
streamlit run travel_agent.py
For local version (Ollama):
streamlit run local_travel_agent.py
The app will open in your browser at http://localhost:8501

Usage

Generating an Itinerary

  1. Enter API Keys: Input your OpenAI and SerpAPI keys in the sidebar
  2. Specify Destination: Enter where you want to travel
  3. Set Duration: Choose the number of days (1-30)
  4. Generate: Click “Generate Itinerary” to start the planning process
  5. Download: Export your itinerary as a calendar file

Calendar Integration

After generating your itinerary:
1

Download

Click “Download Itinerary as Calendar (.ics)” button
2

Import

Open the .ics file with your calendar application:
  • Google Calendar: Import from Settings
  • Apple Calendar: Double-click to import
  • Outlook: File > Import
3

Sync

Your itinerary syncs across all devices where your calendar is connected

Code Example

Here’s the core agent configuration:
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.serpapi import SerpApiTools

# Researcher Agent
researcher = Agent(
    name="Researcher",
    role="Searches for travel destinations, activities, and accommodations",
    model=OpenAIChat(id="gpt-4o", api_key=openai_api_key),
    description="""
    You are a world-class travel researcher. Given a travel destination 
    and duration, generate search terms for finding relevant activities 
    and accommodations, then analyze results.
    """,
    instructions=[
        "Generate 3 search terms related to the destination and duration",
        "Search Google for each term and analyze results",
        "Return the 10 most relevant results",
    ],
    tools=[SerpApiTools(api_key=serp_api_key)],
    add_datetime_to_context=True,
)

# Planner Agent
planner = Agent(
    name="Planner",
    role="Generates itineraries based on research and preferences",
    model=OpenAIChat(id="gpt-4o", api_key=openai_api_key),
    description="""
    You are a senior travel planner. Create detailed itineraries 
    that meet user needs and preferences.
    """,
    instructions=[
        "Generate a draft itinerary with activities and accommodations",
        "Ensure well-structured, informative, and engaging content",
        "Provide balanced recommendations with proper attribution",
    ],
    add_datetime_to_context=True,
)

# Generate itinerary
research_results = researcher.run(
    f"Research {destination} for a {num_days} day trip", 
    stream=False
)

prompt = f"""
Destination: {destination}
Duration: {num_days} days
Research Results: {research_results.content}

Please create a detailed itinerary based on this research.
"""

itinerary = planner.run(prompt, stream=False)

Calendar File Generation

The app includes a sophisticated calendar generation system:
from icalendar import Calendar, Event
from datetime import datetime, timedelta
import re

def generate_ics_content(plan_text: str, start_date: datetime = None) -> bytes:
    """Generate an ICS calendar file from a travel itinerary."""
    cal = Calendar()
    cal.add('prodid', '-//AI Travel Planner//github.com//')
    cal.add('version', '2.0')
    
    if start_date is None:
        start_date = datetime.today()
    
    # Parse itinerary by days
    day_pattern = re.compile(r'Day (\d+)[:\s]+(.*?)(?=Day \d+|$)', re.DOTALL)
    days = day_pattern.findall(plan_text)
    
    # Create events for each day
    for day_num, day_content in days:
        day_num = int(day_num)
        current_date = start_date + timedelta(days=day_num - 1)
        
        event = Event()
        event.add('summary', f"Day {day_num} Itinerary")
        event.add('description', day_content.strip())
        event.add('dtstart', current_date.date())
        event.add('dtend', current_date.date())
        event.add('dtstamp', datetime.now())
        cal.add_component(event)
    
    return cal.to_ical()

Local vs Cloud Version

File: travel_agent.pyPros:
  • High-quality itineraries with GPT-4o
  • Best performance and accuracy
  • No local setup required
Cons:
  • Requires OpenAI API key (paid)
  • Sends data to external APIs
Use when: You want the highest quality results and don’t mind API costs

Use Cases

Perfect for planning short 2-3 day trips with detailed hour-by-hour schedules
Generate comprehensive multi-week itineraries with cultural experiences and must-see attractions
Combine meetings with leisure activities and local dining recommendations
Plan activities suitable for families, friends, or corporate groups

Tips for Best Results

API Key Security: Never commit API keys to version control. Always use environment variables or Streamlit secrets in production.
Better Prompts: Be specific about your preferences. Mention interests like “hiking”, “museums”, “food tours”, or “nightlife” for more tailored recommendations.
Calendar Sync: After importing to your calendar, the itinerary is available offline on all synced devices, perfect for international travel without data.

Troubleshooting

Free SerpAPI accounts have limited searches. Consider upgrading or spacing out requests if you hit limits.
Ensure your calendar app supports .ics files. Most modern calendar applications do, but some may require specific import steps.
Make sure Ollama is installed and running. Test with ollama list to verify models are available.

Next Steps

Explore More Agents

Check out other AI agent examples

GitHub Repository

View the complete source code

Build docs developers (and LLMs) love