Skip to content

About

AI travel assistant for US hotels: LangGraph agent (Gemini) with review-grounded RAG over pgvector, an Airflow ETL, FastAPI streaming API, and a Streamlit chat UI.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

🏨 Travel Mitra

CI

An AI-powered travel assistant for US hotels. Chat with it to find hotels by location, price, and rating; browse results as cards; pick one and ask what guests actually say about it β€” answered from real reviews via hybrid (vector + metadata) retrieval.

Built as a production-grade MVP with three subsystems:

  1. ETL pipeline (Apache Airflow) β€” populates a single Postgres + pgvector DB from public data sources.
  2. LangGraph agent (Gemini) β€” constrained, typed tools + RAG over reviews, with durable conversation state.
  3. FastAPI + Streamlit β€” streaming chat API and a step-by-step chat UI.

✨ Features

  • Conversational hotel search β€” "hotels in NYC under $300, 4+ stars" β†’ ranked results.
  • Dynamic slot-filling β€” asks for a location when it's missing; applies price/rating filters when given.
  • Pick & drill in β€” select a hotel and ask follow-ups ("is it quiet?", "good for families?"); context persists across turns.
  • Review-grounded answers β€” sentiment/aspect Q&A from real guest reviews (hybrid pgvector search), never fabricated.
  • Step-by-step chat UX β€” the agent emits messages as actions (say / show_hotels); the UI streams a loader β†’ cards carousel β†’ answer.
  • Production-grade ETL β€” idempotent upserts, raw-payload staging, a monthly API-budget guardrail, and runtime-configurable params.
  • Observability β€” LangSmith tracing of every tool call and token.

πŸ—οΈ Architecture

                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚  Streamlit UI  (:8501)         β”‚  chat, hotel-card carousel
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚ SSE
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚  FastAPI  (:8000)  /chat /healthβ”‚
                β”‚   └─ LangGraph ReAct agent      β”‚  gemini-2.5-flash
                β”‚        tools: search_locations, β”‚
                β”‚        search_hotels, get_hotel_β”‚
                β”‚        details, search_reviews, β”‚
                β”‚        say, show_hotels         β”‚
                β”‚   └─ Postgres checkpointer       β”‚  durable per-thread state
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚ psycopg3
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚  PostgreSQL 16 + pgvector       β”‚  cities, locations, hotels,
                β”‚  (data DB, host :5433)          β”‚  reviews, review_embeddings
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–²β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚ idempotent upserts
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚  Airflow 3 DAG `travel_mitra_etl`β”‚
                β”‚  load_cities β†’ resolve_locations β”‚
                β”‚  β†’ fetch_hotels β†’ fetch_reviews  β”‚
                β”‚  β†’ embed_reviews                 β”‚
                β”‚  (UI :8080, own metadata DB)     β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data flow

  • simplemaps CSV β†’ cities (no API).
  • TripAdvisor Content API (category=geos) β†’ locations (city β†’ geo id), and /reviews β†’ review text.
  • Xotelo API (free) β†’ hotels per location (price range, rating, mentions, image, URL).
  • Gemini gemini-embedding-001 (768-dim) β†’ review_embeddings for hybrid RAG.

🧰 Tech stack

Layer Tech
UI Streamlit
API FastAPI + SSE (sse-starlette)
Agent LangGraph (prebuilt ReAct) + langchain-google-genai (gemini-2.5-flash)
Conversation state langgraph-checkpoint-postgres (AsyncPostgresSaver)
Embeddings Gemini gemini-embedding-001 (768-dim, via REST)
Data layer psycopg3 + pgvector (no ORM β€” "code owns the SQL")
DB PostgreSQL 16 + pgvector
ETL Apache Airflow 3 (LocalExecutor)
Observability LangSmith
Infra Docker Compose

πŸ“ Repository layout

Travel-mitra-2.0/
β”œβ”€ docker-compose.yml          # full stack: postgres x2, airflow x4, api, ui
β”œβ”€ .env.example                # required secrets/config
β”œβ”€ requirements-api.txt        # API image deps
β”œβ”€ requirements-ui.txt         # UI image deps
β”œβ”€ requirements-agent.txt      # local venv (notebook + api + ui)
β”œβ”€ db/migrations/              # 0001_init, 0002_api_tables, 0003_embedding_model (auto-applied)
β”œβ”€ data/                       # simplemaps uscities CSV (seed)
β”œβ”€ etl/                        # ETL package (sources, transforms, load, embed, budget)
β”œβ”€ airflow/
β”‚  β”œβ”€ Dockerfile               # Airflow 3 + ETL deps
β”‚  └─ dags/travel_mitra_dag.py # the staged, idempotent DAG
β”œβ”€ agent/                      # LangGraph agent (tools, queries, graph, prompts, llm)
β”œβ”€ app/                        # FastAPI app (main, runtime, schemas) + Dockerfile
β”œβ”€ ui/                         # Streamlit app + Dockerfile
└─ notebooks/01_agent_prototype.ipynb

πŸš€ Quickstart (Docker)

