LearnSystem design

Deep-research agent with cited reports

Design an agent that takes a research question, searches the web and internal documents, and produces a cited multi-page report within ten minutes.

Applied LLM8 parts

Contents

What to cover

Sketch your own design first. A complete answer has these parts; the notes say what each should settle.

  1. Requirementssources allowed; freshness; depth vs time budget; cost per report; how users judge quality; safety (untrusted web content)
  2. Estimates
  3. API
  4. Data model
  5. Architectureplanner that decomposes into sub-questions; parallel sub-agents with search/fetch tools and own context; source quality scoring and dedup; notes store with citations; synthesis/writer; citation verification; budget manager (time, tokens, tool calls); streaming progress to user; eval with expert-graded reports and claim-level citation checks
  6. Deep divesa fetched page contains injected instructions — what happens?; How do you grade a 10-page report automatically?
  7. Trade-offsbreadth (more sub-agents) vs cost and coordination; depth of reading vs latency; single writer vs section writers
  8. Evaluationclear budgets and stopping; context isolation; citation verification; injection handling for web content; evaluation strategy beyond vibes

Reference design

One way to answer it, part by part. Open a part once you have your own version of it.

Requirements

Functional: accept a research question (with optional clarifying exchange), search the web and permitted internal documents, read sources, and deliver a structured multi-page report with inline citations to exact passages, within ten minutes, streaming progress throughout.

Assumptions to confirm

  • Sources allowed: public web via a search API and our own fetcher (respecting robots and terms; no paywall circumvention); internal collections through a permission-aware search tool; user uploads.
  • Freshness: news-sensitive questions need sources from the last few hours; every citation shows its publication and access date.
  • Depth vs time budget: quick (~3 minutes), standard (~7 minutes), deep (hard cap 10 minutes); the agent stops at the budget and says what it did not cover.
  • Cost per report: target ≤ $2 at standard depth.
  • How users judge quality: correctness, coverage of the important angles, trustworthy citations, synthesis rather than a list of summaries, clear structure.
  • Safety: web content is untrusted (prompt injection, SEO spam, misinformation); the agent only reads — it never sends messages, submits forms or writes anywhere except the report; internal data must not leak into web requests.
  • Volume: ~10k reports/day, peaking at ~2k/hour.

Estimates

Flow · 4 stepsStandard time budget for a report

Standard time budget for a reportA horizontal timeline shows the standard budget: a 30 s plan, 5 min of parallel research, a 1.5 min section-drafting lane with citation verification running inside it, a 30 s editor pass, and ~1.5 min of slack for slow fetches and retries. The verification lane is fed by note quotes from research and checks drafted claims as each section lands, so it does not add serial time. The final box marks p95 under 10 minutes.Plan30 sParallel research5 minSection drafting1.5 minCitation verification1 min, checks draftedclaims as sections landEditor pass30 sSlack and p95~1.5 min slack; p95 under 10 minnote quotes1234PlanResearchDraft and verifyFinish
  1. Plan The planner scopes the question and outlines the report in 30 s.
  2. Research Parallel sub-agents search and fetch for 5 min.
  3. Draft and verify Sections are drafted over 1.5 min; citation verification (1 min) runs inside that window as sections land, so it adds no time.
  4. Editor and slack The editor pass takes 30 s; ~1.5 min slack covers slow fetches and retries, keeping p95 under 10 minutes.

The standard budget runs plan, parallel research, overlapping drafting and verification, an editor pass, then slack, keeping p95 under 10 minutes.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1PlanThe planner scopes the question and outlines the report in 30 s.
2ResearchParallel sub-agents search and fetch for 5 min.
3Draft and verifySections are drafted over 1.5 min; citation verification (1 min) runs inside that window as sections land, so it adds no time.
4Editor and slackThe editor pass takes 30 s; ~1.5 min slack covers slow fetches and retries, keeping p95 under 10 minutes.

Source: This page's text

Boxes
BoxGroupDetail
PlanPlan30 s
Parallel researchResearch5 min
Section draftingDraft and verify1.5 min
Citation verificationDraft and verify1 min, checks drafted claims as sections land
Editor passFinish30 s
Slack and p95Finish~1.5 min slack; p95 under 10 min

