Recursive Language Model
The model calls itself to solve sub-problems, recursively.
Intent & Description
🎯 Intent
Solve complex problems by recursively decomposing them into sub-problems, dispatching each to a fresh model call, and combining results — like recursive function calls but with LLMs.
📋 Context
Some problems have natural recursive structure (parsing, hierarchical summarization, tree traversal, nested reasoning). Flattening them into a single prompt loses the structure. Recursive calls preserve it and let each sub-call be independently scoped.
💡 Solution
Design a prompt that (1) checks if the current problem is a base case (answer directly), (2) if not, decomposes into sub-problems and makes recursive agent calls for each, (3) combines sub-results into an answer for the current level. Implement with a hard recursion depth cap and step budget to prevent infinite loops. See also: goal-decomposition, least-to-most-prompting, hierarchical-agents.
Real-world Use Case
- Hierarchical document summarization (summarize sections, then sections-of-sections).
- Recursive code analysis (analyze functions, then call sites, then callers).
- Tree-structured planning where sub-plans compose into a master plan.
Source
📌 TL;DR
Some problems are recursive — solve them recursively, with a depth cap and a base case.
Advantages
- Naturally handles problems with recursive structure without flattening them.
- Each recursive call has a clean, scoped context — no context bloat from the full problem.
- Parallelizable at each recursion level for independent sub-problems.
Disadvantages
- Recursion depth must be capped — unbounded recursion = unbounded cost.
- Combining sub-results is non-trivial and often requires careful merge logic.
- Debugging recursive call trees is significantly harder than linear pipelines.