Skip to content

Librarian Agents: Training LLMs to Curate Long-Context Workspaces that Anticipate Future Queries

optionalcorefrontierpaperrubric 9/122026 · ~40 min

Anikait Singh, Teresa Zhang, Yoonho Lee, … Chelsea Finn

Read first: DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models

Status

TL;DR. Librarian Agents moves work from question time to before any question. A small builder agent reads a document collection and organizes it into a filesystem of synthetic notes and folders, each note linking back to its source documents, which are never deleted. A frozen answering agent later navigates this filesystem with list and read tools. The builder is trained with GRPO, and its reward is how well the answerer does on the resulting filesystem. On per-task BrowseComp-Plus document sets it reaches 0.75–0.77 accuracy, compared with 0.42–0.44 for embedding and reranker retrieval.

Why it matters now. Most agent memory is written for the writer’s own later use, and most retrieval is reactive: nothing happens until a query arrives. Here the memory is an artifact built for a different reader and optimized for that reader’s accuracy. For an IR reader, this is learned document organization, comparable to RAPTOR’s hierarchical summaries or GraphRAG’s entity graphs, but the structure is chosen by an RL policy rather than a fixed pipeline. It is a reusable corpus workspace, not conversational memory and not working context.

Librarian Agents: an RL-trained builder turns raw documents into a filesystem that a frozen answerer navigates Raw documents for one corpus go to a builder policy, which edits a filesystem with four actions: CreateFile with reference links to sources, MergeFiles to add hierarchy, Delete for synthetic files only, and Stop. The raw documents are never deleted and stay reachable through the reference links. Every eight builder turns, a frozen answering agent with list and read file tools answers training questions on the current filesystem; the change in its utility is the builder's dense reward, plus a terminal reward. The builder never sees evaluation questions. At test time the finished filesystem is reused for every question about the corpus, so the construction cost B is spread over q questions: tokens per question equal B divided by q plus the answer cost A. Build once, before any question; answer many times raw docs D one corpus never deleted (fallback) builder (RL) CreateFile + links MergeFiles Delete, Stop filesystem F README.md topic_a/ overview.md entity_x.md [refs: d17, d42] topic_b/ … links back to raw docs frozen answerer list_files, read_file → answer training: probe every 8 turns reward = U(F_t) − U(F_t−1) + terminal answer reward Test time: one filesystem per corpus, reused for all q questions tokens per question T(q) = B / q + A (B: build cost, A: answer cost)
Original sketch. The builder edits a filesystem over one corpus; a frozen answerer's accuracy, probed during construction, is the reward. At test time one filesystem serves every question on that corpus.

Problem. Questions that need several documents force a retrieve-and-read system to redo cross-document reasoning for every question. Precomputed structures (knowledge graphs, hierarchical summaries) do it once, but with fixed rules that are not tuned to what a reader needs.

Setup. A corpus of raw documents D\mathcal{D} and a filesystem Ft\mathcal{F}_t of synthetic files. The builder πbuild\pi_{\text{build}} takes one action per turn:

  • CreateFile: write a new synthetic file from some raw documents and/or existing synthetic files, with reference links to its sources.
  • MergeFiles: combine related synthetic files into a higher-level summary or directory, adding hierarchy.
  • Delete: remove a synthetic file. Raw documents are never deleted.
  • Stop: return the filesystem.

The builder chooses the action and its inputs; the file text is written by a fixed Qwen3.5-35B-A3B “content executor”. The builder never sees the evaluation questions.

Objective. With a frozen answerer πans\pi_{\text{ans}} and binary correctness, the filesystem’s score is S(F)=Eq E [Acc]S(\mathcal{F}) = \mathbb{E}_q\,\mathbb{E}\,[\mathrm{Acc}] and its utility subtracts navigation costs:

U(F)=S(F)−λtok Ctok(F)−λread Cread(F).U(\mathcal{F}) = S(\mathcal{F}) - \lambda_{\text{tok}}\,C_{\text{tok}}(\mathcal{F}) - \lambda_{\text{read}}\,C_{\text{read}}(\mathcal{F}).

Here the navigation costs are correctness-weighted: each rollout’s normalised token and file-read costs are multiplied by its correctness indicator before averaging. Thus incorrect answers receive zero utility regardless of navigation cost.

The sparse reward is U(FH)U(\mathcal{F}_H) minus α\alpha times the total build cost. The dense reward per turn is the change in utility:

rtdense=U(Ft)−U(Ft−1)−α Costbuild(at),∑t=1Hrtdense=rsparse−U(F0).r_t^{\text{dense}} = U(\mathcal{F}_t) - U(\mathcal{F}_{t-1}) - \alpha\,\mathrm{Cost}_{\text{build}}(a_t), \qquad \sum_{t=1}^{H} r_t^{\text{dense}} = r^{\text{sparse}} - U(\mathcal{F}_0).

Since U(F0)U(\mathcal{F}_0) is fixed, this is potential-based shaping and does not change the optimal policy. In practice the answerer is probed every eight builder turns (at most four probes) on the training task’s question, plus a terminal reward. The main run sets λtok=λread=α=0\lambda_{\text{tok}} = \lambda_{\text{read}} = \alpha = 0: the reward is accuracy only.

Training. Qwen3.5-4B builder, GRPO with per-step advantages, LoRA rank 32, learning rate 4e-5, batch 8, group 4, at most 32 builder turns; Gemini 3.1 Flash Lite compacts long builder histories. 680 BrowseComp-Plus tasks for training.

Worked trace (illustrative). A document set has 30 pages about several people and events. The builder creates people/ with one note per person, each linking to the pages that mention them, and events/ with a timeline note; then it merges the person notes into an overview. A later question needs a fact linking person X to event Y: the answerer lists people/, reads X’s note, follows its link to the timeline, and answers. If a needed detail was not written into any note, it can follow the reference links to the raw page.

Retrieve-and-read RAGLibrarian Agents
When work happensPer questionOnce per corpus, before questions
What the reader seesTop-k raw chunksA navigable tree of synthetic notes with source links
What is optimizedRetriever relevanceBuilder policy, for a frozen reader’s accuracy
What did not changeFrozen answerer, judge, document set
EvidenceBrowseComp-Plus figure, Table 2, BRIGHT Table 3, structure ablation (below)

All numbers are from arXiv v1 (October 2026). The judge is Gemini 3.1 Flash Lite.

  • BrowseComp-Plus setup. 680 training tasks and 50 held-out evaluation tasks. Each task has its own document set (evidence, gold and negative documents, following the dataset’s composition), not the shared corpus of about 100K documents. One filesystem is built per evaluation task and reused for all its questions.
  • Accuracy. With a frozen Qwen3.5-4B answerer: Librarian 0.75, embedding 0.42, embedding + reranker 0.44. With Gemini 3.1 Flash Lite: 0.77 vs 0.30 and 0.42. The untrained builder is below Librarian in both cases.
  • Construction cost (Table 2; accuracy / construction tokens): GraphRAG 0.36 / 11,923; AutoCompaction 0.04 / 501,637; untrained builder 0.28 / 127,683; Librarian 0.77 / 178,926.
  • Reuse. On 443 synthetic questions over 50 document sets (7–10 per set, generated by Gemini from DeepDive examples), Librarian reaches 0.637 vs 0.242 for the untrained builder, but its answerer reads 26.9 files and 9,346 tokens per question vs 2.72 and 1,238. Spreading the build over 20 questions gives about 18K tokens per question.
  • Cost per correct answer (Appendix A.4). At 10 questions per corpus, Librarian uses 33.8% fewer tokens per expected correct answer than the untrained builder (ratio 0.662, 95% CI 0.504–0.836). The two cross at 31 questions per corpus (CI 18–54); beyond that, the untrained builder is cheaper per correct answer because its answerer reads much less.
  • Zero-shot transfer to BRIGHT (Table 3; 150 questions, 50 each from AoPS, Biology and StackOverflow, one filesystem per domain). Average pass@1: Librarian 52.0, BM25 19.0, dense 20.8, Graph 6.3, AutoCompaction 4.5; pass@3 66.8. StackOverflow pass@1 is 85.5. Nine further domains (20 questions each) are compared only against the untrained builder.
  • What RL changes (BRIGHT). The trained builder makes 53.4 files in 45.4 clusters with 8.0 merges, vs 4.8, 4.2 and 0.6 for the untrained builder.
  • Structure ablation (Appendix A.5; 435 questions, 49 corpora; accuracy % / navigation tokens): original 55.86 / 3,635; flattened 57.70 / 5,497; shuffled 51.72 / 3,612.
  • Small, closed document sets. The main result reads whole per-task document sets with 50 evaluation tasks. Whether a builder can organize a 100K-document corpus, where it cannot read everything, is untested.
  • Static corpora. The filesystem is built once; how to update it as documents arrive is open (the authors list this).
  • Who writes the notes. A fixed 35B executor writes file content and a Gemini model compacts histories, so the 4B builder’s learned skill is mainly choosing and grouping.
  • Compression loses needles. Notes can drop a rare detail; reference links are the fallback, and the paper shows a recovery example. When the answerer should skip the synthetic layer is open.
  • Cost depends on reuse. The trained system pays off per correct answer only up to about 31 questions per corpus in their logs; with heavy reuse, cheaper answer-time reading matters more.
  • Different task from conversational memory. Raw-RAG and Librarian Agents answer different questions; a win for one does not settle the other.
  • Is complex agentic memory always needed? (Raw-RAG): keep raw conversation turns and retrieve; the opposite default, for a different task.
  • MemGPT and Mem0 and A-MEM: memory written by the agent for itself during conversations.
  • Context-Folding and AgentFold: compression inside one trajectory rather than across questions.
  • Recursive Language Models: the paper names RLM-style answerers as a way to read such workspaces.
  • Machine Studying (Li, Battle and Khattab, 2026), cited by the paper, frames learning from a corpus as continual adaptation of the whole system; Librarian keeps the answerer frozen and trains only a builder of an external, inspectable artifact.
  • RAPTOR, GraphRAG and HippoRAG: precomputed hierarchical or graph structures built by fixed pipelines.
  • Contextual retrieval: a lighter way to add document-level context before indexing.
  • BrowseComp-Plus and BRIGHT: the evaluation sets.
  • GRPO (DeepSeekMath): the RL algorithm used for the builder.

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.

  1. Derive / compute

    Librarian Agents models tokens per question as T(q) = B/q + A, where B is the one-time construction cost per corpus, A the answer-time cost per question, and q the number of questions asked of the corpus. Dividing by accuracy p gives tokens per expected correct answer. Derive the number of questions q* at which two methods have equal cost per correct answer, and say which method is cheaper below and above q*. Then plug in B = 178,926, A = 9,346, p = 0.637 for the trained builder and B = 127,683, A = 1,238, p = 0.242 for the untrained builder, and compare with the paper's reported crossover of 31 (bootstrap interval 18–54).

    What a strong answer covers
    • Set B1/(p1 q) + A1/p1 = B2/(p2 q) + A2/p2, which gives q* = (B2/p2 − B1/p1) / (A1/p1 − A2/p2).
    • Trained: B/p ≈ 280,900 and A/p ≈ 14,670. Untrained: B/p ≈ 527,600 and A/p ≈ 5,120. So q* ≈ 246,700 / 9,560 ≈ 26.
    • Below q* the trained builder is cheaper per correct answer because its higher accuracy spreads a large build cost better; above q* the untrained builder wins because the trained answerer reads far more per question (about 9.3K vs 1.2K tokens).
    • So "amortization" here does not mean the trained system gets relatively cheaper with more reuse; its relative advantage shrinks as q grows.
    • The rough estimate of 26 falls inside the reported 18–54 interval; the paper computes its 31 from rollout logs and full-denominator accuracy, so the exact inputs differ from the table values used here.
  2. Mechanism

    The builder's sparse reward is the final filesystem's utility minus build cost, and its dense reward at turn t is U(F_t) − U(F_t−1) minus that turn's cost. Show why the dense rewards sum to the sparse reward up to a constant, explain why this kind of shaping does not change which policy is optimal, and describe how the paper approximates it in practice and what it leaves out of the reward in the main run.

    What a strong answer covers
    • With γ = 1 the utility differences telescope: the sum over t of U(F_t) − U(F_t−1) is U(F_H) − U(F_0), and the cost terms add up to the total build cost, so the sum is the sparse reward minus U(F_0).
    • U(F_0) is fixed for a given initial filesystem, so maximizing the dense return is the same as maximizing the sparse one; this is potential-based shaping with U as the potential (Ng et al., 1999).
    • Computing U after every edit would need an answerer run each time, so the paper probes answerability every eight builder turns (at most four probes) and adds a terminal answer-correctness reward.
    • The main run sets the navigation-cost weights and the build-cost weight to zero, so the reward is accuracy only; structure and cost are not directly rewarded.
    • Advantages are computed per step as in multi-turn GRPO, with a group of 4 construction rollouts per task.
  3. What if…

    The paper's structure ablation keeps the content of the trained filesystems and changes only their organization: original, flattened (all files in one directory), or shuffled (files placed in semantically wrong folders). On 435 questions over 49 corpora, accuracy and navigation tokens are 55.86 / 3,635, 57.70 / 5,497 and 51.72 / 3,612. What does each intervention show about what the hierarchy contributes, and what does this imply for the claim that structure is what the builder learns?

    What a strong answer covers
    • Flattening keeps accuracy (57.70 vs 55.86, within the standard errors of about 2.6–2.8) but raises navigation cost by about 50%: the hierarchy mainly saves reading, not correctness.
    • Shuffling keeps the cost but lowers accuracy by about 4 points: misleading placement hurts more than no hierarchy.
    • Flattening shows that the folder hierarchy is not necessary for the observed accuracy under this intervention. Identifying which synthetic-content changes (which documents are combined, what is written) cause the learned gain needs additional ablations.
    • The content is written by a fixed Qwen3.5-35B-A3B executor; the 4B builder chooses what to create and merge, so "what the builder learns" is selection and grouping more than writing.
    • These questions come from the expanded synthetic set, not the original BrowseComp-Plus questions, so the result is about that setting.
  4. Critique

    The headline BrowseComp-Plus result is 0.75 for Librarian Agents vs 0.42 for embedding retrieval and 0.44 with a reranker (Qwen3.5-4B answerer). Explain exactly what task is being solved, how it differs from standard BrowseComp-Plus retrieval and from the Raw-RAG paper's conversational-memory setting, and what the result does and does not show.

    What a strong answer covers
    • Each evaluation task has its own small document set (evidence, gold and negative documents, following the dataset's composition), not the full shared BrowseComp-Plus corpus of about 100K documents.
    • Evaluation uses 50 held-out tasks, so one task is two accuracy points and confidence intervals are wide.
    • The builder reads the whole small document set before any question, which is a different problem from finding a needle in a large corpus; the retrieval baselines search the same small set.
    • Raw-RAG compares memory designs for long conversations, keeping raw turns; Librarian builds a reusable workspace over a fixed corpus. A win in one does not settle the other.
    • The result shows that an RL-trained builder can produce a workspace a small frozen answerer uses well; it does not show this scales to large or changing corpora, or that it beats a strong agentic search over the raw documents at equal total tokens.
  5. Research idea

    Propose a follow-up that tests Librarian Agents on the full BrowseComp-Plus corpus instead of per-task document sets. What changes in the builder's problem, what baselines and budgets would make the comparison fair, and how would you decide when the answerer should skip the synthetic layer and go straight to the raw documents?

    What a strong answer covers
    • With 100K documents the builder can no longer read everything; it needs its own retrieval or clustering step, and construction cost grows with the corpus, so the build must be shared across many questions to pay off.
    • Baselines: dense or BM25 retrieval with a reranker, an agentic search agent over the raw corpus, and RAPTOR- or GraphRAG-style precomputed structures, all with the same answerer and the same total token budget (build plus answer).
    • Report accuracy, evidence recall against the human relevance labels, and tokens per correct answer as a function of how many questions share the build, as in the paper's T(q) analysis.
    • Bypass policy: give the answerer a raw-search tool alongside the filesystem and log when it is used; or use a cheap confidence signal (did the synthetic files cite a source for the needed fact) to decide when to follow provenance links.
    • Measure needle loss directly: questions whose answer is in a raw document but absent from every synthetic file.
  6. Connect

    Place Librarian Agents in a four-way map of "memory" for agents: within-trajectory working context, cross-session conversational memory, reusable corpus workspaces, and weight updates. For each, name an example from this section or elsewhere on the site, what is stored, when it is written, and what signal trains the writer.

    What a strong answer covers
    • Within-trajectory working context: ReSum, Context-Folding and AgentFold; stores summaries or return messages of the current task; written during the episode; trained by the task's outcome reward (RL) or by SFT.
    • Cross-session conversational memory: MemGPT, Mem0, A-MEM, and the raw-turn store in the Raw-RAG paper; stores facts or raw turns from past conversations; written as the conversation happens; usually prompted, not trained.
    • Reusable corpus workspace: Librarian Agents (and precomputed structures such as RAPTOR or GraphRAG); stores synthetic notes with links to sources; written before any question; trained by a frozen answerer's accuracy.
    • Weight updates: learning the corpus into the model's parameters (for example the Machine Studying framing of continual adaptation from corpora); stores knowledge in weights; trained with a training objective on the corpus rather than through an answerer's reward on an external artifact.
    • The axes that matter: whether the raw evidence is kept, whether the store can be inspected, and whether the writer is optimized for a downstream reader.

Done with this page?

Status