Source: This page's text

  • Concurrency: 2k reports/h ÷ 60 × 8 min ≈ 270 reports in flight, × 6 sub-agents ≈ 1,600 concurrent sub-agents.
  • Tool traffic: ~40 searches and ~60 fetches per report over ~6 minutes of research → 270 × 60 / 360 s ≈ 45 fetches/s and ~30 searches/s at peak.
  • Tokens per report:
    • sub-agents (cheaper model, ~$0.5/M in, $2/M out): 6 × ~130k input ≈ 800k → $0.40; 30k output → $0.06;
    • planner and writer (strong model, $3/M in, $15/M out): ~70k input → $0.21; ~8k output → $0.12;
    • citation verification (cheaper judge model): ~150 claims × 2k tokens = 300k → $0.15;
    • search API: 40 × an assumed ~$0.005 per query = $0.20.
    • ≈ $1.15 per report, ~$11.5k/day at 10k reports.
  • Time budget (standard): plan 30 s → parallel research 5 min → section drafting 1.5 min → verification 1 min (overlapping drafting) → editor pass 30 s; ~1.5 min slack for slow fetches and retries → p95 under 10 minutes.
  • Storage: ~60 fetched sources × ~50 KB extracted text = 3 MB per report → 30 GB/day; cached by URL and content hash for 24 hours and shared across reports.

API

POST /v1/research   {question, sources: {web: true, internal: ["policies", "market-notes"]},
                     depth: "quick"|"standard"|"deep", budget: {minutes: 10, usd: 2},
                     format: "report"|"brief", clarify: true}
                    → {report_id} | {clarifying_questions: [...]}
GET  /v1/research/{id}/events      (SSE)
     plan {sub_questions[]} · subtask_started {id, query} · source_found {title, url}
     · progress {pct, eta_s} · section_drafted {title} · done {report_id}
GET  /v1/research/{id}  → {markdown, citations: [{n, url | doc_id, title, quote, published_at,
                           accessed_at}], claims: [{text, citations[], verified}], cost, coverage_notes}
POST /v1/research/{id}/feedback {rating, issues: ["wrong_fact", "bad_citation", "missing_angle"]}
POST /v1/research/{id}/cancel

Runs are server-side jobs: if the client disconnects, the SSE stream replays from Last-Event-ID, and the report is still delivered. Internal collections are searched with the caller’s identity, so citations never include documents the user cannot open.

Data model

  • Report: id, user, question, depth, budget and spend (time, tokens, tool calls, $), status, plan, final markdown, coverage notes.
  • SubQuestion: id, report_id, text, status, assigned agent, budget share, findings summary.
  • Source: canonical URL or doc_id, content hash, fetched_at, published_at, domain, type (primary, news, blog, forum, internal), quality score, injection flag, extracted text pointer.
  • Note: id, sub_question, claim text, verbatim quote with character offsets, source_id, confidence. Notes are the only channel from research to writing.
  • Section: outline position, draft text, note ids used.
  • Claim: sentence in the report, cited note ids, verification verdict (supported | partial | unsupported), action taken.
  • Trace: every model call and tool call with inputs, outputs, tokens and latency.

Postgres for reports and notes; object storage for fetched pages; a shared fetch cache; ClickHouse for traces.

Architecture

Flow · 5 stepsHow the deep-research agent runs

How the deep-research agent runsThe figure shows the reference architecture as a left-to-right flow. A user question enters through the API, the orchestrator and budget manager hand it to the planner, and parallel sub-agents search, fetch, extract and write structured notes. Notes feed a gap check, parallel section writing, claim-level citation verification and an editor pass that produces the report.Userresearch questionAPIPOST /v1/researchOrchestrator + budgetwall clock, tokens, tool calls, $Plannerscope, sub-questions, outlineSub-agents in parallelisolated contexts, read toolsNotes storeclaims with quotes and source idsGap checkmissing angles, spawn moreWritersections in parallel, inline [n]Citation verifierclaim vs quoted spanEditor passcoherence, executive summaryReport + bibliographymarkdown, citations, claimssub-questionsclaim + quotenotes only12345InputPlan and researchWrite and verify
  1. Plan The API hands the question to the orchestrator and budget manager; the planner scopes sub-questions and the report outline.
  2. Research Parallel sub-agents search web and internal sources, fetch and extract, score and classify, then write structured notes.
  3. Gap check The planner checks for missing angles and spawns more subtasks only while budget remains.
  4. Write Sections are drafted in parallel from notes only, with inline [n] citations.
  5. Verify and edit Claims are checked against quoted spans, then an editor pass adds coherence, executive summary and limitations.

A research question flows from the API through planning, parallel sub-agent research, a notes store, gap checking, parallel writing, citation verification and an editor pass.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1PlanThe API hands the question to the orchestrator and budget manager; the planner scopes sub-questions and the report outline.
2ResearchParallel sub-agents search web and internal sources, fetch and extract, score and classify, then write structured notes.
3Gap checkThe planner checks for missing angles and spawns more subtasks only while budget remains.
4WriteSections are drafted in parallel from notes only, with inline [n] citations.
5Verify and editClaims are checked against quoted spans, then an editor pass adds coherence, executive summary and limitations.

Source: This page's text

Boxes
BoxGroupDetail
UserInputresearch question
APIInputPOST /v1/research
Orchestrator + budgetPlan and researchwall clock, tokens, tool calls, $
PlannerPlan and researchscope, sub-questions, outline
Sub-agents in parallelPlan and researchisolated contexts, read tools
Notes storePlan and researchclaims with quotes and source ids
Gap checkPlan and researchmissing angles, spawn more
WriterWrite and verifysections in parallel, inline [n]
Citation verifierWrite and verifyclaim vs quoted span
Editor passWrite and verifycoherence, executive summary
Report + bibliographyWrite and verifymarkdown, citations, claims

Source: This page's text

User ─► API ─► Orchestrator + Budget manager (wall clock, tokens, tool calls, $)
   ─► Planner (strong model): scope, sub-questions (4–8), report outline
   ─► Sub-agents in parallel (cheaper model, isolated contexts):
         search(web | internal) ─► fetch ─► extract ─► write Notes (claim + quote)
         ├─ Fetch service: sandboxed headless browser, HTML→text, strips hidden
         │  text and scripts, size caps, robots, shared cache, SSRF protection
         ├─ Source scorer: domain reputation, primary vs secondary, recency,
         │  near-duplicate removal (MinHash), syndicated-copy detection
         └─ Injection classifier on fetched text → flag / down-weight
   ─► Notes store (claims with quotes and source ids)
   ─► Gap check (planner): missing angles → spawn more subtasks if budget allows
   ─► Writer: sections drafted in parallel from notes only, inline [n]
   ─► Citation verifier: claim vs quoted span → keep / rewrite / drop
   ─► Editor pass: coherence, contradictions, executive summary, limitations
   ─► Report + bibliography; progress streamed over SSE throughout

Deep dives

Flow · 4 stepsHow fetched pages are handled against injection

How fetched pages are handled against injectionA flow from the sub-agent's read-only tools and fetch service to a fetched page, then extraction, an injection classifier, the notes store and the writer. The main defence is capability limits: no email, form or write action, internal-read sub-agents lose web fetch, and fetch refuses URLs built from internal content and private IP ranges.Sub-agent toolsread-only: search, fetch, internalsearchFetched pageuntrusted; may carry injectedinstructionsExtractionstrips hidden text and scriptsInjection classifierflags injection patternsNotes storeclaim + verbatim quoteWriternotes onlyfetchextracttextflag / down-weightstructured notes1234ReadFilterHand-off
  1. Capability limits Capability limits carry the defence: read-only tools (search, fetch, internal search); no email, form or write action. Internal-read sub-agents lose web fetch.
  2. Untrusted text Fetched text enters context inside clear delimiters marked as untrusted; the extraction step strips hidden text and scripts.
  3. Classifier A classifier flags injection patterns; flagged sources are down-weighted, quoted only if essential and logged.
  4. Notes hand-off Research flows to the writer only as structured notes (claim plus verbatim quote), so imperatives in a page do not become instructions to the writer.

Fetched pages are treated as untrusted: read-only tools, extraction, classification and structured notes keep injected instructions from reaching the writer.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1Capability limitsCapability limits carry the defence: read-only tools (search, fetch, internal search); no email, form or write action. Internal-read sub-agents lose web fetch.
2Untrusted textFetched text enters context inside clear delimiters marked as untrusted; the extraction step strips hidden text and scripts.
3ClassifierA classifier flags injection patterns; flagged sources are down-weighted, quoted only if essential and logged.
4Notes hand-offResearch flows to the writer only as structured notes (claim plus verbatim quote), so imperatives in a page do not become instructions to the writer.

Source: This page's text

Boxes
BoxGroupDetail
Sub-agent toolsReadread-only: search, fetch, internal search
Fetched pageReaduntrusted; may carry injected instructions
ExtractionFilterstrips hidden text and scripts
Injection classifierFilterflags injection patterns
Notes storeHand-offclaim + verbatim quote
WriterHand-offnotes only

Source: This page's text

Flow · 4 stepsHow a report is graded automatically

How a report is graded automaticallyA report flows into four parallel grading paths: atomic claims checked against cited passages by an entailment judge, key-point recall scored against an expert rubric, accuracy checked on verifiable answers, and structure and usefulness scored by a rubric judge plus pairwise preference. All four feed a calibration step against about 50 expert-graded reports per release, ending in scores with confidence intervals.Report10-page reportKey-points rubricexpert rubric per questionAtomicclaimsextractclaimsAccuracycheckverifiableanswersStructurejudgerubric +pairwisepreferenceCoveragejudgerecall ofkeypointsEntailment judgeclaim vs cited passageCalibration~50 expert-graded reports perreleaseScoreswith confidence intervals1234InputGradingCalibration
  1. Check citations Extract atomic claims and check each against its cited passage with an entailment judge, targeting at least 95% supported.
  2. Score coverage A judge scores recall of the expert key-points rubric for the benchmark question.
  3. Check accuracy and structure Accuracy is checked on verifiable answers; structure and usefulness are scored by a rubric judge plus pairwise preference.
  4. Calibrate and report Every judge is calibrated against about 50 expert-graded reports per release, and scores are reported with confidence intervals.

A report is decomposed into citation precision, key-point coverage, accuracy and structure checks, then calibrated against expert labels before scores are reported.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1Check citationsExtract atomic claims and check each against its cited passage with an entailment judge, targeting at least 95% supported.
2Score coverageA judge scores recall of the expert key-points rubric for the benchmark question.
3Check accuracy and structureAccuracy is checked on verifiable answers; structure and usefulness are scored by a rubric judge plus pairwise preference.
4Calibrate and reportEvery judge is calibrated against about 50 expert-graded reports per release, and scores are reported with confidence intervals.

Source: This page's text

Boxes
BoxGroupDetail
ReportInput10-page report
Atomic claimsGradingextract claims
Entailment judgeGradingclaim vs cited passage
Key-points rubricGradingexpert rubric per question
Coverage judgeGradingrecall of key points
Accuracy checkGradingverifiable answers
Structure judgeGradingrubric + pairwise preference
CalibrationCalibration~50 expert-graded reports per release
ScoresCalibrationwith confidence intervals

Source: This page's text

A fetched page contains injected instructions. Capability limits carry the defence: sub-agents only have read tools (search, fetch, internal search), so there is no email, form or write action to hijack. Fetched text enters context inside clear delimiters marked as untrusted, and the extraction step strips hidden text. A classifier flags injection patterns; flagged sources are down-weighted, quoted only if essential and logged. Research flows to the writer only as structured notes (claim plus verbatim quote), so imperatives in a page do not become instructions to the writer. To stop exfiltration, a sub-agent that has read internal documents loses web fetch, and fetch refuses URLs built from internal content; the fetcher blocks private IP ranges.

Grading a 10-page report automatically. Decompose. (1) Citation precision: extract atomic claims and check each against its cited passage with an entailment judge — target ≥ 95% supported. (2) Coverage: experts write a key-points rubric per benchmark question; a judge scores recall of key points. (3) Accuracy: questions with verifiable answers. (4) Structure and usefulness: rubric-based judge plus pairwise preference against the previous version. Calibrate every judge against ~50 expert-graded reports per release and report scores with confidence intervals.

Trade-offs

  • Breadth (more sub-agents) vs cost and coordination: more sub-agents cover more angles but duplicate searches and overload synthesis; start with 4–8, let the gap check spawn more only when budget remains, and dedupe sources globally.
  • Depth of reading vs latency: skimming many pages finds breadth, reading a few primary sources fully finds substance; extract and score first, then read in full only the top sources per sub-question.
  • Single writer vs section writers: one writer is coherent but slow and strains its context on long reports; section writers in parallel are faster but repeat and contradict each other. Use a shared outline, parallel section drafting, then one editor pass for consistency.
  • Cheaper sub-agent model vs quality: research tasks tolerate a cheaper model; planning and writing get the strong model, and claim verification uses a cheaper judge only after it is calibrated against expert labels (on the strong model it would add ~$0.75 per report).

Evaluation

  • Clear budgets and stopping: per-report budget manager enforcing time, tokens and tool calls; budget-overrun rate and p95 completion time monitored; reports state what was not covered when the budget ran out.
  • Context isolation: sub-agents with separate contexts and structured notes as the only hand-off; verified in tests by planting injected pages in a sandboxed web corpus.
  • Citation verification: claim-level support rate, unsupported-claim rate shown to users and tracked per release.
  • Injection handling: red-team corpus of malicious pages (hidden text, instructions in alt text, exfiltration URLs) run in CI; zero tool misuse allowed.
  • Beyond vibes: benchmark of ~200 questions across domains with expert rubrics; per-dimension scores with CIs; pairwise preference vs incumbent; latency and cost per report.
  • Online: ratings and issue tags, follow-up question rate, export and share rate, abandonment mid-run, citation click-through; sampled reports reviewed weekly by experts and failures added to the benchmark.

What a strong design shows

  • Has an explicit budget manager (time, tokens, tool calls, money) with graceful stopping and honest coverage notes.
  • Isolates sub-agent contexts and passes only structured, quoted notes to the writer.
  • Verifies citations claim by claim before the report ships.
  • Defends against injection through capabilities (read-only tools, no exfiltration path), not just prompt wording.
  • Evaluates with decomposed, calibrated graders (citation precision, key-point coverage, accuracy, preference) instead of overall impressions.

Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.