# Recursive Language Models (RLM)

> A framework treating long prompts as programmatic environments inside a REPL

Recursive Language Models (RLM) solve context rot and RAG limitations by treating massive context as an environment rather than raw tokens fed into a prompt. A model uses a Python REPL to search, slice, and recursively process subsets of documents via code. This programmatic inspection cuts inference costs while outperforming standard long-context models on needle-in-a-haystack and multi-document reasoning.

## The framework

Main claim: DeepMind built an AI with perfect memory of everything it has read, called Recursive Language Models (RLM), potentially ending traditional context windows.

1. Context rot: bigger windows (2M, 10M tokens) don't help — every frontier model degrades past ~100K tokens ("context rot").
2. Why RAG fails: retrieving chunks and stuffing them into the prompt breaks for tasks needing multiple parts of a document considered simultaneously — "lost context".
3. How RLMs work: instead of pushing 10M tokens into the model, the prompt is loaded as a variable in a Python REPL. The model writes code to grep(pattern, prompt), slice(start, end, prompt), and recursively\_call(prompt) on relevant snippets — an AI agent navigating the prompt programmatically rather than reading linearly.
4. Analogy: like a human with a huge document — Ctrl+F, jump to sections, take notes; the prompt is an environment, not a linear read.
5. Results: multi-document research — GPT-5 base: 0%, GPT-5 with RLM: 91%. Information-dense reasoning — base: 0.04%, RLM: 58%.
6. Emergent behaviour: models weren't trained for this — they invented regex filtering, recursive sub-calls, and self-verification on their own.
7. Cost: median RLM run is cheaper than the base model because it only reads what it needs instead of ingesting 10M tokens upfront.
8. What it unlocks: analyzing entire legal codebases, million-line repositories, synthesizing hundreds of research papers, processing years of medical records.

## What it is for

- Navigate million-line codebases without running into context rot or high token costs
- Synthesize hundreds of complex research papers or legal contracts simultaneously
- Process multi-year medical histories by running targeted recursive code queries
- Replace standard RAG pipelines for tasks requiring holistic document context

## Key points

- Loads raw context into a Python REPL environment as accessible variables
- Enables the model to write code to grep, slice, and programmatically inspect text
- Supports recursive model sub-calls that process only relevant text chunks
- Eliminates linear context degradation ('context rot') in long-document tasks
- Reduces median run costs compared to feeding full multi-million token contexts

## Pricing

Free

## Details

- Type: Framework
- Category: [AI](https://xiry.app/topics/ai.md)
- Platforms: other
- For: AI researchers, machine learning engineers, and LLM application developers
- Alternative to: Traditional RAG pipelines, Standard long-context prompt stuffing
- Tags: llm, rlm, context window, rag, prompt engineering, deepmind, python repl

## Why it was saved

- [@rryssf, 12 January 2026](https://x.com/rryssf/status/2010699140431503692): A full mental model plus benchmarks for a significant AI technique, captured with diagrams.

## Related

- [Prompt Engineering (Google Whitepaper)](https://xiry.app/resources/prompt-engineering-google-whitepaper-2086): A comprehensive guide to prompt engineering techniques and LLM parameters by Google. (Article or course, Free)
- [8 Ways to Improve RAG Applications](https://xiry.app/resources/8-ways-to-improve-rag-applications): Practical architectural strategies to fix common failure modes in RAG systems (Tip, Free)
- [AnythingLLM](https://xiry.app/resources/anythingllm): Private, on-device AI assistant to chat with documents and local models. (Desktop app, Open source)
- [CLaRa: Bridging Retrieval and Generation with Continuous Latent Reasoning](https://xiry.app/resources/clara-bridging-retrieval-and-generation-with-continuous-late): RAG framework using continuous latent reasoning and embedding-based context compression (Article or course, Free)
- [DeepSeek Chat](https://xiry.app/resources/deepseek-chat): Conversational AI assistant with open-weights reasoning and general language models (Web app, Freemium)
- [Fabric](https://xiry.app/resources/fabric): Open-source framework to apply modular AI prompt patterns via the CLI. (GitHub repo, Open source)

Updated 11 October 2026. Page: https://xiry.app/resources/recursive-language-models-rlm

Make your own library: Xiry takes your saved reels, tweets, Reddit bookmarks and Watch Later videos, makes them searchable and pulls the useful stuff out, like this library. It's invite-only for now; join the waitlist at https://xiry.app/#waitlist.
