01 The Problem
Movie databases like TMDB are exhaustive but rigid. They expose genre filters, release years, and ratings โ but they cannot interpret themes, compare filmographies, or synthesise critical perspective. A single LLM call lacks live data. A single API lacks semantic understanding. The only viable solution is decomposition: multiple specialised agents working in parallel, coordinated by an orchestrator.
02 System Architecture
User (browser) โ HTTPS โ CDN + TLS termination โ Nginx (reverse proxy, cloud VPS) โโโ / โ React frontend (static, port 5174) โโโ /api/* โ FastAPI backend (uvicorn, port 8001) โ โ Server-Sent Events stream โ LangGraph StateGraph โ understand โ rewrites a follow-up as a standalone question โ kb_lookup โ knowledge base first: calibrated relevance gate โ โโโโโโโโโโโโโดโโโโโโโโโโโโโ โ supervisor_route โ โ decides which agents to invoke โโโโฌโโโโโโโโโโโฌโโโโโโโฌโโโโ (RAG joins if the KB is relevant, skipped if not) โ โ โ (parallel fan-out; + music_agent โ MusicBrainz) tmdb_agent rag_agent search_agent TMDB API KB passages Tavily Web (httpx) :19530 API โ โ โ โโโโดโโโโโโโโโโโดโโโโโโโดโโโโ โ synthesise โ merges results, streams answer โ SSE โ browser (token by token)
Each layer has a single, clear responsibility. The understand step makes a follow-up self-contained. The knowledge-base lookup checks the curated corpus first. The supervisor decides routing. Agents specialise. The synthesiser integrates. The SSE stream makes the entire process visible to the user in real time.
03 Core Technologies
LangGraph โ Multi-Agent Orchestration
LangGraph models the AI pipeline as a directed graph. Each node is an async Python function (an agent); each edge is conditional routing logic. A shared StateGraph object carries conversation state between nodes, and MemorySaver checkpoints that state (in memory) so multi-turn conversation context persists across queries on the same thread. A follow-up such as "Who composed its score?" is rewritten into a standalone question ("Who composed the score for Inception (2010)?") by one small Claude call before any agent sees it; the final answer still sees the user's own words and the history.
Milvus โ Hybrid Vector Search
Milvus stores the movie knowledge corpus (critical essays, directorial analyses, genre guides). The RAG agent retrieves relevant passages using hybrid search: a fusion of two complementary retrieval methods ranked by Reciprocal Rank Fusion (RRF).
Anthropic Claude โ LLM Inference
Every LLM call โ follow-up rewriting, the knowledge-base grader, routing, per-agent intent extraction and final synthesis โ goes through a single factory, llm.py:get_chat(). The model is one server-wide cost tier (DEFAULT_MODEL_TIER: haiku ยท sonnet ยท opus, default haiku) that runs the newest model in that tier once it has passed the evals (quality against the baseline, and no rise in cost per question); until then the previous model stays live. Streaming the answer token by token is what makes the UI feel instant.
FastAPI + Server-Sent Events
The backend exposes a single streaming endpoint. It runs the LangGraph pipeline with astream_events() and translates internal events โ agent lifecycle, LLM tokens, retrieved chunks, TMDB results โ into a typed SSE stream consumed by the browser.
EventSource in the browser auto-reconnects on drop. WebSockets add bidirectional protocol overhead that is unnecessary here.React + TypeScript Frontend
The frontend is a Vite SPA that maintains a live EventSource connection per query. It is laid out as a chat, and every answer carries a step trace: the follow-up rewrite, the knowledge-base verdict and how it was decided, the routing, each source's result, the free lookups vs. Claude calls (purpose, tokens in/out), what the combiner received, any links the guardrail removed, and the model. Older turns fold to a one-line summary. An optional panel (โก) adds an animated pipeline graph, a Gantt timeline, a typed event log and a context panel; a ๐งช Evals & ops panel shows the eval tiers, scheduled jobs and ingest history. The AI process is visible, not a black box.
04 A Query, Step by Step
Tracing "Show me good bank heist movies" through the full stack:
Understand + knowledge-base lookup: a first question needs no rewrite (no LLM call); the question is embedded and searched in Milvus (hybrid BM25+dense), and the relevance gate decides whether the passages are useful. Then the supervisor calls Claude to classify intent โ routes to all three agents in parallel: tmdb + rag + search
TMDB agent calls Claude to extract intent (discover, genre: Crime/Thriller) โ queries TMDB API โ calls Claude to write a grounded answer citing specific films with ratings
RAG agent reuses the knowledge-base passages the gate kept (no second search) โ calls Claude to write a knowledge-based answer
Search agent sends the query to Tavily โ retrieves current web results โ calls Claude to ground the answer in recent criticism and best-of lists
Synthesiser receives all three outputs, calls Claude to merge them by question, not by source โ one list, overlapping films deduplicated, sources credited inline, disagreements noted where they occur
SSE stream delivers typed events to the browser as they occur: pipeline_start โ kb_lookup โ routing_decision โ agent_start โ token (รN) โ tmdb_results โ chunks_retrieved โ agent_end โ done
05 Technical Highlights
MemorySaver + thread_id keeps the conversation, and each follow-up is rewritten into a standalone question for the agents. "What about his other films?" works correctly without re-stating context.
movie_and_person intent type fetches movie detail and actor filmography in parallel, sorts by rating, and hands the ranked list to the synthesis LLM โ turning "is this their best film?" from a non-answer into a precise ranked response.
06 Full Stack Summary
| Layer | Technology | Role |
|---|---|---|
| Orchestration | LangGraph 1.1 | Multi-agent state machine with conditional routing and conversation memory |
| LLM inference | Anthropic Claude (haiku / sonnet / opus tier) | All reasoning: follow-up rewriting, relevance grading, routing, intent extraction, answer generation |
| Vector DB | Milvus 2.5 | Hybrid BM25 + dense search over the movie knowledge corpus |
| Embeddings | OpenAI text-embedding-3-small | 1536-dim dense vectors for semantic retrieval |
| Movie data | TMDB API | Real-time film/TV metadata, cast, ratings, trending, person filmography |
| Web search | Tavily API | Current web results as a third retrieval source |
| Backend | FastAPI + uvicorn | Async SSE streaming, typed event protocol |
| Frontend | React + TypeScript + Vite | Chat UI with per-answer step trace, optional pipeline visualisation, dark/light theme |
| Infrastructure | Docker Compose + Nginx + CDN | Containerised deployment, reverse proxy, SSL termination, CDN |