Suryanand/ Bootcamp
suryanand.com ↗Let's talk
← AI system designAI guideAdvanced#system-design#agents#multi-agent#research
Frame · ai-engineering / case-studies / 12-deep-research-agent.mdGuide 103 / 103

Design a deep-research agent

"Deep research" products (from OpenAI, Google, Anthropic, Perplexity and others) take a question, spend several minutes searching and reading, and return a long report with citations. Unlike an answer engine, which does one quick retrieval pass, a research agent runs an open-ended loop: plan, search, read, notice gaps, search again, and finally synthesize. Anthropic's engineering post on their multi-agent research system is the best public reference I know, and I'll borrow its core shape: a lead agent that plans and delegates to parallel subagents, plus a separate citation step.

Requirements

Functional

  • User submits a research question; the agent may ask one or two clarifying questions first.
  • The agent searches the web and optionally private sources (connected drives, internal docs), reads pages and PDFs, and iterates.
  • Output: a structured report with sections, inline citations, and a source list.
  • Progress is visible while running (plan, current activity, sources found); the user can cancel.

Non-functional

  • Runs take minutes, sometimes tens of minutes; they must survive worker restarts.
  • Bounded cost per run (tokens, searches, page fetches) by plan tier.
  • Citation accuracy: claims must be supported by the cited source.
  • Safety: fetched content is untrusted; the agent has read-only tools.

Scale estimates (assumptions)

QuantityAssumptionResult
Research runs per day200,000
Average run length6 minutesabout 830 concurrent runs on average, 3x at peak
Subagents per run4 average
Searches per run408M searches/day
Pages read per run6012M page fetches/day
Tokens per run500,000 total across agents100B tokens/day

Anthropic reports multi-agent research uses many times more tokens than ordinary chat, roughly 15x in their measurement. That is the dominating cost, so budgets and model choice per role matter more than anything else.

High-level architecture

Rendering diagram…

Request flow

Rendering diagram…

Components

ComponentResponsibilityNotes
Research APICreate runs, stream progress, cancelReturns a run id immediately; work is async
Durable workflow engineCheckpoint each step, resume after failures, enforce timeoutsTemporal, Inngest, or a queue with persisted state
Lead agentClarify, plan, delegate, judge completeness, decide when to stopStrongest model; few, high-value calls
SubagentsFocused search and reading on one sub-questionCheaper model; each has its own context window
ToolsWeb search, fetch and extract, PDF parsing, private connectorsTimeouts, caching, robots compliance
Run memoryPlan, notes, source registry outside any context windowLets the lead survive context limits and restarts
Report writerTurn findings into a structured reportWorks from condensed notes, not raw pages
Citation agentAttach and verify citations for each claimAnthropic's system uses a separate citation step

Data model

CREATE TABLE research_runs (
  id             UUID PRIMARY KEY,
  user_id        UUID,
  question       TEXT,
  status         TEXT,        -- clarifying | running | writing | done | failed | cancelled
  budget_tokens  BIGINT,
  used_tokens    BIGINT,
  budget_fetches INT,
  used_fetches   INT,
  plan           JSONB,
  started_at     TIMESTAMPTZ,
  finished_at    TIMESTAMPTZ
);

CREATE TABLE run_steps (
  run_id         UUID,
  step_id        INT,
  agent          TEXT,        -- lead | sub_3 | writer | citer
  kind           TEXT,        -- llm_call | tool_call | spawn | checkpoint
  input_ref      TEXT,        -- pointer to stored payload
  output_ref     TEXT,
  tokens         INT,
  created_at     TIMESTAMPTZ,
  PRIMARY KEY (run_id, step_id)
);

CREATE TABLE sources (
  run_id         UUID,
  source_id      INT,
  url            TEXT,
  title          TEXT,
  fetched_at     TIMESTAMPTZ,
  excerpt_refs   TEXT[],      -- passages actually used
  PRIMARY KEY (run_id, source_id)
);

run_steps doubles as the checkpoint log for resuming and as the trace for debugging, which you will need: agent failures are rarely reproducible.

Deep dives

Orchestrator and subagents

Why multi-agent at all? Research questions often split into independent threads ("compare the battery chemistry, supply chain, and pricing of X and Y"). Parallel subagents explore them simultaneously, each with a clean context window, and return condensed findings rather than raw pages. That compression is the real benefit: the lead agent reasons over a few thousand tokens of findings instead of hundreds of thousands of tokens of web pages. Anthropic reports a large improvement over a single agent on their internal research evals, and also notes that multi-agent setups fit poorly when tasks are tightly interdependent, such as most coding work.

Writing good delegation briefs

Early versions of these systems famously spawned dozens of subagents for simple questions and had subagents duplicating each other's work. The fix is in the lead agent's prompt: scale effort to the question (one subagent for a simple fact, several for a broad comparison), and give each subagent an objective, an output format, suggested sources, and explicit boundaries so tasks do not overlap.

Budgets and stopping

Without budgets, research agents spend whatever you let them. Enforce in code, not only in prompts:

  • Per-run token, search and fetch budgets by plan tier, checked before every call.
  • Per-subagent iteration caps.
  • A lead-agent "sufficiency" check after each round: are the plan's questions answered with sources? If yes, write.
  • When the budget is exhausted, write the best report possible and clearly mark open questions.

Use the strongest model for the lead and writer, and cheaper models for subagents and extraction.

Durability

A 10-minute run will hit worker restarts, provider timeouts and deploys. Run it as a durable workflow: each LLM or tool call is a step whose result is persisted, so a crash resumes from the last completed step instead of starting over (and paying again). Tool calls should be idempotent or cached so retries are cheap. Progress events are emitted from the workflow, so a user who closes the tab can come back and see the run continue.

Context management for long runs

Even the lead agent can exceed its context window across many rounds. Keep the plan and notes in run memory, and when context grows, summarize completed rounds into memory and continue with a fresh context that reloads the plan and notes. Subagents return compact findings with source ids, never raw page text.

Citations and report quality

The writer works from findings that carry source ids. A separate citation pass then checks each claim against the stored excerpts and either confirms, swaps in a better source, or flags the claim. Evaluate reports with a rubric (factual accuracy, citation accuracy, completeness, source quality, efficiency) using an LLM judge calibrated against human graders, plus human review of a sample. Track cost per run next to quality so you notice when quality gains come from simply spending more.

Trade-offs and pitfalls

  • Token cost. Multi-agent is expensive by design. Reserve it for questions that benefit; route simple questions to a single agent or the quick answer engine.
  • Coordination failures. Subagents duplicating work or drifting off scope waste budget. Clear briefs and a shared source registry (skip URLs already read) help.
  • Compounding errors. A wrong early finding can steer the whole run. Ask subagents to report confidence and conflicting sources, not only conclusions.
  • Prompt injection. Web pages can carry instructions. Keep tools read-only, never pass private connector data into web search queries without care, and treat fetched text as data.
  • Non-determinism. Two runs of the same question differ. Rely on traces and aggregate evals, not single reproductions.
  • Source quality. Agents over-trust SEO content. Prefer primary sources in the prompt and score domains.

Checklist

  • Lead agent plans and delegates; subagents run in parallel with focused briefs and their own context.
  • Effort scales with question complexity, enforced by code-level budgets.
  • Runs execute as durable workflows with checkpointed steps and cached tools.
  • Plan, notes and sources live in run memory outside the context window.
  • Separate citation pass verifies claims against stored excerpts.
  • Rubric-based evals with LLM judges calibrated against humans, tracked with cost per run.
  • Read-only tools and untrusted handling of all fetched content.

Further reading

Why this exists README

I learn best by explaining things, so I record the explanations. Everything here is free, with no sign-up. If a lesson helps you ship something, I'd love to hear about it.