FDEInterviews logo
arXiv preprint

Recursive Language Models

The 2025 MIT paper that stops stuffing long inputs into the context window: put the input in a variable, let the model write code to slice it and call itself on the pieces.

Breakdown by FDE Interviews · 11 min read · Updated

About the original · 2025
AUTHORS
Zhang, Kraska, Khattab
FROM
MIT CSAIL
PUBLISHED
Dec 2025 · arXiv preprint
CITED BY
102Semantic Scholar · Oct 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 23% of this breakdown.

01

The paper in one minute

Models now accept hundreds of thousands of tokens, but accepting is not using. Quality drops as inputs grow, and it drops fastest on tasks where the answer depends on most of the input. GPT-5 finds a single needle in a million tokens, but on OOLONG-Pairs, where the answer depends on comparing pairs of lines across the whole input, it scored an F1 of 0.1. The usual fix for long agent histories, compaction (summarizing older context), assumes some details can safely be forgotten.

MIT CSAIL proposes Recursive Language Models (RLMs). Do not put the long prompt in the model's context at all. Put it in a variable inside a Python REPL. The root model is told only the prompt's length and a short preview, and how to reach it. It then writes code: peek at a section, split the input into chunks, loop over them calling a model (or another RLM) on each slice, collect results in variables, and finally set an answer variable. From outside, it behaves like a language model, string in, string out, with no practical limit on input or output length.

With GPT-5 and Qwen3-Coder on four long-context tasks, RLMs beat the base models, compaction agents, retrieval-equipped coding agents and Claude Code, often by double digits, at comparable average cost. They handled inputs above 10 million tokens. The authors also fine-tuned Qwen3-8B on 1,000 RLM trajectories and improved it by a median 28%.

The appendix of things that did not work is as useful as the results: the same prompt behaved differently across models, one model tried to make thousands of sub-calls, and sequential sub-calls made everything slow.

THE IDEA, VISUALLY
THE PROMPT LIVES IN THE ENVIRONMENT, NOT THE WINDOW context = "... millions of tokens ..." root sees: its length and a preview Root model writes code, never reads it all for chunk in split(context, 200 lines): notes.append(llm("label each line", chunk)) pairs = [llm("compare", a, b) for a, b in candidates] Final = summarize(notes, pairs) sub-call sub-call sub-call sub-call sub-call Sub-calls run on slices small enough to read well; results stay in variables, so the answer can be longer than any single output. OOLONG-PAIRS, GPT-5, F1 answer needs pairs of lines across the input, Table 1 GPT-5 alone 0.1 compaction agent 0.1 coding agent + BM25 24.7 RLM, depth 1 58 RLM, depth 3 76
Out of the window and into a variable. The root model reads only a preview, writes code that slices the input, and calls models on each slice, so the input can be far larger than any context window.
Research notes: the problem, approach and results
0.1 → 58F1

on OOLONG-Pairs, GPT-5 alone against GPT-5 as a depth-1 recursive model

10M+tokens

inputs handled, far beyond GPT-5's 272K-token window

1,000samples

of training that improved an 8B model as a recursive model by a median 28%

THE PROBLEM

Even million-token models degrade as inputs grow, especially on tasks where the answer depends on nearly every line, and summarizing old context throws away detail.

THE IDEA

Load the prompt into a Python environment as a variable. The model sees only metadata, writes code to inspect and split it, and calls itself recursively on slices, storing results in variables.

THE RESULT

Strong results at 10M+ tokens and large gains even within the window, at comparable average cost, with high cost variance and new failure modes.

02

Why it matters to an FDE

Customers bring long inputs: a year of support tickets, a full codebase, every contract in a data room. "The model has a million-token window" is not a plan. This paper gives you a better question and a different architecture.

Ask how the task scales with the input. Finding one fact is constant work regardless of length; the authors' S-NIAH task. Labeling and counting every line is linear work. Comparing pairs of items is quadratic. The more the work grows with the input, the earlier a model's context breaks down. A request like "find every pair of contracts with conflicting renewal terms" is quadratic, and no context window will save it.

Treat the data as an environment. RAG pulls snippets into the window; agents fill the window with tool outputs; compaction shrinks the window. All three keep the window as the bottleneck. RLMs move the data out entirely and let code decide what each model call sees. That is a familiar pattern for engineers: map over chunks, store intermediate results, reduce.

Budget for variance and guardrails. Average costs were comparable to the alternatives, but the spread was wide; in some cells the standard deviation exceeded the mean. A model writing loops that call models can make thousands of calls. Production versions need hard limits on sub-calls, depth and spend, a sandboxed execution environment, and logging of every trajectory.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 49 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦3 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    The ideas to keep, the three design choices, task complexity and the misreadings to avoid

    Free account
  2. 04How it works

    The algorithm, the environment, recursion depth and the trained 8B model, with a diagram

    Premium
  3. 05The numbers that matter

    Results and costs by method, model and depth, with the variance that averages hide

    Premium
  4. 06Try it yourself

    A minimal recursive model on a counting task a context window cannot do, with a sub-call budget

    Premium
  5. 07Where it breaks

    The limits the authors list, including the negative results appendix

    Premium
  6. 08Using it on a deployment

    When to use the pattern, and how to make it safe to run

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →