AI travel agent: proposed architecture
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
| Mode | Example | Runs 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_actionrow 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_errorto the model, so it can recover or explain instead of crashing.
Phases
- Tool calling in
llm/, the fake and Ollama providers, 3 read tools, the loop, tests - Chat endpoint (SSE), thread persistence, mobile chat screen
- Pending actions and the confirm flow; receipt photo to a proposed expense
- Places, weather and flights adapters plus the cache
- Trip memory with pgvector
- Background planner runs
- Tracing (Langfuse), evals, budgets, hosted model in staging
Open questions
- Does everyone on a trip share one assistant thread, or does each person get their own?
- Production model: Claude for tool-use quality, with Qwen3 via Ollama for local dev?
- v1 scope: search and recommend only, or real booking?
- Hand-rolled loop first, adding LangGraph only if planner runs need checkpointing?