PLAN → SEARCH → ANALYZE → refine or FINISH → ANSWER with Mercury as the agent. Because each planning turn returns in a few hundred milliseconds, most of the wall clock goes to the search API rather than the model. We walk you through how to build:
- A pluggable search function and an evidence store with stable citation IDs
- A JSON action contract and the plan-search-refine loop it drives
- A fully cited answer with a latency breakdown
Run the Search Agent
Directly via Google Colab or download the
.ipynb to run it locally in JupyterDependencies
API Keys
You need an Inception key plus a key for your search backend. Only the key for the backend you select is prompted for:The Search Backend
The loop only ever sees{heading: [docs]}, where a doc is {url, title, highlights[], publishedDate}. Keeping that shape fixed means swapping providers — Brave, Tavily, Serper, or your own vector index over internal docs — is one function plus a branch in search().
Optional: Parallel as the backend
Optional: Parallel as the backend
Evidence Bookkeeping
The agent’s memory. Two details are what make multi-round search work:- Stable source IDs. A URL keeps the same
[n]for the whole run, across rounds. That is what lets the final answer cite[3]and have it mean something. - Append-only transcript. Each round is appended, never rewritten, so the prompt prefix stays byte-identical between rounds.
The Agent Prompt
The prompt the planner sees every round. Three things are doing the work: a strict action contract of exactly one JSON object per turn, an enumerate-then-verify strategy, and hard evidence rules.Model Calls
A plain OpenAI-compatible chat call, with two Mercury-specific notes:reasoning_effort is the speed/quality dial: instant, low, medium, or high.Use response_format={"type": "json_object"} for the planner only. The final answer is free-form markdown, and forcing JSON there would coerce a perfectly good table into an empty object.The Timings ledger
The Timings ledger
The Loop
Plan, fan out searches in parallel, append evidence, and repeat until the agent saysfinish or the round cap is hit. Then one grounded synthesis call: