Work / Case study 3 of 4 · research · grounded generation

Deep Research Agent

Turns a research question into a structured, cited report from the web and your own documents. It then checks every cited sentence against the stored source text and removes what it can't support.

  • LangGraph
  • Claude
  • Tavily
  • Chroma + fastembed
  • FastAPI + SSE
  • SQLite
  • React + TypeScript
Deep Research Agent
A finished report. Each citation chip jumps to its source and quote; a warning icon marks sentences the verifier kept but found only partly supported.
A finished report. Each citation chip jumps to its source and quote; a warning icon marks sentences the verifier kept but found only partly supported.

Engineering in 30 seconds

  • Plan → parallel research workers (Send) → reflect on gaps → write → verify → finalise
  • Grounded notes: a worker's note is dropped if its snippet is not literally in the stored source
  • Verifier: each cited sentence is judged against its notes. Unsupported sentences are rewritten once, then removed and listed under Limitations
  • Two model tiers: a strong model to plan, write and verify; a cheaper model for parallel workers
  • Eval suite: 19 questions (web, docs-only, mixed, 2 adversarial), LLM rubric judge, automated citation-validity check, A/B runner
  • Strict typing (mypy strict, tsc), Playwright smoke tests, fake LLMs for offline tests

Delivery in 30 seconds

  • Intended user: an analyst who needs a defensible, sourced brief, not a chat answer
  • Searches the web and the user's own uploaded files (PDF, DOCX, MD, TXT, HTML) in parallel; documents stay on the machine
  • Human checkpoint: Deep runs pause so the user can edit and approve the research plan
  • Budgets for rounds, searches, tokens and wall-clock time; hitting one moves to writing with a warning
  • Runs are checkpointed: a killed backend resumes; dropped connections replay via Last-Event-ID
  • Offline demo mode with scripted models: clickable without any API keys

Status, stated plainly: built, tested (pytest, vitest, Playwright) and runs locally. The eval suite is built, but its live results have not been published yet, so this page makes no quality claims.

The problem

“Research agents” are easy to build and hard to trust. They cite sources that don’t say what the sentence claims, they follow instructions hidden in web pages, and they run up cost with no ceiling. I wanted a report where every citation can be checked and the system says what it could not support.

Constraints

  • A citation must point at text that actually supports the sentence. Not just a URL from the same search.
  • Web content is untrusted input. Pages can contain instructions aimed at the model.
  • Bounded cost and time, visible to the user while the run is going.
  • Long runs must survive failures: a crash, a closed tab, a cancel.

What I built

  1. clarify
  2. plan
  3. approve plan
  4. research_worker ×N
  5. collect
  6. reflect (loop on gaps)
  7. write
  8. verify
  9. finalize
Calls an LLMDeterministic codeHuman decision
Workers search Tavily and the local Chroma index in parallel. Reflect either sends another round of workers or moves on to writing when the research is done or a budget is hit.

1. Two layers of grounding. Workers must return claim + verbatim snippet + source ID, and code drops any note whose snippet isn’t literally in the stored source. The verifier then judges each written sentence against its cited notes.

2. Defending against hostile content. Retrieved text is wrapped in delimiters and sanitised (hidden characters, instruction-like sentences, delimiter spoofing). Each finding is emitted as a warning event. Tools are read-only, and unsafe URLs (private IPs, non-http) are blocked.

3. Events as the source of truth. Every run emits typed, sequenced events that are persisted. A dropped connection resumes from the last event, a finished run replays exactly, and history comes for free.

Live progress view: phases, per-sub-question tool calls and sources, and a cost meter showing tokens, searches and time against budget.
Live progress, with the cost meter tracking tokens, searches and time against budget.

How it will be measured

19 questions: 7 web (some time-sensitive), 5 documents-only against a fixture corpus, 5 mixed, and 2 adversarial (a page with an injection, and an unanswerable question). Scoring uses an LLM rubric judge (coverage, accuracy, calibration), plus an automated citation-validity check. Targets: average coverage ≥ 4/5, citation validity ≥ 95%, zero injection compliance.

TODO: run the live eval, commit the report, and publish the table here: coverage, citation validity, injection compliance, cost per run, p50 time. Add a verifier-on vs verifier-off comparison. That comparison is this project’s strongest possible result.

Known limitations

  • Single-user and local: no auth and no cloud deployment yet.
  • The LLM judge shares a model family with the writer; a spot-check by hand is still needed.

What I’d do next

  1. Publish eval results, including the verifier ablation.
  2. Deploy the offline demo mode publicly, so anyone can click through without keys, and gate live runs.
  3. Add per-run cost to the exported report so a reader can see what a brief cost.

How it was built

State solo / AI-assisted honestly, and what you designed yourself (grounding rules, verifier, event model).

← All case studies