Enabling Deep Recursion (Depth > 1)
Extend the recursive language model environment with a runtime stack and recursion logic to support deep multi-level sub-calls.
Time
Compute level
Resources
Prerequisites
Scope
The Gap
The experiments in the paper explicitly limit the recursion depth to one level (Section 5: 'we chose to use a max recursion depth of one'). The system prompt warns models against excessive sub-calls.
Limitation
Limiting recursion to a single layer restricts the model's ability to handle truly hierarchical data structures or extremely massive datasets (e.g., >100M tokens) where a single level of chunking is insufficient to reduce data to a manageable context size.
Proposed Solution
Extend the RLM environment to support a recursion stack, allowing sub-LMs to instantiate their own REPL environments and invoke further sub-LMs. This requires implementing stack management in the runtime and refining prompts to prevent infinite recursion loops.
Why This Matters
Unlock the ability to process effectively infinite contexts using divide-and-conquer strategies (logarithmic scaling), essential for processing entire libraries or repositories rather than single documents.
How to Get Started
- Review the existing recursive language model execution loop and identify where the single recursion limit is enforced.
- Implement a stack data structure in the runtime to manage nested REPL environments and sub-LM state.
- Update the system prompts and execution logic to allow sub-LMs to invoke further sub-LMs safely without infinite loops.
- Test the deep recursion system on complex hierarchical reasoning tasks and monitor execution correctness.
Code linked to this paper on Hugging Face: github.com/alexzhang13/rlm
Suggested by AI. Adapt it to your setup.
Has This Been Done?
The listed works do not present an RLM environment supporting a recursion stack where sub-LMs instantiate their own REPL environments. Papers like Recursive Multi-Agent Systems explore multi-agent setups, but none implement this specific recursive execution stack for language model runtimes.
- Recursive Multi-Agent Systems · 2026 · 20 citations
We searched OpenAlex for “Extend the recursive language model environment with a runtime stack and recursion logic to support deep multi-level sub-calls.” and “Enabling Deep Recursion (Depth > 1)” and an AI compared the idea with the top 10 results. A small search can miss relevant work.
Source Paper
Recursive Language ModelsAlex L. Zhang, Tim Kraska, Omar Khattab · 2025
This paper introduces Recursive Language Models (RLMs), an inference-time scaling strategy that allows Large Language Models to process arbitrarily long inputs by treating the context as an external environment within a Python REPL. Instead of ingesting the full context at once, the model writes code to programmatically access, decompose, and recursively sub-query specific chunks of the data, enabling effective processing of inputs up to 10M+ tokens with competitive costs compared to base models.
Related Ideas
- Recursive Associative-Memory Graph Traversal for Multi-Step Scientific ReasoningWeight-Space Programming Doesn't Need Transformers🟡Fairly easy
- Subgraph-Decomposed Curriculum RL for Hard Repository-Level Software EngineeringSage S2.1 Flash Technical Report🔴Hard
- Backtracking Search for Multi-Step Coding ChainsGLM-5: from Vibe Coding to Agentic Engineering🟡Fairly easy
- Integration of Sequence Parallelism for Long-Context TrainingLlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models🔴Hard
- Semantic Compressive Memory for Long-Horizon ContextMiroThinker: Pushing the Performance Boundaries of Open-Source Research Agents via Model, Context, and Interactive Scaling🟠Medium