Defined in: packages/components/src/agents/rlm/RLMCore.ts:144
RLM Core - Recursive Language Model with REPL environment Based on the paper arXiv:2512.24601
Handles long contexts by allowing the LLM to generate code that orchestrates multiple sub-LLM calls for chunking and analysis tasks.
Supports true recursion: Sub-LLM can itself be an RLM instance with REPL capabilities.
Example
const rlm = new RLMCore(rootLLM, subLLM, 2); // depth=2 enables recursive RLM
const result = await rlm.executeStream({
context: fileSystemContext,
query: "Analyze this codebase architecture"
});
Implements
Constructors
Constructor
new RLMCore(
rootLLM,
subLLM,
maxDepth?,
sharedContext?,
customPrompt?,
options?
): RLMCore;
Defined in: packages/components/src/agents/rlm/RLMCore.ts:172
Create an RLM instance with optional recursive nesting
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
rootLLM |
LLMProvider |
undefined |
LLM for generating orchestration code at this level |
subLLM |
LLMProvider |
undefined |
LLM for answering sub-queries (can be another RLM for recursion) |
maxDepth? |
number |
1 |
Maximum nesting depth (default: 1) |
sharedContext? |
FileSystemContext |
undefined |
Shared FileSystemContext across all recursion levels (internal use) |
customPrompt? |
| string | CustomPromptBuilder |
undefined |
Additional task-specific prompt (appended to default) |
options? |
RLMCoreOptions |
{} |
Additional options, such as verbose |
Returns
RLMCore
Remarks
When maxDepth > 1, the constructor automatically creates nested RLM instances:
- depth=2: Root RLM → Sub RLM → Base LLM
- depth=3: Root RLM → Sub RLM → Sub RLM → Base LLM
All nested RLMs share the same FileSystemContext (if provided) to avoid redundant file reads.
For most tasks, depth=1 is sufficient. Use a greater depth only for complex multi-layer analysis.
Methods
execute()
execute(input): Promise<RLMResult>;
Defined in: packages/components/src/agents/rlm/RLMCore.ts:199
Execute RLM with given context and query
Parameters
| Parameter | Type |
|---|---|
input |
RLMInput |
Returns
Promise<RLMResult>
executeStream()
executeStream(input): AsyncGenerator<RLMChunk>;
Defined in: packages/components/src/agents/rlm/RLMCore.ts:220
Execute RLM with streaming output
Parameters
| Parameter | Type |
|---|---|
input |
RLMInput |
Returns
AsyncGenerator<RLMChunk>
generate()
generate(prompt): Promise<string>;
Defined in: packages/components/src/agents/rlm/RLMCore.ts:708
Implement LLMProvider.generate - allows RLM to be used as sub-LLM This enables true recursive RLM where Sub-LLM is itself an RLM instance
Parameters
| Parameter | Type |
|---|---|
prompt |
string |
Returns
Promise<string>
Implementation of
generateStream()
generateStream(prompt): AsyncGenerator<string>;
Defined in: packages/components/src/agents/rlm/RLMCore.ts:718
Implement LLMProvider.generateStream - streaming variant for recursive RLM
Parameters
| Parameter | Type |
|---|---|
prompt |
string |
Returns
AsyncGenerator<string>