Abstract
Large Language Models (LLMs) face significant challenges in processing extremely long contexts, primarily due to fixed context windows and "context rot"—the degradation of reasoning quality as input length increases. We introduce Recursive Language Models (RLMs), a novel inference paradigm that treats long prompts as external environments rather than sequential token streams. By leveraging a Python Read-Eval-Print Loop (REPL), RLMs programmatically decompose complex tasks into manageable sub-queries. Our evaluation shows that RLMs can scale effective context windows to over 10 million tokens, significantly outperforming frontier models like GPT-5 on dense retrieval and quadratic complexity tasks while maintaining cost efficiency.
Introduction
The evolution of Large Language Models has been marked by a continuous effort to expand context windows. However, two fundamental issues persist: physical context limits and the phenomenon of "context rot." Even when a prompt fits within a model's technical limit, the model's ability to reason over that information often declines sharply as the sequence length grows. Existing mitigation strategies, such as Retrieval-Augmented Generation (RAG) or summarization, are inherently lossy and struggle with tasks requiring dense, holistic understanding of the input.
This paper presents Recursive Language Models (RLMs), which shift the burden of context management from the model's neural attention mechanism to a symbolic, programmatic execution environment.
Methodology: Prompts as Environments
The core innovation of RLMs is the treatment of the prompt as a variable within a persistent Python REPL. Instead of ingesting the entire prompt as a single sequence, the "root" LLM interacts with it through code.
As illustrated in the architecture diagram, the RLM workflow consists of four primary stages:
- Symbolic Loading: The prompt is loaded into the environment as a variable (e.g.,
prompt). - Programmatic Exploration: The model writes Python code to inspect metadata (e.g., length, structure) and slice the prompt into manageable chunks.
- Recursive Execution: The model issues sub-calls (
sub_llm()) to process specific snippets. These calls can be directed to the same model or specialized smaller models. - Stateful Aggregation: Results are stored as variables in the REPL, allowing the root model to synthesize a final response from structured intermediate data.
Experimental Setup
We evaluated RLMs against several benchmarks designed to test long-context limits:
- S-NIAH: A standard "needle-in-a-haystack" test.
- BrowseComp-Plus: Multi-hop QA over 1,000 documents (up to 11M tokens).
- OOLONG & OOLONG-Pairs: Benchmarks for transformation and cross-document comparison. OOLONG-Pairs specifically tests quadratic complexity, requiring the model to compare all pairs of entries across the dataset.
Results and Analysis
RLMs demonstrate a remarkable ability to bypass the "hard ceiling" of traditional Transformer architectures. By decomposing the task, the model avoids the quadratic memory costs and attention dilution associated with massive context windows.
As shown in the performance comparison, the base GPT-5 model experiences a catastrophic decline in performance on the OOLONG benchmarks as context length increases, eventually failing entirely beyond its 262k token limit. In contrast, RLM(GPT-5) maintains stable performance even as the input scales to 1 million tokens and beyond.
On the BrowseComp-Plus task, RLM(GPT-5) achieved 91.3% accuracy on 11-million-token inputs, a regime where the base model could not even begin processing. Furthermore, RLMs proved highly effective at quadratic tasks; on OOLONG-Pairs, they achieved an F1 score of 58.0%, while vanilla frontier models failed catastrophically (near 0%).
Cost and Efficiency
Contrary to expectations that multiple recursive calls would increase costs, RLMs often proved more economical than "summary agents." By selectively querying only relevant portions of the context, RLMs avoid the high cost of re-ingesting and summarizing massive amounts of irrelevant data. Additionally, we found that even small models (e.g., Qwen3-8B) can be fine-tuned to become "natively recursive," improving their decision-making efficiency by 28.3% over their base counterparts.
Conclusion and Future Work
Recursive Language Models represent a paradigm shift in how LLMs handle massive contexts. By moving from a purely neural reading approach to a hybrid symbolic-neural interaction, RLMs unlock the ability to process tens of millions of tokens with high precision. Future research will focus on reducing latency through asynchronous sub-calls and exploring deeper hierarchical recursion to solve even more complex reasoning problems.
Summary updated