Building a retrieval environment for search-agent RL
Read first: Synthetic RL environments for agent training: a map · Search-R1: Training LLMs to Reason and Leverage Search Engines with Reinforcement Learning
TL;DR. A search agent’s environment is a corpus, an index, a few tools, a question generator and an answer checker. That is closer to an IR test collection than to a software sandbox, and IR has decades of practice building such collections. This page applies the six parts from the environments map to retrieval and draws design choices from published work. The answer-checking side is studied in depth; the environment side is thin. Agent World Model explicitly scopes to stateful apps “that necessitate database interactions instead of information retrieval”.
Key idea
Section titled “Key idea”| Environment part | Retrieval version | Precedent |
|---|---|---|
| State / observation | Frozen corpus and indexes; snippets and documents returned | BrowseComp-Plus: 100,195 documents for 830 questions |
| Tools | search(q, k), get_document(id); optionally a live-web tier | Search-R1 (E5 over Wikipedia); GEM QA with a Search tool wrapper |
| Task generator | Entity-anchored multi-hop questions built by search | DeepSeek-V3.2’s long-tail entity pipeline; training-data synthesis |
| Verifier / reward | Exact match or LLM judge; evidence recall from qrels | Search-R1 exact match; Tongyi’s 0/1 answer reward |
| Reset | The corpus is unchanged, but per-episode state (conversation, query budget, pagination cursors, caches, scratchpad) must be cleared | Contrast with SQL-backed AWM, which must snapshot and restore a database |
| Sandboxing | No unrestricted external egress: only the approved retrieval service is reachable; gold files and judge stay outside the container | Interfaces such as OpenEnv and verifiers |
One episode, step by step. Take the question “Which university did the author of the 2019 paper that introduced dataset X attend?” against a frozen corpus.
| Step | Who produces it | Tokens | Reward |
|---|---|---|---|
| 0. Reset | environment | samples the question from the task set; empty history, fresh query budget | — |
1. search("dataset X 2019 paper") | policy (action) | environment runs the retriever and returns five snippets with document ids (observation) | 0 |
2. get_document("d_4812") | policy (action) | environment returns the paper’s author list (observation) | 0 |
3. search("[author name] alma mater") | policy (action) | environment returns snippets naming the university (observation) | 0 |
| 4. final answer | policy (action) | answer text; the episode ends and the checker compares it with the gold answer | 1 if accepted, else 0 |
Only the policy’s own tokens (the tool calls, its reasoning and the final answer) are trained; snippet and document tokens are observations and are normally masked out of the policy loss, as in Search-R1. All intermediate rewards are zero, so the whole learning signal arrives at the end. That sparse terminal reward is why task difficulty and evidence diagnostics matter so much below.
Real, simulated, or both. There are three backends, and published systems use all three.
- A local retriever over a frozen corpus is cheap, deterministic and identical to evaluation on that corpus.
- An LLM-simulated search engine (ZeroSearch) writes documents given the query and the gold answer, with a noise curriculum. It is useful when the target is the open web and API calls are costly. The simulator knows the answer, which is a leak risk.
- A live web API is faithful to deployment but costly, slow and non-stationary.
Tongyi DeepResearch climbs this ladder: an offline 2024-Wikipedia simulator for algorithm work, then real tools for final RL. DreamGym’s experience model is itself retrieval-augmented. It conditions on the top-k similar past transitions, which the authors say reduces hallucination, so simulator quality becomes a retrieval problem (simulated environments).
Tasks. DeepSeek-V3.2 builds its 50,275 search prompts with a multi-agent pipeline that keeps a question only when a verifier confirms the gold answer and several answer agents all fail (lab pipelines has the details; training-data synthesis covers the wider family). “All answer agents fail” selects hard questions, but hard is not the same as useful: the question must also be answerable from the corpus the policy will search, and the policy must solve it sometimes, or every GRPO group is all zeros. The same idea runs in reverse in BrowseComp-Plus: there, questions are fixed and the corpus is built around them, with gold and hard-negative documents. A related but different design is SPICE (2510.24684), where a challenger mines a corpus to write questions and a reasoner answers them without document access. That is corpus-grounded task synthesis, not an environment for learning to retrieve.
Train/test splits for environments. Hold out questions and corpora (or corpus slices), not only questions, so that a familiar evaluation collection does not quietly become the training environment. If BrowseComp-Plus is the evaluation, do not train on its corpus or on questions synthesized from it. Note also the difference between a new structural variant of the same world (another retriever or snippet format over the same corpus) and a genuinely new world (an independent corpus); agentic data scaling finds that new worlds are worth more.
Evidence so far. RL on a local corpus with a plain retriever is the Search-R1 baseline that most search-agent papers reuse. ZeroSearch’s simulated engine matches or beats the same recipe trained on Google, when evaluated with real Google. GEM reports that adding its Search tool gives the highest QA accuracy in every setting after RL on HotpotQA and NaturalQuestions. Tongyi credits environment stability, more than algorithm choice, for successful agent RL. He et al. (agentic data scaling) already vary retrieval backends and interface semantics in their search-domain environment-scaling experiments: instances differ in backend (BM25, dense retrieval or a paginated web-search API), snippet grammar, rate limits and page-fetch availability (§4.3; Appendices A and D). A narrower open experiment is a matched-compute train-retriever × test-retriever matrix that isolates backend strength and randomization from snippet and tool changes. That is the research question above and a natural use of BrowseComp-Plus.
Connections
Section titled “Connections”- Search-agent RL recipes: Search-R1, ASearcher, ZeroSearch, Tongyi DeepResearch.
- Evaluation side: BrowseComp-Plus, BrowseComp.
- Long trajectories inside a search environment: context folding.
- Frontier pipelines for search data: lab pipelines.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Mechanism
DeepSeek-V3.2 keeps a synthesized search question only if a verifier agent confirms the gold answer and finds every candidate answer from several differently configured answer agents to be wrong. Explain what this filter selects for, how it acts as a difficulty filter, and two ways it can produce bad training tasks.
What a strong answer covers
- Selects questions that current models fail but whose answer can be confirmed with search: hard to solve, checkable, like BrowseComp.
- Diverse answer agents (different checkpoints and prompts) approximate the policy family; "all wrong" means near-zero pass rate for them, so the policy starts at the edge of its ability.
- Failure 1: the gold answer is wrong or ambiguous and the verifier agrees with it (shared model biases), so the task rewards a wrong answer and penalizes right ones.
- Failure 2: tasks may be unsolvable for the policy in practice (all-zero groups) unless a later pass-rate filter like pass@k > 0 removes them; or they may be hard only because the needed page is missing from the search backend the policy will use.
- Design
Design an RL environment for a 7B deep-research agent on a 100K-document corpus like BrowseComp-Plus. Specify state, tools, task generator, reward, reset and sandboxing, and say which parts you would run for real and which you would simulate.
What a strong answer covers
- State: frozen corpus plus prebuilt BM25 and dense indexes, served read-only. The corpus never changes, but reset must still clear per-episode state: the conversation, query budget, pagination cursors, caches and any scratchpad.
- Tools: search(query, k) returning snippets with document ids and get_document(id), exposed through an MCP or OpenEnv-style server; results cached per query for determinism and throughput.
- Task generator: entity-anchored multi-hop questions synthesized from the corpus (DeepSeek-style answer-agent filter), with difficulty tagged by hops and evidence spread, then a pass-rate filter against the current policy.
- Reward: exact match or an LLM judge on the final answer; optionally small credit for retrieving gold evidence (qrels make this possible), with care that it does not dominate.
- Real vs simulated: real local retrieval for training (cheap, faithful to the eval); simulate only what is costly or missing, such as a live-web tier or user clarification, and evaluate on the real backend.
- Research idea
BrowseComp-Plus shows that swapping BM25 for a strong dense retriever changes agent accuracy a lot under a fixed agent. Propose an experiment on whether the retriever used during RL training should be fixed, strong, weak, or randomized, and what the result would tell us about environment design.
What a strong answer covers
- Prior work: He et al. already vary retrieval backend, snippet grammar and page-fetch availability together as environment variants in their search domain. The open, narrower question is a matched-compute train-retriever × test-retriever matrix that isolates backend strength from snippet and tool changes.
- Arms: train with BM25 only, a strong dense retriever only, and a random choice per episode (domain randomization), holding snippet format and tools fixed; evaluate every policy with every retriever.
- Hypothesis A: weak retrievers force better query reformulation and persistence, which transfers upward; hypothesis B: strong retrievers give more reward signal per rollout and faster learning.
- Measure accuracy, number of search calls, evidence recall from qrels, and query diversity, so that behaviour changes and not only scores are visible.
- Implication: if the policy overfits its training retriever, the retriever must be treated as part of the environment distribution (like tool or user variation), not a fixed component.