What are recursive language models?
A recursive language model (RLM) keeps a long prompt in a code environment and calls itself on pieces of it, instead of reading it all in one context window.
A recursive language model (RLM) is a way of running a language model so it can work on inputs far longer than its context window. The long prompt is stored outside the model, in a code environment, and the model writes code to inspect it and calls itself on the pieces. The idea comes from Alex L. Zhang, Tim Kraska and Omar Khattab (arXiv, December 2025), and the paper was accepted to NeurIPS 2026 (author blog).
It is an inference strategy, not a new architecture. The authors call it “a thin wrapper around a LM that can spawn (recursive) LM calls,” and callers use it like an ordinary model call (author blog).
How an RLM works
The root model receives only the user’s query. The full context sits in a Python REPL as a variable. The root model can peek at it, partition it, search it with code and launch sub-queries, calling a recursive model “as if it were a function in code.” It finishes with FINAL(...) or FINAL_VAR(...) (author blog).
user query
|
root model <-> REPL (context as a variable)
| |
| sub-model calls on slices
v
FINAL(answer)
The root is depth 0. A max depth of 1 lets the root call plain models, and a depth above 1 lets it call other RLMs. The paper assumes depth 1 unless stated and also tests max depths 0 to 3 (paper, v3, May 2026). The first blog post only considered depth 1. Prime Intellect’s implementation fixes depth at 1 and adds an llm_batch function to run sub-calls in parallel (Prime Intellect, 1 January 2026).
How it differs from other ways to handle long context
| Approach | What happens to the long input |
|---|---|
| Plain long context window | The whole input is placed in the prompt. |
| Compaction or summarizing | Earlier text is condensed, so detail can be lost. Prime Intellect says its RLM “never actually summarizes context” (source). |
| RAG | A retriever picks passages to put in the prompt. |
| RLM | The input stays in the REPL. The model decides what to read and which slices to hand to sub-calls. |
The paper compares RLMs against compaction and coding scaffolds directly. For GPT-5 it reports median gains of 26% over compaction, 130% over CodeAct with sub-calls and 13% over Claude Code (paper).
What the results show
The numbers below come from the authors, using the models they tested in 2025 and 2026.
- OOLONG, about 132k tokens: RLM with GPT-5-mini beat GPT-5 by over 34 points (about 114%) and was nearly as cheap per query. Removing recursion cut performance by about 10% (author blog).
- OOLONG, about 263k tokens: the same setup beat GPT-5 by over 15 points (about 49%) and was cheaper per query on average.
- BrowseComp-Plus, 10 to 1,000 documents, 20 sampled queries: RLM with GPT-5 was “the only model / agent able to achieve and maintain perfect performance at the 1000 document scale”.
- Training: RLM-Qwen3-8B beat its base model by 28.3% on average and approached vanilla GPT-5 on three long-context tasks (paper).
Results from others are less uniform. Prime Intellect, testing mainly GPT-5-mini, saw reward rise generally, but fall on a math-python environment, and on DeepDive the RLM did worse than the plain model unless it was given strategy tips. Total time rose in every environment (Prime Intellect).
Limits to know
- Speed: recursive calls block and do not use prefix caching, so queries take from a few seconds to several minutes (author blog).
- Cost control: the authors say they lack strong guarantees on total API cost or runtime per call.
- Depth: deeper is not always better. In the paper, higher-depth GPT-5 variants outperformed all other methods on some tasks, but higher depths did worse on average for Qwen3-Coder, whose syntax errors propagate to sub-calls (paper). A March 2026 reproduction by Daren Wang found that depth 2 lowered accuracy in every condition it tested. On a simple retrieval task, run time went from 3.6s for the plain model to 89.3s at depth 1 and 344.5s at depth 2 (preprint).
- Output and time caps: Prime Intellect’s setup limits REPL output to 8192 characters per turn and each REPL call to 120 seconds by default (source).
- Maturity: Prime Intellect calls its results experimental and relative, not absolute benchmark claims.
Running one
The authors publish a library, installed with pip install rlms on Python 3.11 or later. Its environment option takes local (the default), ipython, docker, modal, prime, daytona or e2b. The README says local runs generated code on the host, suits local low-risk tasks such as simple benchmarking and should not be used in production, while the Docker and cloud options isolate it (GitHub). Treat the model’s code as untrusted, as with any agent that executes code.
An RLM resembles a ReAct agent in that it loops over actions and observations, but the loop is code the model writes against its own context. The model also manages what enters its own window.
Tracing an RLM run
One RLM call fans out into many model calls, so you need a record of each. The library’s RLMLogger keeps the trajectory in memory on completion.metadata, or writes a .jsonl file per completion with log_dir, and ships a visualizer (GitHub).
To see the same run in a tracing tool, HoneyHive’s tracing concepts describe model events that store input messages, parameters and output, with metadata such as prompt_tokens, completion_tokens, total_tokens and cost, and sessions that group events. Per-call token and cost data shows where a recursive run spends its budget. See LLM observability and agent observability.
FAQ
What is a recursive language model?
An inference method where a language model treats a long prompt as an external environment, inspects and splits it with code, and calls itself recursively on snippets (Zhang, Kraska and Khattab).
Is an RLM a new kind of model?
No. The authors describe it as a thin wrapper around a language model that can spawn recursive model calls, used like a normal model call (author blog). They also post-trained a model, RLM-Qwen3-8B, to use the method (paper).
How long an input can an RLM handle?
The paper reports inputs up to about two orders of magnitude beyond a model's context window (paper). Prime Intellect found no model succeeded on its real Oolong data beyond about 1.5M characters.
Are RLMs slower or more expensive?
They can be slower. The authors say recursive calls are blocking and skip prefix caching, so a query can take seconds to minutes, and they have no strong guarantees on total cost (author blog). Deeper recursion adds more time (Wang).
Is it safe to run the code an RLM writes?
Not by default. The open-source library's local environment runs code on the host, and the README says it should not be used in production. Docker, Modal, Prime, Daytona and E2B environments isolate it (GitHub).