Skip to content

feat(core): implement Recursive Language Model (RLM) support - #6795

Closed
soya-miruku wants to merge 4 commits into
anomalyco:devfrom
soya-miruku:claude/recursive-language-models-ZbaHg
Closed

soya-miruku wants to merge 4 commits into
anomalyco:devfrom
soya-miruku:claude/recursive-language-models-ZbaHg

Conversation

@soya-miruku

Copy link
Copy Markdown

Add experimental RLM infrastructure based on the paper "Recursive Language Models" (Zhang et al., 2025). This allows processing arbitrarily long contexts by treating prompts as part of an external Python REPL environment.

Key additions:

  • repl tool: Persistent Python REPL with llm_query() for recursive sub-calls
  • rlm agent: Specialized subagent for long-context processing
  • rlm-sub agent: Hidden subagent for handling recursive LLM queries
  • FINAL()/FINAL_VAR() response patterns for returning answers

The RLM approach enables:

  • Processing contexts 10-100x beyond normal context windows
  • Programmatic examination and decomposition of long inputs
  • Recursive self-invocation over context snippets
  • Code-based filtering before semantic analysis

Enable via: experimental.repl_tool = true in config

claude added 4 commits January 4, 2026 01:32
Add experimental RLM infrastructure based on the paper "Recursive Language
Models" (Zhang et al., 2025). This allows processing arbitrarily long
contexts by treating prompts as part of an external Python REPL environment.

Key additions:
- repl tool: Persistent Python REPL with llm_query() for recursive sub-calls
- rlm agent: Specialized subagent for long-context processing
- rlm-sub agent: Hidden subagent for handling recursive LLM queries
- FINAL()/FINAL_VAR() response patterns for returning answers

The RLM approach enables:
- Processing contexts 10-100x beyond normal context windows
- Programmatic examination and decomposition of long inputs
- Recursive self-invocation over context snippets
- Code-based filtering before semantic analysis

Enable via: experimental.repl_tool = true in config
- Add llm_query_parallel() for concurrent sub-agent execution
- Add llm_map() for mapping prompts over items with auto-batching
- Add probe_context() for analyzing context metadata
- Add smart_chunk() for semantic-aware text splitting
- Add plan_decomposition() for LLM-assisted strategy planning
- Update TypeScript handler to execute batch queries in parallel
- Enhance prompts with comprehensive documentation of new features

The model now decides parallelism based on data characteristics,
spawning multiple sub-agents simultaneously via Promise.all().
- Add RLM system prompt instructions for primary agent
- Create rlm-auto.txt with guidance on when/how to use REPL tool
- Add SystemPrompt.rlm() to conditionally include RLM instructions
- Instructions included when experimental.repl_tool is enabled
- Primary agent can now automatically use REPL for large contexts
- Create RLM module for context analysis and detection
- Auto-detect when input context exceeds 100KB threshold
- Inject RLM activation prompt when large context detected
- Emit 'rlm.activated' event for TUI visibility
- Model now receives explicit guidance to use REPL tool

When large context is detected, the model sees:
<rlm-context-loaded>
A large context (XXkb) has been loaded...
Use the REPL tool - do NOT try to process directly.
</rlm-context-loaded>
@soya-miruku soya-miruku closed this Jan 4, 2026
@tschmidt-code

Copy link
Copy Markdown

@soya-miruku I was just about to post this as a feature request. Do you have any info on why this was closed?

@fire17

fire17 commented Jan 16, 2026

Copy link
Copy Markdown

Has anyone successfully adopted RLMs to opencode ?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants