# Recursive Language Model

> The model calls itself to solve sub-problems, recursively.

- **Category**: Agentic AI
- **Subcategory**: Reasoning
- **Canonical URL**: https://designpattern.fyi/patterns/recursive_language_model/

---

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



## Use Cases
- 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.






## Trade-offs


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




### Considerations & Drawbacks

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







---
**Reference**: [Original Source](https://www.agentpatternscatalog.org/patterns/recursive-language-model/)

