massimodeluisa/recursive-decomposition-skill / skills/recursive-decomposition
recursive-decomposition
VerifiedDecompose dense codebase-wide, multi-document, PDF, and aggregation work even when the input fits the context window, following Recursive Language Models (Zhang, Kraska, Khattab, 2025). Use when the user asks to analyse all files, a whole repo, all docs, large PDFs, or to aggregate or multi-hop across scattered sources. Skip one file, one function, a single needle, or a one-page PDF conversion. Triggers: long context, context rot, large codebase, many files, all files, big document, multi-document, PDF, aggregate, summarize everything, codebase-wide, multi-hop, recursive, sub-agents, map-reduce.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 8.5 KB |
| evals/README.md | markdown | 2.3 KB |
| evals/evals.json | config | 1.2 KB |
| evals/gold/pdf-corpus.json | config | 253 B |
| evals/trigger-queries.json | config | 3.0 KB |
| references/codebase-analysis.md | markdown | 2.9 KB |
| references/cost-analysis.md | markdown | 3.8 KB |
| references/document-aggregation.md | markdown | 3.5 KB |
| references/rlm-strategies.md | markdown | 4.9 KB |
references/rlm-strategies.md
View on GitHub# RLM decomposition strategies
Strategies taken from Recursive Language Models (Zhang, Kraska, Khattab, arXiv:2512.24601). Numbers below are from that paper, v3.
## Context rot
Quality falls as the prompt gets longer. The paper (citing Hong et al., 2025) calls this context rot:
- retrieval misses
- details dropped in long documents
- invented links between distant passages
- weaker reasoning over a large evidence set
The fix in the paper is to keep the active window small and reach the rest of the prompt through tools: peek, slice, recurse.
## What models actually do
Section 5 of the paper describes how current models behave as RLMs: probe the input, then split the work into sub-calls. The patterns below are the ones this skill turns into a protocol.
### Filter with code before you read
Narrow the set with a pattern, then open what remains.
```text
pattern = (database|connection|auth)
keep files whose content matches pattern
read only those files
```
In an agent session: grep before read, glob to cut the file set, then chain filters (type, then keyword, then meaning).
### Chunk
Uniform: split a 1000-line file into ten 100-line windows, merge with overlap.
By meaning: one function, class, or section per chunk. Prefer a complete unit over equal sizes.
By keyword: all error-handling in one batch, all API definitions in another, each with a prompt that matches that batch.
### Recurse
This skill uses one level only. Sub-agents answer; they do not spawn sub-agents.
```text
main agent
├── sub-agent (chunk A)
├── sub-agent (chunk B)
└── sub-agent (chunk C)
then merge
```
The paper's OOLONG-Pairs numbers move with recursion depth (GPT-5: 58.0% F1 at depth=1, 76.0% at depth=3). Extra depth is not free: Qwen3-Coder-480B-A35B often makes syntax errors, and those errors spread into sub-calls, so depth 2 and 3 can score worse than depth 1 on that model (arXiv:2512.24601, Table 1 and Figure 4b). This skill stays at depth 1.
### Verify by reading less
1. Write an answer from the large pass.
2. Pull the cited locations.
3. Re-read only those locations.
4. Check the answer against that small window.
5. If it disagrees, re-read the disagreement, not the whole corpus.
### Build long output in pieces
Generate each section on its own, store the pieces, then stitch. That is how an RLM writes past the model's output limit (paper, section 5).
## Size limits
These match the skill body. They are session limits, not paper results.
- Files over 2,000 lines or 50 KB: read by line range, never in one shot.
- PDFs over 100 pages or 30 MB: metadata or a split, not a full ingest.
- Stay under about 30k tokens in the active window when you can.
## Task shape
| Shape | Typical job | Approach |
|-------|-------------|----------|
| O(1) | one needle | filter until the set is small, then read |
| O(n) | count, list, summarise every item | map-reduce over disjoint batches |
| O(n²) | pairwise relations | blocked pairs, sample first if the full grid is too large |
| O(log n) | search in ordered or nested data | divide and conquer |
Figure 1 in the paper scales S-NIAH, OOLONG, and OOLONG-Pairs from 2^13 to 2^20 tokens. GPT-5 drops faster on the linear and quadratic tasks. Past 2^14 tokens the RLM beats GPT-5 on those plots.
## Model differences (from the paper)
GPT-5 as an RLM: fewer syntax errors in trajectories, more stable as depth increases (Table 1).
Qwen3-Coder-480B-A35B as an RLM: more syntax errors even on correct runs (Figure 4b). Extra recursion depth can hurt. Prefer coarser batches and a hard depth cap with this class of model.
In-context decomposition examples in the system prompt change the first split and the final score on OOLONG, even when the example is from another task (Figure 4a). Put a concrete split in the sub-agent brief.
## Failure modes
Infinite recursion: this skill is depth 1; sub-agents must not launch sub-agents.
The same span processed twice: partition once into disjoint batches; deduplicate before merge.
Sub-agent missing the question or the schema: the brief is the whole context that agent gets.
Merged answer contradicts the files: spot-check cited lines; re-read the conflict.
## Numbers from Table 1 (GPT-5 unless noted)
| Task | Without RLM | RLM (depth=1) |
|------|-------------|----------------|
| BrowseComp-Plus, 6 to 11M tokens | compaction 70.5%; GPT-5 base hits the context limit | 91.3% at $0.99 average |
| OOLONG | GPT-5 44.0 | 56.0 (+28.4% vs base; Qwen3-Coder +33.3%) |
| OOLONG-Pairs | F1 0.1 | F1 58.0 (76.0 at depth=3) |
A linear extrapolation of GPT-5-mini ingesting 6 to 11M tokens is $1.50 to $2.75. Median RLM cost is comparable or lower than the base model; the average can rise on long outlier trajectories.
## Skip decomposition when
- the job is one file, one function, or a single needle
- the answer sits in one obvious range
- latency matters more than completeness
- coordination would cost more than a direct read
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |