RLM (Recursive Language Model): Write Code to Call Itself, Not Tools

A 6.5-minute official demo covering the mechanics, a haiku tournament, and benchmark data on when it's actually worth it.
By LangChain08-08 · 9 min read⚑ Product update
Tool Guide · Xiaohu Explains
TL;DR
  • 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.
⚑ This article breaks down a technical sharing video released by LangChain. The mechanism descriptions and benchmark data are sourced from that video. Additional background information with citations comes from public resources outside the video.
01

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:

Traditional

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.

RLM

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."

TRADITIONAL Context Window Full · need summaries to fit Summaries lose info RLM Main Agent writes code calls itself var file var Sub Sub Sub Take a piece · process · report back
With the same data, one approach crams it all into the window, the other keeps it in variables and files for on-demand access. Diagram based on the video.

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.

02

The Pain Points RLM Solves

It targets three issues; the first two are classic agent problems.

1
Fails on Long Text and Large Data

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.

2
Lossy Summarization

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.

3
Inflexible Logic Control

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.
03

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.

1
Add a code interpreter

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.

2
Use the task function for sub-agents

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.

Program written by the main agent
1# Data prep: normal code
2rows = load_dataset(...)
3chunks = split(rows, n=16)
4
5# Spawn sub-agents to work
6results = [task(c) for c in chunks]
7
8# Aggregate after they return: also normal code
9answer = aggregate(results)
└─ Sub-agentSub-agentSub-agent → results to line 9

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.

Winner 16 sub-agents write one each Rounds · code-driven
The main agent writes code to place the 16 sub-agents' outputs into a bracket, converging round by round. Diagram based on the video.
04

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:

DifficultyTypeExample
EasiestCountingAcross all headlines, which label is least common?
MediumFilter then countHow many sci/tech headlines are under a specific username?
HardestTemporal reasoningBefore 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).

64k
Context Length
Standard
RLM

Minimal difference—essentially a tie. No clear benefit to RLM at this setting.

128k
Context Length
Standard
RLM

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.

05

What RLM Is Good For

1
Break the context bottleneck

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.

2
From probabilistic guess to deterministic computation

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.

✅ Readiness Checklist

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.

Source
How to use RLMs in Deep AgentsLangChain·Official video
Our note
Mechanism descriptions, demo process, and benchmark data come from the video above. The origin of the RLM concept (Alex Zhang's Oct 2025 blog and subsequent paper arXiv:2512.24601) is our addition, not from the video. The video didn't disclose the model used, specific latency/cost multiples, or exact accuracy scores. All diagrams are our own based on the video.
↑ End of article
✓ This article is free to read in full

Members can copy or download the full Markdown, and let their AI subscribe and ask.

Read the original ↗
📮 New explainers, straight to your inbox

Found this useful? Leave your email — every new explainer, the moment it's out. Unsubscribe anytime.