RLM (Recursive Language Model) Reasoning Pattern
Based on Zhang et al., MIT CSAIL (arXiv:2512.24601)
Core Principle: Context Outside, Not Inside
Never load entire large files into context. Instead, keep data "outside" and access selectively.
4-Step Reasoning Pattern
1. PROBE (Explore)
Search for relevant areas using keywords before reading:
code
Grep for keywords to find relevant lines Glob to find related files by pattern
Example:
code
Grep(pattern="authentication", path="src/") Glob(pattern="**/auth*.py")
2. EXTRACT (Load Selectively)
Only read the specific sections you need:
code
Read with offset/limit for specific line ranges Load only chunks that contain matches
Example:
code
Read(file_path="src/auth/login.py", offset=50, limit=100)
3. CONFIRM (Verify)
Before answering, verify information against the source:
code
Re-check that found information matches the question Validate references actually exist Cross-reference multiple sources if needed
4. ANSWER (Respond)
Provide verified response based on confirmed evidence.
When to Apply This Pattern
| Situation | Action |
|---|---|
| File > 1000 lines | PROBE first with Grep, never Read entire |
| Complex analysis | Delegate to Task tool sub-agent |
| Code generation | Verify imports/references exist with Grep |
| Multiple files | Use Glob to find, then selective Read |
Anti-Patterns (Avoid)
code
# BAD: Loading entire file
Read("large_file.py") # Don't do this!
# GOOD: Search first, then selective read
Grep("function_name", "src/")
Read("src/file.py", offset=150, limit=50)
Sub-Agent Delegation
For complex multi-step analysis, use Task tool:
code
Task(
subagent_type="Explore",
prompt="Find all authentication-related code and summarize the flow"
)
Verification Checklist
Before providing an answer:
- • Did I search before reading?
- • Did I read only necessary sections?
- • Did I verify references exist?
- • Is my answer based on confirmed evidence?
Additional Resources
- •For Python implementation details, see rlm_agent.py
- •For detailed API reference, see REFERENCE.md
Quick Commands
Run the RLM agent directly:
bash
python ~/.claude/skills/rlm-reasoning/scripts/rlm_query.py "your question" /path/to/file