RLM (Recursive Language Model): Write Code to Call Itself, Not Tools
- RLM gives models the ability to "call themselves": the main agent writes code to spawn sub-agents, shifting context from the model window into variables and files.
- Official benchmarks draw a practical line: at a 64k context, there's little difference; at 128k, the gap becomes clear.
- The trade-offs are stated upfront: higher latency and token costs, in exchange for accuracy and determinism.
What RLM (Recursive Language Model) Is
In plain terms, RLM gives an AI model the ability to "call itself."
That definition is easy to hear and move past. It only makes sense when you see it next to the traditional approach:
You give the agent a huge file, and it has to stuff everything into its limited memory (the context window) to analyze it.
The result is often that it forgets earlier parts, or loses significant detail when summarizing.
The model's orchestration logic lives in code. The main agent acts as a director, writing code to create multiple sub-agents for parallel work—a divide-and-conquer strategy.
Most of the context and intermediate data is held in variables or local files, rather than being force-fed into the context window.
The real-world difference: the model doesn't need to "memorize the whole book before answering"; it "writes a processing pipeline and looks up the page it needs."
Background not covered in the video: RLM wasn't introduced by LangChain. It comes from a blog post by Alex Zhang in October 2025, later formalized in a paper (arXiv:2512.24601). LangChain integrated this paradigm into its agent framework to make it directly usable.
This article examines a 6-minute 36-second official tech talk by LangChain open-source engineer Sydney Runkle, focused on using RLM within Deep Agents.
The full LangChain official demo, 6 min 36 sec, with our bilingual subtitles. The breakdown below covers this video.
The Pain Points RLM Solves
It targets three issues; the first two are classic agent problems.
Traditional agents struggle to process tens of thousands of lines deterministically, line by line. They read once and answer based on understanding, which becomes unreliable with large datasets—you can't guarantee every line was actually seen.
Context windows are finite. Long conversations eventually require summarization to make room. But summaries are lossy—you don't know if the compressed-away part contained the critical line.
With code-driven logic, complex structures like loops, fan-out, and pipelining become easy for the model to build. Any orchestration pattern you can write in code is available.
Moving orchestration into code yields two key benefits:
- Deterministic Coverage—code guarantees every line is processed, nothing skipped. This is crucial for large-scale data problems.
- Custom Orchestration—organize work however you want using code-level primitives.
Using RLM in Deep Agents
Deep Agents is LangChain's open-source harness for building general-purpose agents handling complex real-world tasks. Enabling RLM involves two steps.
Mount a lightweight code execution environment onto the main agent. There's a notable design choice here: it's light enough for the model to write and run code, without needing a heavy full sandbox.
The main agent writes code that calls the built-in task function to launch and coordinate sub-agents, then aggregates results. Arbitrary code can run before and after the task calls—data prep before, aggregation after.
Getting started is straightforward: use the create deep agent primitive, pass in the code interpreter middleware, and you're in code mode.
The highlighted lines are the whole secret: orchestration is code, task is the only fork, and it's surrounded by regular code. Illustrative snippet, not from the video.
DEMOLive Walkthrough: 16 Sub-Agents Compete in a Haiku Tournament
The demo environment is decode, LangChain's terminal coding agent built on the Deep Agents framework. Type decode in your terminal to start.
The keyword to trigger RLM is workflow. The prompt given was: run a workflow to generate 16 haikus about breakfast foods, then pick the best through a tournament.
Here's what happened next: the main agent automatically spawned 16 sub-agents, each quickly writing a poem. Then it started writing code (using a JS eval tool) to run head-to-head rounds—16 to quarterfinals, and so on. Partway through, the model wrote buggy code, noticed, and fixed it. Finally, a champion emerged: a haiku about berries.
The demo itself isn't complex, but it shows the pattern: fan out 16 parallel tasks, then converge round by round via a tournament structure. That's what "organizing work with code primitives" looks like in practice.
Performance and Benchmarks
Beyond the demo, the official team provided benchmarks using the Oolong dataset, a benchmark suite specifically testing long-context reasoning and data aggregation.
SETUPHow the Test Was Designed
They used the AgNews portion of Oolong: a large table with thousands of rows, each containing three fields: date, user, and an unlabeled news headline.
The task had two steps: first, classify each headline into one of four categories: world, sports, sci/tech, or business; then answer distributional questions about the data.
Questions were grouped by difficulty:
| Difficulty | Type | Example |
|---|---|---|
| Easiest | Counting | Across all headlines, which label is least common? |
| Medium | Filter then count | How many sci/tech headlines are under a specific username? |
| Hardest | Temporal reasoning | Before August 2004, were there more sports headlines than world headlines? |
The core challenge is data volume: feeding thousands of rows to the model and asking for classification, aggregation, and reasoning is nearly impossible without RLM or some form of code support.
RESULTTwo Context Lengths, Two Very Different Outcomes
The comparison was between a standard Deep Agent without a code interpreter, and one with it (i.e., RLM enabled).
Minimal difference—essentially a tie. No clear benefit to RLM at this setting.
RLM shows a massive advantage. The standard agent fails frequently at this size.
Bar lengths indicate trends: the video showed chart trends without specific scores.
More interesting is how the standard agent fails: at 128k, its answers are full of "I can't determine exactly" and "I'm blocked from calculating." The model is overwhelmed by the sheer volume and gives up. The RLM version, guided by code logic, breaks the task apart and calculates the correct answer.
The takeaway: with even longer contexts or harder questions, the RLM version would likely extend its lead.
TRADE-OFFThe Cost: Slower and Pricier
The video is upfront about the costs: RLM mode has significantly higher latency and consumes more tokens. The return is accuracy and determinism.
There's room for optimization. The speaker noted that fine-tuning—like designing skills to handle specific problem types—could substantially cut token usage and cost.
What RLM Is Good For
Stop relying on huge context windows; use "code + sub-agent divide and conquer" for massive data. Context lives in variables and files; the model fetches what it needs.
Complex large-scale classification, statistics, and logic are executed rigorously by programs, not approximated by the model's intuition. This significantly boosts agent usability in complex, real-world business scenarios.
For the "should I use it?" question, the benchmark line is the most practical answer: If your data doesn't strain the context window, RLM won't show obvious benefits and will cost you latency and money. At the 128k scale, or when tasks demand line-by-line completeness, its value becomes clear.
Info Not Provided in the Video: The specific model used was never mentioned, which affects transferability. Latency and costs were described qualitatively, without multiples. Accuracy was shown via chart trends without concrete scores. The task function signature and sub-agent configuration weren't detailed. Whether the model's self-correction in the demo is typical or occasional wasn't addressed.
When Models Write Code to Call Themselves: The Gap Shows Past 128k Context
A 6.5-minute LangChain engineer demo, visually explained in one page—the mechanism, a haiku tournament, and the practical judgment on whether to adopt it.
↓ Read in one page · Includes an animated diagram
RLM (Recursive Language Model) gives models the power to "call themselves": the main agent writes code, spawns several copies to process data, then aggregates results. This concept isn't from LangChain; it comes from Alex Zhang's Oct 2025 blog and paper. LangChain integrated it into its Deep Agents framework.
Stuff the entire dataset into the context window. If it doesn't fit, summarize—but summaries are lossy, and the compressed-away part might be the critical line.
Orchestration logic lives in code. The main agent acts as a director, writing code to spawn copies for parallel processing. Most data sits in variables/files, fetched on demand.
You get two things: code guarantees every line is processed (deterministic coverage), and complex orchestrations like loops, fan-out, and multi-step pipelines are easy to build (custom orchestration).
Deep Agents is LangChain's open-source framework for building general-purpose agents that handle complex real-world tasks. Adding RLM takes two steps: attach a lightweight code execution environment to the main agent (no need for a full sandbox), then have it use the built-in task function to write code and coordinate sub-agents. Other code can run before/after, e.g., data prep and result aggregation. Start with create deep agent, pass the code interpreter middleware, and trigger with the workflow keyword.
Alongside the demo, there were benchmarks using the AgNews portion of the Oolong dataset—thousands of unlabeled news headlines. The task: classify each (world/sports/sci-tech/business), then answer statistical questions, from "which label is least common" up to "were there more sports than world headlines before a certain month."
At 128k, the standard agent frequently answered "can't compute" or "can't say precisely"—overwhelmed and giving up. The RLM version still broke the task down via code and produced correct answers.
This approach delivers two things: moving data off the overloaded context into variables/files for on-demand access, and letting code rigorously execute large-scale classification, statistics, and reasoning—not leaving it to the model's fuzzy impression.
✔ The task requires complex orchestration: loops, parallel fan-out, or multi-step pipelines.
✘ Data still fits comfortably in the context; higher latency and costs with no visible benefit.
✘ If you just want a quick answer and exactness isn't critical, a standard agent is sufficient.
The video doesn't specify the model used, shows accuracy only as a chart trend without exact scores, and mentions latency and costs only directionally without multiples—these factors affect whether the conclusions transfer to your own scenario.
for c in 16
Members can copy or download the full Markdown, and let their AI subscribe and ask.
Found this useful? Leave your email — every new explainer, the moment it's out. Unsubscribe anytime.
