Recursive Language Models (RLMs) are a scaffolding architecture that fundamentally differs from ReAct, CodeAct, and vanilla subagent patterns. Instead of loading the full user prompt into the LLM's context window, RLMs give the model access to a persistent Python REPL where the prompt lives as a variable. The LLM deliberately reads slices of context, writes code to transform data, and recursively invokes subagents via llm_query(). Crucially, subagent outputs are returned as Python variables in the REPL rather than being auto-loaded into the parent's context window, enabling composable answers without token-by-token regeneration. This approach enables arbitrarily long outputs, focused attention on relevant context sections, parallel subagent execution, and significant cost savings through KV cache reuse. The article walks through a concrete toy problem (counting letter 'r' in fruit/country/animal names) to illustrate how each architecture handles it, culminating in how RLMs solve it elegantly through recursive composition.

32m read timeFrom towardsdatascience.com
Post cover image
Table of contents
1. Of all the complicated experiments I ran…3. Recursive Language Models4. Why does this work so well?
332 Impressions