Skip to main content

AI travel agent: proposed architecture

Status: proposal

Nothing on this page is built yet. The open questions at the bottom need answers before Phase 1 starts.

The agent is a domain inside the FastAPI backend, not a separate service. It shares the same database, settings and (later) background worker.

Key rule: tools call services​

Tools are thin wrappers over the same domain services the API uses, so the agent gets the same validation and per-trip authorization. trip_id and user_id come from the request's AgentContext, never from the model's arguments, so the model cannot be talked into touching another trip.

Two ways to run it​

ModeExampleRuns as
Chat turn"Add dinner Friday 8pm"API request streaming SSE; about 8 tool steps and 60s at most
Planner run"Plan 4 days in Lisbon under €800"Background job; progress over Postgres LISTEN/NOTIFY, push notification when done

The agent proposes, the user confirms​

  • Read tools run freely: get_trip, list_itinerary, list_expenses, search_places, get_weather, search_trip_memory.
  • Write tools create a pending_action row instead of writing, and the app shows it as a confirm card. Confirming calls the normal API endpoint with an idempotency key.

Planned tables​

agent_threads, agent_messages, agent_runs (model, prompt version, tokens, cost), pending_actions, trip_memory_chunks (pgvector embeddings, filtered by trip_id), and external_cache (a Postgres TTL cache, instead of adding Redis).

Guardrails​

  • Model choice, token budgets per user and per trip, and step limits live in a DB settings table, so they can change without a redeploy.
  • Text returned by tools is passed to the model as data, never as instructions (prompt-injection defence).
  • A failed tool returns is_error to the model, so it can recover or explain instead of crashing.

Phases​

  1. Tool calling in llm/, the fake and Ollama providers, 3 read tools, the loop, tests
  2. Chat endpoint (SSE), thread persistence, mobile chat screen
  3. Pending actions and the confirm flow; receipt photo to a proposed expense
  4. Places, weather and flights adapters plus the cache
  5. Trip memory with pgvector
  6. Background planner runs
  7. Tracing (Langfuse), evals, budgets, hosted model in staging

Open questions​

  1. Does everyone on a trip share one assistant thread, or does each person get their own?
  2. Production model: Claude for tool-use quality, with Qwen3 via Ollama for local dev?
  3. v1 scope: search and recommend only, or real booking?
  4. Hand-rolled loop first, adding LangGraph only if planner runs need checkpointing?