Prerequisites

  • Docker + Docker Compose
  • A Gemini API key (https://aistudio.google.com/apikey)
  • A TripAdvisor Content API key (only needed to run the ETL; the demo works on already-loaded data)

1. Configure secrets

cp .env.example .env

Fill in .env:

GEMINI_API_KEY=your_gemini_key
TRIPADVISOR_API_KEY=your_tripadvisor_key      # for ETL only
TRIPADVISOR_REFERER=https://your-allowlisted-domain.com   # must match the key's domain restriction
# Optional tracing:
LANGSMITH_TRACING=false
LANGSMITH_API_KEY=

A Fernet key and an Airflow JWT secret are pre-filled for local dev β€” rotate for anything non-local.

2. Initialize Airflow (first run only)

docker compose up airflow-init

3. Bring up the stack

docker compose up -d
docker compose ps
Service URL Notes
Chat UI http://localhost:8501 Streamlit
Chat API http://localhost:8000/health FastAPI
Airflow http://localhost:8080 admin / admin
Data DB localhost:5433 app / app / travelmitra

The data DB schema auto-applies on first volume init (via docker-entrypoint-initdb.d).


πŸ›’οΈ Running the ETL

  1. Open Airflow at http://localhost:8080.
  2. Enable & trigger travel_mitra_etl (β–Ά Trigger DAG w/ config).
  3. Tune runtime params (all defaulted) β€” e.g. start small:
    • top_n_cities = 5
    • review_hotels_per_location = 20

Stages: load_cities β†’ resolve_locations β†’ fetch_hotels β†’ fetch_reviews β†’ embed_reviews.

Everything is idempotent (ON CONFLICT upserts) and budget-aware (a monthly TripAdvisor call cap, tracked in api_call_log) β€” re-running never duplicates rows or re-spends API calls.

The free TripAdvisor reviews endpoint returns ~5 reviews/hotel; reviews are fetched for a price-stratified top-K per city to keep coverage across budget/mid/luxury tiers.


πŸ’¬ Using the chat

Open http://localhost:8501 and try:

  • "Hotels in New York under $300, 4+ stars" β†’ a lead-in + a scrollable card carousel.
  • Click πŸ’¬ Ask on a card (or "tell me about the second one") β†’ drills into that hotel.
  • "Is it quiet and good for families?" β†’ a review-grounded answer.
  • Use the sidebar to start a New chat or switch between previous conversations (each keeps its own context).

πŸ§‘β€πŸ’» Local development (agent / notebook)

Run the agent or notebook against the containerized DB without rebuilding images:

python -m venv .venv
.venv/Scripts/activate        # Windows;  source .venv/bin/activate on macOS/Linux
pip install -r requirements-agent.txt

# Notebook prototype
jupyter notebook notebooks/01_agent_prototype.ipynb

# Or run the API locally (DB at localhost:5433)
uvicorn app.main:app --reload --port 8000

# Or the UI locally
streamlit run ui/streamlit_app.py

The agent reads DATABASE_URL (default localhost:5433 on the host) and GEMINI_API_KEY from the environment / .env.


βš™οΈ Configuration

Variable Used by Purpose
GEMINI_API_KEY agent, ETL embed Gemini LLM + embeddings
TRIPADVISOR_API_KEY ETL locations + reviews
TRIPADVISOR_REFERER ETL must match the key's domain allowlist (sent as Referer)
DATABASE_URL agent/API data DB DSN (psycopg3)
AGENT_MODEL agent defaults to gemini-2.5-flash
LANGSMITH_* agent/ETL optional tracing
TRIPADVISOR_MONTHLY_BUDGET ETL (Airflow Variable) hard call cap (default 4500)

ETL operational knobs (top_n_cities, review_hotels_per_location, price tiers, …) are DAG params, overridable per run with sensible defaults.


🧭 Key design decisions

  • Constrained, typed tools β€” not a free-form SQL agent. The LLM picks a tool and fills args; our code owns the SQL. Safe, deterministic, testable.
  • psycopg3, no ORM. Hybrid vector+metadata queries are clean in raw SQL; same driver as the LangGraph checkpointer.
  • Hybrid review search. review_embeddings denormalizes location_id / city_id / price / hotel_rating / accommodation_type, so vector similarity + structured filters run in one query.
  • "Talking is an action." The agent communicates only via say() / show_hotels(), emitting messages step by step and stopping at success β€” the app renders each as its own bubble.
  • Embedding model tracked per row (review_embeddings.model) so a model change can re-embed only stale rows.

πŸ—ΊοΈ Roadmap

  • Live date-based pricing via Xotelo /rates (an estimate_stay tool β€” schema already supports it).
  • Evals (golden Q&A: tool-selection accuracy + answer relevance).
  • Test suite (pytest, unit + integration) toward 80% coverage.
  • Containerized UI live-reload / CI.

πŸ“ Notes

  • US hotels only, for the cities loaded into the catalog. No booking, availability, or date-specific pricing in v1.
  • Secrets live in .env (gitignored). Never commit real keys; rotate anything exposed.

πŸ“„ License

MIT

About

AI travel assistant for US hotels: LangGraph agent (Gemini) with review-grounded RAG over pgvector, an Airflow ETL, FastAPI streaming API, and a Streamlit chat UI.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages