AI · Framework

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's 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
Topic
AI Architecture
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: A full mental model plus benchmarks for a significant AI technique, captured with diagrams.

Related

Updated