> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/Shubhamsaboo/awesome-llm-apps/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Travel Agent

> Build an intelligent travel planning agent that generates personalized itineraries with OpenAI GPT-4o

## 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

<CardGroup cols={2}>
  <Card title="Multi-Agent Architecture" icon="users">
    * **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
  </Card>

  <Card title="Smart Itinerary Generation" icon="route">
    * Customizable duration (1-30 days)
    * Personalized recommendations for activities, dining, and accommodations
    * Detailed day-by-day planning
  </Card>

  <Card title="Calendar Integration" icon="calendar">
    * Export itineraries as .ics calendar files
    * Compatible with Google Calendar, Apple Calendar, Outlook
    * Each day appears as an all-day event with full details
  </Card>

  <Card title="Flexible Deployment" icon="server">
    * Cloud version with OpenAI GPT-4o
    * Local version with Ollama for privacy
    * Web-based interface with Streamlit
  </Card>
</CardGroup>

## How It Works

<Steps>
  <Step title="User Input">
    Users specify their destination and travel duration (1-30 days)
  </Step>

  <Step title="Research Phase">
    The Researcher agent generates search terms and queries SerpAPI for:

    * Popular activities and attractions
    * Accommodation options
    * Dining recommendations
    * Local experiences
  </Step>

  <Step title="Planning Phase">
    The Planner agent synthesizes research into a comprehensive itinerary:

    * Day-by-day activity schedules
    * Restaurant suggestions
    * Accommodation recommendations
    * Practical travel tips
  </Step>

  <Step title="Calendar Export">
    Users can download the itinerary as a .ics file for seamless calendar integration
  </Step>
</Steps>

## Setup

<Steps>
  <Step title="Clone the Repository">
    ```bash theme={null}
    git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
    cd awesome-llm-apps/starter_ai_agents/ai_travel_agent
    ```
  </Step>

  <Step title="Install Dependencies">
    ```bash theme={null}
    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
  </Step>

  <Step title="Get API Keys">
    **OpenAI API Key:**

    * Sign up at [OpenAI Platform](https://platform.openai.com/)
    * Generate an API key from your dashboard

    **SerpAPI Key:**

    * Sign up at [SerpAPI](https://serpapi.com/)
    * Get your API key for web search functionality
  </Step>

  <Step title="Run the Application">
    **For cloud version (OpenAI GPT-4o):**

    ```bash theme={null}
    streamlit run travel_agent.py
    ```

    **For local version (Ollama):**

    ```bash theme={null}
    streamlit run local_travel_agent.py
    ```

    The app will open in your browser at `http://localhost:8501`
  </Step>
</Steps>

## 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:

<Steps>
  <Step title="Download">
    Click "Download Itinerary as Calendar (.ics)" button
  </Step>

  <Step title="Import">
    Open the .ics file with your calendar application:

    * **Google Calendar**: Import from Settings
    * **Apple Calendar**: Double-click to import
    * **Outlook**: File > Import
  </Step>

  <Step title="Sync">
    Your itinerary syncs across all devices where your calendar is connected
  </Step>
</Steps>

## Code Example

Here's the core agent configuration:

```python theme={null}
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:

```python theme={null}
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

<Tabs>
  <Tab title="Cloud (OpenAI)">
    **File**: `travel_agent.py`

    **Pros:**

    * 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
  </Tab>

  <Tab title="Local (Ollama)">
    **File**: `local_travel_agent.py`

    **Pros:**

    * Completely free to use
    * Full privacy - no data sent externally
    * No API rate limits

    **Cons:**

    * Requires Ollama installation
    * Limited by local hardware
    * May produce lower quality results

    **Use when**: Privacy is paramount or you want to avoid API costs
  </Tab>
</Tabs>

## Use Cases

<AccordionGroup>
  <Accordion title="Weekend Getaways" icon="calendar-days">
    Perfect for planning short 2-3 day trips with detailed hour-by-hour schedules
  </Accordion>

  <Accordion title="International Vacations" icon="earth-americas">
    Generate comprehensive multi-week itineraries with cultural experiences and must-see attractions
  </Accordion>

  <Accordion title="Business Travel" icon="briefcase">
    Combine meetings with leisure activities and local dining recommendations
  </Accordion>

  <Accordion title="Group Travel" icon="users">
    Plan activities suitable for families, friends, or corporate groups
  </Accordion>
</AccordionGroup>

## Tips for Best Results

<Warning>
  **API Key Security**: Never commit API keys to version control. Always use environment variables or Streamlit secrets in production.
</Warning>

<Tip>
  **Better Prompts**: Be specific about your preferences. Mention interests like "hiking", "museums", "food tours", or "nightlife" for more tailored recommendations.
</Tip>

<Info>
  **Calendar Sync**: After importing to your calendar, the itinerary is available offline on all synced devices, perfect for international travel without data.
</Info>

## Troubleshooting

<AccordionGroup>
  <Accordion title="SerpAPI Rate Limits">
    Free SerpAPI accounts have limited searches. Consider upgrading or spacing out requests if you hit limits.
  </Accordion>

  <Accordion title="Calendar Import Issues">
    Ensure your calendar app supports .ics files. Most modern calendar applications do, but some may require specific import steps.
  </Accordion>

  <Accordion title="Local Ollama Not Working">
    Make sure Ollama is installed and running. Test with `ollama list` to verify models are available.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Explore More Agents" icon="robot" href="/examples/ai-research-agent">
    Check out other AI agent examples
  </Card>

  <Card title="GitHub Repository" icon="github" href="https://github.com/Shubhamsaboo/awesome-llm-apps">
    View the complete source code
  </Card>
</CardGroup>
