@elizaos/plugin-rlm 2.0.0-beta.1 → 2.0.3-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shaw Walters and elizaOS Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,211 +1,119 @@
1
- # plugin-rlm
1
+ # @elizaos/plugin-rlm
2
2
 
3
- RLM (Recursive Language Model) plugin for elizaOS.
3
+ RLM (Recursive Language Model) plugin for elizaOS. Enables Eliza agents to process arbitrarily long contexts through recursive self-calls in a Python REPL environment.
4
4
 
5
- ## Overview
5
+ ## What it does
6
6
 
7
- This plugin integrates **Recursive Language Models (RLMs)** into elizaOS, enabling LLMs to process arbitrarily long contexts through recursive self-calls in a REPL environment.
7
+ Standard LLMs degrade on long inputs ("context rot"). This plugin integrates the RLM technique ([arXiv:2512.24601](https://arxiv.org/abs/2512.24601)) which processes long prompts by:
8
8
 
9
- RLMs represent a breakthrough in long-context processing that:
10
- - Handles inputs **up to 2 orders of magnitude beyond** standard model context windows
11
- - Outperforms vanilla GPT-5 on long-context benchmarks using smaller models
12
- - Uses strategies like **Peeking**, **Grepping**, **Partition+Map**, and **Summarization**
9
+ 1. Storing the full input in a Python REPL environment.
10
+ 2. Letting the model **Peek**, **Grep**, **Partition**, **Map**, and **Summarize** over the data in multiple iterations.
11
+ 3. Returning a final answer once the model is satisfied.
13
12
 
14
- ### Reference
13
+ This allows processing of inputs far beyond a model's native context window using smaller, cheaper models.
15
14
 
16
- - **Paper**: [Recursive Language Models](https://arxiv.org/abs/2512.24601) (arXiv:2512.24601)
17
- - **Authors**: Alex L. Zhang, Tim Kraska, Omar Khattab (MIT CSAIL)
18
- - **Official Implementation**: [github.com/alexzhang13/rlm](https://github.com/alexzhang13/rlm)
15
+ When the Python backend is not installed the plugin still loads, but model calls fail explicitly instead of returning fallback responses.
19
16
 
20
- ## Installation
21
- # Optional: Install RLM backend
22
- pip install git+https://github.com/alexzhang13/rlm.git
23
- ```
24
-
25
- ### TypeScript
26
-
27
- ```bash
28
- cd plugins/plugin-rlm
29
- npm install
30
- npm run build
31
- ```
32
- ## Configuration
17
+ ## Capabilities added
33
18
 
34
- The plugin reads configuration from environment variables:
19
+ The plugin registers model handlers for:
35
20
 
36
- | Variable | Default | Description |
37
- |----------|---------|-------------|
38
- | `ELIZA_RLM_BACKEND` | `gemini` | LLM backend (`openai`, `anthropic`, `gemini`, `groq`, `openrouter`) |
39
- | `ELIZA_RLM_ENV` | `local` | Execution environment (`local`, `docker`, `modal`, `prime`) |
40
- | `ELIZA_RLM_MAX_ITERATIONS` | `4` | Maximum REPL iterations |
41
- | `ELIZA_RLM_MAX_DEPTH` | `1` | Maximum recursion depth |
42
- | `ELIZA_RLM_VERBOSE` | `false` | Enable verbose logging |
43
- | `ELIZA_RLM_PYTHON_PATH` | `python` | Python executable path (TypeScript/Rust IPC) |
44
- | `ELIZA_RLM_MAX_RETRIES` | `3` | Maximum retry attempts for transient failures |
45
- | `ELIZA_RLM_RETRY_DELAY` | `1000` | Base delay (ms) between retries |
46
- | `ELIZA_RLM_RETRY_MAX_DELAY` | `30000` | Maximum delay (ms) between retries |
21
+ - `ModelType.TEXT_SMALL`
22
+ - `ModelType.TEXT_LARGE`
23
+ - `ModelType.TEXT_REASONING_SMALL`
24
+ - `ModelType.TEXT_REASONING_LARGE`
25
+ - `ModelType.TEXT_COMPLETION`
47
26
 
48
- ### Retry Logic
27
+ Any `runtime.useModel(...)` call for these types is routed through the RLM backend.
49
28
 
50
- The plugin includes automatic retry with exponential backoff for transient failures. Retries are triggered for:
51
- - Connection timeouts
52
- - Rate limit errors (429)
53
- - Temporary server errors (503)
54
- - Network connection failures
55
-
56
- **Assumptions and Limitations:**
57
- - Retry detection uses substring matching on error messages (e.g., "timeout", "connection", "rate limit")
58
- - Different LLM backends may use different error message formats
59
- - Non-transient errors (e.g., authentication, validation) are NOT retried
29
+ ## Installation
60
30
 
61
- ### Metrics (TypeScript)
31
+ ```bash
32
+ # Install the TypeScript plugin
33
+ bun add @elizaos/plugin-rlm
62
34
 
63
- The TypeScript client provides metrics for monitoring:
35
+ # Install the Python backend (required for inference)
36
+ pip install git+https://github.com/alexzhang13/rlm.git
37
+ ```
64
38
 
65
- ```typescript
66
- const client = new RLMClient();
39
+ ## Enable the plugin
67
40
 
68
- // Get current metrics
69
- const metrics = client.getMetrics();
70
- console.log(metrics.totalRequests, metrics.successfulRequests);
41
+ Add `@elizaos/plugin-rlm` to your character's plugin list. No other registration is required.
71
42
 
72
- // Register callback for real-time metrics
73
- client.onMetrics((metrics) => {
74
- // Send to Prometheus, Datadog, etc.
75
- exporter.recordGauge('rlm_latency_p95', metrics.p95LatencyMs);
76
- });
77
- ```
43
+ ## Configuration
78
44
 
79
- Available metrics:
80
- - `totalRequests`, `successfulRequests`, `failedRequests`, `stubResponses`
81
- - `totalRetries` - total retry attempts across all requests
82
- - `averageLatencyMs`, `p95LatencyMs` - latency percentiles (rolling 1000 samples)
83
- - `lastRequestTimestamp`, `lastErrorTimestamp`, `lastError`
45
+ All settings are read from environment variables.
84
46
 
85
- ### Backend API Keys
47
+ | Variable | Default | Description |
48
+ |---|---|---|
49
+ | `ELIZA_RLM_BACKEND` | `gemini` | LLM backend: `openai`, `anthropic`, `gemini`, `groq`, `openrouter` |
50
+ | `ELIZA_RLM_ENV` | `local` | Execution environment: `local`, `docker`, `modal`, `prime` |
51
+ | `ELIZA_RLM_MAX_ITERATIONS` | `4` | Maximum REPL iterations per call |
52
+ | `ELIZA_RLM_MAX_DEPTH` | `1` | Maximum recursion depth |
53
+ | `ELIZA_RLM_VERBOSE` | `false` | Enable verbose logging |
54
+ | `ELIZA_RLM_PYTHON_PATH` | `python` | Python executable path |
55
+ | `ELIZA_RLM_MAX_RETRIES` | `3` | Retry attempts for transient failures |
56
+ | `ELIZA_RLM_RETRY_BASE_DELAY` | `1000` | Base retry delay (ms, exponential backoff) |
57
+ | `ELIZA_RLM_RETRY_MAX_DELAY` | `30000` | Maximum retry delay (ms) |
58
+ | `ELIZA_RLM_PRICING_JSON` | _(unset)_ | JSON override for model pricing (per 1M tokens) |
86
59
 
87
- Depending on your chosen backend, set the appropriate API key:
60
+ Backend API keys are forwarded to the Python subprocess via the environment. Set whichever key matches your chosen backend:
88
61
 
89
62
  ```bash
90
- # For OpenAI backend
63
+ export GEMINI_API_KEY=... # default backend
91
64
  export OPENAI_API_KEY=sk-...
92
-
93
- # For Anthropic backend
94
65
  export ANTHROPIC_API_KEY=sk-ant-...
95
-
96
- # For Google Gemini backend
97
- export GEMINI_API_KEY=...
98
66
  ```
99
67
 
100
- ## Usage
101
- # The plugin is auto-loaded by elizaOS runtime
102
- # Or use the client directly:
103
- client = RLMClient()
104
- result = await client.infer("Process this very long text...")
105
- print(result.text)
106
- ```
68
+ ## Backend availability
69
+
70
+ When the Python backend is unavailable (not installed, wrong `ELIZA_RLM_PYTHON_PATH`, startup failure), `RLMClient.infer()` throws. Use `RLMClient.getStatus()` to check availability before routing production model calls through RLM.
107
71
 
108
- ### TypeScript
72
+ ## Metrics
109
73
 
110
74
  ```typescript
111
- import { rlmPlugin, RLMClient } from "@elizaos/plugin-rlm";
75
+ import { RLMClient } from "@elizaos/plugin-rlm";
112
76
 
113
- // Plugin is auto-registered when loaded
114
- // Or use client directly:
115
77
  const client = new RLMClient();
116
- const result = await client.infer("Process this very long text...");
117
- console.log(result.text);
78
+ const metrics = client.getMetrics();
79
+ // metrics.totalRequests, .successfulRequests, .failedRequests,
80
+ // .totalRetries, .averageLatencyMs, .p95LatencyMs
81
+
82
+ client.onMetrics((m) => {
83
+ // called after every request
84
+ });
118
85
  ```
119
- ## Model Types
120
86
 
121
- The plugin registers handlers for the following model types:
87
+ ## Trajectory logging
122
88
 
123
- | Model Type | Description |
124
- |------------|-------------|
125
- | `TEXT_SMALL` | Small text generation |
126
- | `TEXT_LARGE` | Large text generation |
127
- | `TEXT_REASONING_SMALL` | Small reasoning model |
128
- | `TEXT_REASONING_LARGE` | Large reasoning model |
129
- | `TEXT_COMPLETION` | Text completion |
130
- | `TEXT_RLM_LARGE` | Explicit RLM mode |
131
- | `TEXT_RLM_REASONING` | Explicit RLM with reasoning |
89
+ `trajectory-integration.ts` provides `RLMTrajectoryIntegration`, which wraps an
90
+ `RLMClient` with step-level cost tracking and optional logging to an external
91
+ `TrajectoryLogger` (compatible with `plugin-trajectory-logger`). It is an
92
+ internal source module the package's public entrypoint exports only
93
+ `rlmPlugin`, `RLMClient`, `configFromEnv`, `resetClient`,
94
+ `DEFAULT_CONFIG`, `ENV_VARS`, and the RLM types.
132
95
 
133
96
  ## Architecture
134
97
 
135
98
  ```
136
99
  plugins/plugin-rlm/
137
- ├── README.md # This file
138
- └── typescript/
139
- ├── package.json
140
- ├── types.ts # TypeScript types
141
- ├── client.ts # RLMClient
142
- ├── index.ts # Plugin definition
143
- └── __tests__/
144
- ├── plugin.test.ts # Unit tests
145
- └── integration.test.ts # Integration tests
146
- ```
147
-
148
- ### Cross-Language Design
149
-
150
- Since the official RLM library is Python-only:
151
-
152
- 1. **Python**: Direct integration with the `rlm` library
153
- 2. **TypeScript**: IPC via Python subprocess with JSON-RPC protocol
154
- 3. **Rust**: IPC via Python subprocess with JSON-RPC protocol
155
-
156
- All implementations fall back to **stub mode** when the RLM backend is unavailable, returning safe placeholder responses without throwing errors.
157
-
158
- ## Stub Mode
159
-
160
- When the RLM backend is not installed or unavailable, the plugin operates in stub mode:
161
-
162
- This allows the plugin to be loaded and used without the RLM dependency for testing and development purposes.
163
-
164
- ## Testing
165
- ### TypeScript
166
-
167
- ```bash
168
- cd plugins/plugin-rlm
169
- npm install
170
- npm test
100
+ ├── index.ts # Plugin definition and singleton client management
101
+ ├── client.ts # RLMClient — Python IPC, retry, metrics
102
+ ├── server.ts # RLMServer — TCP IPC server (wraps RLMClient)
103
+ ├── cost.ts # Cost estimation, pricing table, strategy detection
104
+ ├── types.ts # All shared types and ENV_VARS constants
105
+ └── trajectory-integration.ts # Step-level cost + trajectory logging
171
106
  ```
172
- ## How RLM Works
173
-
174
- RLMs treat long prompts as external objects stored in a Python REPL environment. Instead of feeding the entire input to the model, the LM:
175
-
176
- 1. **Peeks** at portions of the context
177
- 2. **Greps** for relevant information using regex
178
- 3. **Partitions** the context into manageable chunks
179
- 4. **Maps** recursive LM calls over chunks
180
- 5. **Summarizes** and aggregates results
181
-
182
- This approach addresses "context rot" - the degradation of model performance as prompt length increases.
183
-
184
- ### Example: Long Context Processing
185
-
186
- ## Performance
187
-
188
- Based on the original paper's benchmarks:
189
-
190
- | Benchmark | GPT-5 | RLM(GPT-5-mini) | Improvement |
191
- |-----------|-------|-----------------|-------------|
192
- | OOLONG (132k) | 30% | 64% | +114% |
193
- | OOLONG (263k) | 31% | 46% | +49% |
194
- | BrowseComp-Plus | ~60% | 100% | +67% |
195
-
196
- RLM using GPT-5-mini **outperforms vanilla GPT-5** while being cheaper per query.
197
107
 
198
108
  ## Limitations
199
109
 
200
- - **Latency**: RLM calls take longer due to recursive processing
201
- - **Cost**: Multiple LLM calls may increase API costs
202
- - **Python Dependency**: TypeScript and Rust rely on Python IPC
203
- - **No Streaming**: Streaming is not yet supported in RLM
204
-
205
- ## Contributing
206
-
207
- Contributions are welcome! Please see the main elizaOS repository for contribution guidelines.
110
+ - **Python dependency:** Real inference requires a Python process with the `rlm` library installed.
111
+ - **No streaming:** All inference is synchronous (returns full text).
112
+ - **Latency:** Multiple recursive LLM calls are slower than a single call.
113
+ - **Token counting:** Uses a `text.length / 4` approximation; inaccurate for non-ASCII.
114
+ - **Node only:** Does not run in browser or mobile runtimes.
208
115
 
209
- ## License
116
+ ## Reference
210
117
 
211
- MIT
118
+ - Paper: [Recursive Language Models](https://arxiv.org/abs/2512.24601) — Zhang, Kraska, Khattab (MIT CSAIL)
119
+ - Official Python library: [github.com/alexzhang13/rlm](https://github.com/alexzhang13/rlm)
package/package.json CHANGED
@@ -1,17 +1,24 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-rlm",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.3-beta.3",
4
4
  "description": "RLM (Recursive Language Model) plugin for elizaOS - enables processing of arbitrarily long contexts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./*.css": "./dist/*.css",
14
+ "./*": {
15
+ "types": "./dist/*.d.ts",
16
+ "import": "./dist/*.js",
17
+ "default": "./dist/*.js"
12
18
  }
13
19
  },
14
20
  "files": [
21
+ "registry-entry.json",
15
22
  "dist",
16
23
  "src"
17
24
  ],
@@ -21,8 +28,8 @@
21
28
  "test": "vitest run --config vitest.config.ts",
22
29
  "test:watch": "vitest",
23
30
  "lint": "bunx @biomejs/biome check --write --unsafe .",
24
- "lint:fix": "biome check --write .",
25
- "typecheck": "tsc --noEmit",
31
+ "lint:fix": "bunx @biomejs/biome check --write .",
32
+ "typecheck": "tsgo --noEmit",
26
33
  "lint:check": "bunx @biomejs/biome check .",
27
34
  "format": "bunx @biomejs/biome format --write .",
28
35
  "format:check": "bunx @biomejs/biome format ."
@@ -44,7 +51,7 @@
44
51
  "directory": "plugins/plugin-rlm"
45
52
  },
46
53
  "dependencies": {
47
- "@elizaos/core": "2.0.0-beta.1"
54
+ "@elizaos/core": "2.0.3-beta.3"
48
55
  },
49
56
  "devDependencies": {
50
57
  "@biomejs/biome": "^2.4.14",
@@ -54,7 +61,7 @@
54
61
  "vitest": "^4.0.0"
55
62
  },
56
63
  "peerDependencies": {
57
- "@elizaos/core": "2.0.0-beta.1"
64
+ "@elizaos/core": "2.0.3-beta.3"
58
65
  },
59
66
  "engines": {
60
67
  "node": ">=24.0.0"
@@ -70,5 +77,6 @@
70
77
  },
71
78
  "publishConfig": {
72
79
  "access": "public"
73
- }
80
+ },
81
+ "gitHead": "f54b0f4eaed317d59fa7dbcdce20f4cdb0734420"
74
82
  }
@@ -0,0 +1,26 @@
1
+ {
2
+ "id": "rlm",
3
+ "name": "Rlm",
4
+ "description": "RLM (Recursive Language Model) plugin for elizaOS - enables processing of arbitrarily long contexts",
5
+ "npmName": "@elizaos/plugin-rlm",
6
+ "version": "2.0.0-beta.0",
7
+ "source": "bundled",
8
+ "tags": ["rlm", "recursive-language-model", "llm", "agent", "long-context"],
9
+ "config": {},
10
+ "render": {
11
+ "visible": true,
12
+ "pinTo": [],
13
+ "style": "card",
14
+ "icon": "RefreshCw",
15
+ "group": "documents",
16
+ "groupOrder": 6,
17
+ "actions": ["enable", "configure"]
18
+ },
19
+ "resources": {
20
+ "homepage": "https://github.com/elizaos/eliza#readme",
21
+ "repository": "https://github.com/elizaos/eliza"
22
+ },
23
+ "dependsOn": [],
24
+ "kind": "plugin",
25
+ "subtype": "documents"
26
+ }
package/dist/index.d.ts DELETED
@@ -1,168 +0,0 @@
1
- import { Plugin } from '@elizaos/core';
2
-
3
- /** Types for the RLM (Recursive Language Model) plugin. */
4
- type RLMBackend = "openai" | "anthropic" | "gemini" | "groq" | "openrouter";
5
- type RLMEnvironment = "local" | "docker" | "modal" | "prime";
6
- interface RLMConfig {
7
- backend: RLMBackend;
8
- backendKwargs: Record<string, string>;
9
- environment: RLMEnvironment;
10
- maxIterations: number;
11
- maxDepth: number;
12
- verbose: boolean;
13
- pythonPath: string;
14
- maxRetries?: number;
15
- retryBaseDelay?: number;
16
- retryMaxDelay?: number;
17
- }
18
- interface RLMMessage {
19
- role: "user" | "assistant" | "system";
20
- content: string;
21
- }
22
- interface RLMMetadata {
23
- stub: boolean;
24
- iterations?: number;
25
- depth?: number;
26
- error?: string;
27
- }
28
- interface RLMResult {
29
- text: string;
30
- metadata: RLMMetadata;
31
- }
32
- interface RLMInferOptions {
33
- /** Model identifier for this request */
34
- model?: string;
35
- /** Maximum tokens to generate */
36
- maxTokens?: number;
37
- /** Sampling temperature */
38
- temperature?: number;
39
- /** Top-p sampling parameter */
40
- topP?: number;
41
- /** Stop sequences */
42
- stopSequences?: string[];
43
- /** User identifier for tracking */
44
- user?: string;
45
- /** Enable streaming (not yet supported by RLM) */
46
- stream?: boolean;
47
- /** Override max iterations for this request */
48
- maxIterations?: number;
49
- /** Override max recursion depth for this request */
50
- maxDepth?: number;
51
- /** Override root model for this request */
52
- rootModel?: string;
53
- /** Override subcall model for this request */
54
- subcallModel?: string;
55
- /** Enable trajectory logging for this request */
56
- logTrajectories?: boolean;
57
- /** Enable cost tracking for this request */
58
- trackCosts?: boolean;
59
- }
60
- interface RLMStatusResponse {
61
- available: boolean;
62
- backend: string;
63
- environment: string;
64
- maxIterations: number;
65
- maxDepth: number;
66
- }
67
- interface GenerateTextParams {
68
- prompt?: string;
69
- system?: string;
70
- messages?: RLMMessage[];
71
- model?: string;
72
- maxTokens?: number;
73
- temperature?: number;
74
- topP?: number;
75
- stopSequences?: string[];
76
- user?: string;
77
- stream?: boolean;
78
- }
79
- declare const DEFAULT_CONFIG: RLMConfig;
80
- interface RLMMetrics {
81
- totalRequests: number;
82
- successfulRequests: number;
83
- failedRequests: number;
84
- stubResponses: number;
85
- totalRetries: number;
86
- averageLatencyMs: number;
87
- p95LatencyMs: number;
88
- lastRequestTimestamp: number;
89
- lastErrorTimestamp?: number;
90
- lastError?: string;
91
- }
92
- type MetricsCallback = (metrics: RLMMetrics) => void;
93
- declare const ENV_VARS: {
94
- readonly BACKEND: "ELIZA_RLM_BACKEND";
95
- readonly ENVIRONMENT: "ELIZA_RLM_ENV";
96
- readonly MAX_ITERATIONS: "ELIZA_RLM_MAX_ITERATIONS";
97
- readonly MAX_DEPTH: "ELIZA_RLM_MAX_DEPTH";
98
- readonly VERBOSE: "ELIZA_RLM_VERBOSE";
99
- readonly PYTHON_PATH: "ELIZA_RLM_PYTHON_PATH";
100
- readonly MAX_RETRIES: "ELIZA_RLM_MAX_RETRIES";
101
- readonly RETRY_BASE_DELAY: "ELIZA_RLM_RETRY_BASE_DELAY";
102
- readonly RETRY_MAX_DELAY: "ELIZA_RLM_RETRY_MAX_DELAY";
103
- };
104
-
105
- /** RLM Client - communicates with Python subprocess via JSON-RPC IPC. */
106
-
107
- interface Logger {
108
- info: (message: string, ...args: unknown[]) => void;
109
- warn: (message: string, ...args: unknown[]) => void;
110
- error: (message: string, ...args: unknown[]) => void;
111
- debug: (message: string, ...args: unknown[]) => void;
112
- }
113
- declare function configFromEnv(env?: NodeJS.ProcessEnv): RLMConfig;
114
- declare class RLMClient {
115
- private config;
116
- private process;
117
- private reader;
118
- private requestId;
119
- private pendingRequests;
120
- private isReady;
121
- private isAvailable;
122
- private hasStartupError;
123
- private logger;
124
- private metrics;
125
- private static readonly MAX_LATENCY_SAMPLES;
126
- private latencies;
127
- private latencyIndex;
128
- private latencyCount;
129
- private metricsCallback;
130
- constructor(config?: Partial<RLMConfig>, logger?: Logger, strictValidation?: boolean);
131
- private startServer;
132
- private waitForReady;
133
- private handleMessage;
134
- private sendRequest;
135
- private ensureServer;
136
- get available(): boolean;
137
- getMetrics(): RLMMetrics;
138
- onMetrics(callback: MetricsCallback): void;
139
- private updateMetrics;
140
- static normalizeMessages(messages: string | RLMMessage[]): RLMMessage[];
141
- infer(messages: string | RLMMessage[], opts?: RLMInferOptions): Promise<RLMResult>;
142
- getStatus(): Promise<RLMStatusResponse>;
143
- shutdown(): Promise<void>;
144
- }
145
- declare function stubResult(error?: string): RLMResult;
146
-
147
- /**
148
- * RLM (Recursive Language Model) plugin for elizaOS.
149
- *
150
- * This plugin integrates Recursive Language Models into elizaOS, enabling
151
- * LLMs to process arbitrarily long contexts through recursive self-calls
152
- * in a REPL environment.
153
- *
154
- * Reference:
155
- * - Paper: https://arxiv.org/abs/2512.24601
156
- * - Implementation: https://github.com/alexzhang13/rlm
157
- */
158
-
159
- /**
160
- * Reset the client singleton. Useful for testing or forced reinitialization.
161
- */
162
- declare function resetClient(): Promise<void>;
163
- /**
164
- * RLM plugin definition.
165
- */
166
- declare const rlmPlugin: Plugin;
167
-
168
- export { DEFAULT_CONFIG, ENV_VARS, type GenerateTextParams, RLMClient, type RLMConfig, type RLMInferOptions, type RLMMessage, type RLMMetadata, type RLMResult, type RLMStatusResponse, configFromEnv, rlmPlugin as default, resetClient, rlmPlugin, stubResult };
package/dist/index.js DELETED
@@ -1,613 +0,0 @@
1
- // index.ts
2
- import {
3
- buildCanonicalSystemPrompt,
4
- logger,
5
- ModelType,
6
- recordLlmCall,
7
- resolveEffectiveSystemPrompt
8
- } from "@elizaos/core";
9
-
10
- // client.ts
11
- import { spawn } from "child_process";
12
- import * as path from "path";
13
- import * as readline from "readline";
14
- import { assertRecordedLlmCall } from "@elizaos/core";
15
-
16
- // types.ts
17
- var DEFAULT_CONFIG = {
18
- backend: "gemini",
19
- backendKwargs: {},
20
- environment: "local",
21
- maxIterations: 4,
22
- maxDepth: 1,
23
- verbose: false,
24
- pythonPath: "python",
25
- maxRetries: 3,
26
- retryBaseDelay: 1e3,
27
- retryMaxDelay: 3e4
28
- };
29
- var ENV_VARS = {
30
- BACKEND: "ELIZA_RLM_BACKEND",
31
- ENVIRONMENT: "ELIZA_RLM_ENV",
32
- MAX_ITERATIONS: "ELIZA_RLM_MAX_ITERATIONS",
33
- MAX_DEPTH: "ELIZA_RLM_MAX_DEPTH",
34
- VERBOSE: "ELIZA_RLM_VERBOSE",
35
- PYTHON_PATH: "ELIZA_RLM_PYTHON_PATH",
36
- MAX_RETRIES: "ELIZA_RLM_MAX_RETRIES",
37
- RETRY_BASE_DELAY: "ELIZA_RLM_RETRY_BASE_DELAY",
38
- RETRY_MAX_DELAY: "ELIZA_RLM_RETRY_MAX_DELAY"
39
- };
40
- var VALID_BACKENDS = [
41
- "openai",
42
- "anthropic",
43
- "gemini",
44
- "groq",
45
- "openrouter"
46
- ];
47
- var VALID_ENVIRONMENTS = ["local", "docker", "modal", "prime"];
48
- var RLMConfigError = class extends Error {
49
- constructor(message) {
50
- super(message);
51
- this.name = "RLMConfigError";
52
- }
53
- };
54
- function validateConfig(config, strict = false) {
55
- const errors = [];
56
- if (config.backend !== void 0 && !VALID_BACKENDS.includes(config.backend)) {
57
- errors.push(`Invalid backend '${config.backend}'. Valid options: ${VALID_BACKENDS.join(", ")}`);
58
- }
59
- if (config.environment !== void 0 && !VALID_ENVIRONMENTS.includes(config.environment)) {
60
- errors.push(
61
- `Invalid environment '${config.environment}'. Valid options: ${VALID_ENVIRONMENTS.join(", ")}`
62
- );
63
- }
64
- if (config.maxIterations !== void 0 && config.maxIterations < 1) {
65
- errors.push("maxIterations must be >= 1");
66
- }
67
- if (config.maxDepth !== void 0 && config.maxDepth < 1) {
68
- errors.push("maxDepth must be >= 1");
69
- }
70
- if (config.maxRetries !== void 0 && config.maxRetries < 0) {
71
- errors.push("maxRetries must be >= 0");
72
- }
73
- if (config.retryBaseDelay !== void 0 && config.retryBaseDelay < 0) {
74
- errors.push("retryBaseDelay must be >= 0");
75
- }
76
- if (config.retryBaseDelay !== void 0 && config.retryMaxDelay !== void 0 && config.retryMaxDelay < config.retryBaseDelay) {
77
- errors.push("retryMaxDelay must be >= retryBaseDelay");
78
- }
79
- if (strict && errors.length > 0) {
80
- throw new RLMConfigError(errors.join("; "));
81
- }
82
- return errors;
83
- }
84
-
85
- // client.ts
86
- var defaultLogger = {
87
- info: (msg, ...args) => console.log(`[RLM] ${msg}`, ...args),
88
- warn: (msg, ...args) => console.warn(`[RLM] ${msg}`, ...args),
89
- error: (msg, ...args) => console.error(`[RLM] ${msg}`, ...args),
90
- debug: (msg, ...args) => console.debug(`[RLM] ${msg}`, ...args)
91
- };
92
- function configFromEnv(env2 = process.env) {
93
- return {
94
- backend: env2[ENV_VARS.BACKEND] ?? DEFAULT_CONFIG.backend,
95
- backendKwargs: {},
96
- environment: env2[ENV_VARS.ENVIRONMENT] ?? DEFAULT_CONFIG.environment,
97
- maxIterations: Number.parseInt(env2[ENV_VARS.MAX_ITERATIONS] ?? "", 10) || DEFAULT_CONFIG.maxIterations,
98
- maxDepth: Number.parseInt(env2[ENV_VARS.MAX_DEPTH] ?? "", 10) || DEFAULT_CONFIG.maxDepth,
99
- verbose: ["1", "true", "yes"].includes((env2[ENV_VARS.VERBOSE] ?? "").toLowerCase()),
100
- pythonPath: env2[ENV_VARS.PYTHON_PATH] ?? DEFAULT_CONFIG.pythonPath,
101
- maxRetries: Number.parseInt(env2[ENV_VARS.MAX_RETRIES] ?? "", 10) || DEFAULT_CONFIG.maxRetries,
102
- retryBaseDelay: Number.parseInt(env2[ENV_VARS.RETRY_BASE_DELAY] ?? "", 10) || DEFAULT_CONFIG.retryBaseDelay,
103
- retryMaxDelay: Number.parseInt(env2[ENV_VARS.RETRY_MAX_DELAY] ?? "", 10) || DEFAULT_CONFIG.retryMaxDelay
104
- };
105
- }
106
- var RLMClient = class _RLMClient {
107
- config;
108
- process = null;
109
- reader = null;
110
- requestId = 0;
111
- pendingRequests = /* @__PURE__ */ new Map();
112
- isReady = false;
113
- isAvailable = false;
114
- hasStartupError = false;
115
- logger;
116
- metrics = {
117
- totalRequests: 0,
118
- successfulRequests: 0,
119
- failedRequests: 0,
120
- stubResponses: 0,
121
- totalRetries: 0,
122
- averageLatencyMs: 0,
123
- p95LatencyMs: 0,
124
- lastRequestTimestamp: 0
125
- };
126
- static MAX_LATENCY_SAMPLES = 1e3;
127
- latencies = new Array(_RLMClient.MAX_LATENCY_SAMPLES).fill(0);
128
- latencyIndex = 0;
129
- latencyCount = 0;
130
- metricsCallback = null;
131
- constructor(config, logger2, strictValidation = false) {
132
- this.config = { ...configFromEnv(), ...config };
133
- this.logger = logger2 ?? defaultLogger;
134
- const errors = validateConfig(this.config);
135
- if (errors.length > 0) {
136
- if (strictValidation) {
137
- throw new Error(`RLM configuration invalid: ${errors.join("; ")}`);
138
- }
139
- for (const error of errors) {
140
- this.logger.warn(`Configuration warning: ${error}`);
141
- }
142
- }
143
- }
144
- async startServer() {
145
- if (this.process) return;
146
- this.hasStartupError = false;
147
- this.logger.debug(
148
- `Starting RLM server: ${this.config.pythonPath} -m elizaos_plugin_rlm.server`
149
- );
150
- try {
151
- this.process = spawn(this.config.pythonPath, ["-m", "elizaos_plugin_rlm.server"], {
152
- stdio: ["pipe", "pipe", "pipe"],
153
- env: {
154
- ...process.env,
155
- [ENV_VARS.BACKEND]: this.config.backend,
156
- [ENV_VARS.ENVIRONMENT]: this.config.environment,
157
- [ENV_VARS.MAX_ITERATIONS]: String(this.config.maxIterations),
158
- [ENV_VARS.MAX_DEPTH]: String(this.config.maxDepth),
159
- [ENV_VARS.VERBOSE]: this.config.verbose ? "true" : "false"
160
- },
161
- cwd: path.join(__dirname, "..", "python")
162
- });
163
- } catch (error) {
164
- this.logger.warn(`Failed to start RLM server: ${error}`);
165
- this.isAvailable = false;
166
- return;
167
- }
168
- if (!this.process.stdout || !this.process.stdin) {
169
- this.logger.warn("RLM server process missing stdio streams");
170
- this.isAvailable = false;
171
- return;
172
- }
173
- this.reader = readline.createInterface({
174
- input: this.process.stdout,
175
- crlfDelay: Number.POSITIVE_INFINITY
176
- });
177
- this.reader.on("line", (line) => {
178
- this.handleMessage(line);
179
- });
180
- this.process.stderr?.on("data", (data) => {
181
- this.logger.debug(`RLM server stderr: ${data.toString()}`);
182
- });
183
- this.process.on("error", (error) => {
184
- this.logger.error(`RLM server error: ${error.message}`);
185
- this.isAvailable = false;
186
- this.hasStartupError = true;
187
- });
188
- this.process.on("exit", (code) => {
189
- this.logger.debug(`RLM server exited with code ${code}`);
190
- this.isReady = false;
191
- this.isAvailable = false;
192
- this.process = null;
193
- });
194
- await this.waitForReady();
195
- }
196
- waitForReady() {
197
- return new Promise((resolve, reject) => {
198
- const TIMEOUT_MS = 1e4;
199
- const POLL_INTERVAL_MS = 100;
200
- const deadline = Date.now() + TIMEOUT_MS;
201
- const checkReady = () => {
202
- if (this.isReady) {
203
- resolve();
204
- } else if (!this.process || this.hasStartupError) {
205
- reject(new Error("RLM server process failed before ready"));
206
- } else if (Date.now() > deadline) {
207
- reject(new Error("RLM server startup timeout"));
208
- } else {
209
- setTimeout(checkReady, POLL_INTERVAL_MS);
210
- }
211
- };
212
- checkReady();
213
- });
214
- }
215
- handleMessage(line) {
216
- try {
217
- const message = JSON.parse(line);
218
- if ("ready" in message) {
219
- const readyMsg = message;
220
- this.isReady = true;
221
- this.isAvailable = readyMsg.available;
222
- this.logger.info(`RLM server ready, available: ${this.isAvailable}`);
223
- return;
224
- }
225
- const response = message;
226
- const pending = this.pendingRequests.get(response.id);
227
- if (pending) {
228
- this.pendingRequests.delete(response.id);
229
- pending.resolve(response);
230
- }
231
- } catch (_error) {
232
- this.logger.error(`Failed to parse RLM server message: ${line}`);
233
- }
234
- }
235
- async sendRequest(method, params = {}) {
236
- await this.ensureServer();
237
- if (!this.process?.stdin) {
238
- throw new Error("RLM server not running");
239
- }
240
- const id = ++this.requestId;
241
- const request = { id, method, params };
242
- return new Promise((resolve, reject) => {
243
- const timeout = setTimeout(() => {
244
- this.pendingRequests.delete(id);
245
- reject(new Error(`RLM request timeout: ${method}`));
246
- }, 6e4);
247
- this.pendingRequests.set(id, {
248
- resolve: (response) => {
249
- clearTimeout(timeout);
250
- if (response.error) {
251
- reject(new Error(response.error));
252
- } else {
253
- resolve(response.result);
254
- }
255
- },
256
- reject: (error) => {
257
- clearTimeout(timeout);
258
- reject(error);
259
- }
260
- });
261
- this.process?.stdin?.write(`${JSON.stringify(request)}
262
- `);
263
- });
264
- }
265
- async ensureServer() {
266
- if (!this.process || !this.isReady) {
267
- await this.startServer();
268
- }
269
- }
270
- get available() {
271
- return this.isAvailable;
272
- }
273
- getMetrics() {
274
- return { ...this.metrics };
275
- }
276
- onMetrics(callback) {
277
- this.metricsCallback = callback;
278
- }
279
- updateMetrics(latencyMs, success, isStub, error) {
280
- this.metrics.totalRequests++;
281
- this.metrics.lastRequestTimestamp = Date.now();
282
- if (isStub) {
283
- this.metrics.stubResponses++;
284
- } else if (success) {
285
- this.metrics.successfulRequests++;
286
- } else {
287
- this.metrics.failedRequests++;
288
- this.metrics.lastErrorTimestamp = Date.now();
289
- this.metrics.lastError = error;
290
- }
291
- this.latencies[this.latencyIndex] = latencyMs;
292
- this.latencyIndex = (this.latencyIndex + 1) % _RLMClient.MAX_LATENCY_SAMPLES;
293
- this.latencyCount = Math.min(this.latencyCount + 1, _RLMClient.MAX_LATENCY_SAMPLES);
294
- if (this.latencyCount > 0) {
295
- const valid = this.latencies.slice(0, this.latencyCount);
296
- this.metrics.averageLatencyMs = valid.reduce((a, b) => a + b, 0) / this.latencyCount;
297
- this.metrics.p95LatencyMs = [...valid].sort((a, b) => a - b)[Math.floor(valid.length * 0.95)] ?? 0;
298
- }
299
- this.metricsCallback?.(this.getMetrics());
300
- }
301
- static normalizeMessages(messages) {
302
- return typeof messages === "string" ? [{ role: "user", content: messages }] : messages;
303
- }
304
- async infer(messages, opts) {
305
- assertRecordedLlmCall({
306
- actionType: "rlm.client.infer",
307
- model: opts?.rootModel,
308
- purpose: "external_llm"
309
- });
310
- const startTime = Date.now();
311
- const { maxRetries = 3, retryBaseDelay = 1e3, retryMaxDelay = 3e4 } = this.config;
312
- const RETRYABLE_PATTERNS = ["timeout", "rate limit", "connection", "503", "429", "econnreset"];
313
- let lastError = null;
314
- for (let attempt = 0; attempt < maxRetries; attempt++) {
315
- try {
316
- await this.ensureServer();
317
- if (!this.isReady) {
318
- this.updateMetrics(Date.now() - startTime, true, true);
319
- return stubResult();
320
- }
321
- const result = await this.sendRequest("infer", {
322
- messages: _RLMClient.normalizeMessages(messages),
323
- opts: opts ?? {}
324
- });
325
- this.updateMetrics(Date.now() - startTime, true, false);
326
- return result;
327
- } catch (error) {
328
- lastError = error instanceof Error ? error : new Error(String(error));
329
- const isRetryable = RETRYABLE_PATTERNS.some(
330
- (p) => lastError?.message.toLowerCase().includes(p)
331
- );
332
- if (!isRetryable || attempt === maxRetries - 1) {
333
- this.logger.error(`RLM inference failed after ${attempt + 1} attempts: ${error}`);
334
- this.updateMetrics(Date.now() - startTime, true, true, lastError.message);
335
- return stubResult(lastError.message);
336
- }
337
- const delay = Math.min(retryBaseDelay * 2 ** attempt, retryMaxDelay) * (0.75 + Math.random() * 0.5);
338
- this.metrics.totalRetries++;
339
- this.logger.warn(
340
- `RLM attempt ${attempt + 1}/${maxRetries} failed. Retrying in ${Math.round(delay)}ms`
341
- );
342
- await new Promise((resolve) => setTimeout(resolve, delay));
343
- }
344
- }
345
- this.updateMetrics(Date.now() - startTime, false, false, lastError?.message);
346
- return stubResult(lastError?.message);
347
- }
348
- async getStatus() {
349
- try {
350
- await this.ensureServer();
351
- return await this.sendRequest("status");
352
- } catch {
353
- return {
354
- available: false,
355
- backend: this.config.backend,
356
- environment: this.config.environment,
357
- maxIterations: this.config.maxIterations,
358
- maxDepth: this.config.maxDepth
359
- };
360
- }
361
- }
362
- async shutdown() {
363
- if (!this.process) return;
364
- try {
365
- await this.sendRequest("shutdown");
366
- } catch {
367
- }
368
- this.reader?.close();
369
- this.process?.kill();
370
- this.process = null;
371
- this.isReady = false;
372
- this.isAvailable = false;
373
- }
374
- };
375
- function stubResult(error) {
376
- return {
377
- text: "[RLM STUB] RLM backend not available",
378
- metadata: { stub: true, error }
379
- };
380
- }
381
-
382
- // cost.ts
383
- var MODEL_PRICING = {
384
- openai: {
385
- "gpt-5": { input: 2.5, output: 10 },
386
- "gpt-5-preview": { input: 10, output: 30 },
387
- "gpt-5-mini": { input: 0.15, output: 0.6 },
388
- "gpt-3.5-turbo": { input: 0.5, output: 1.5 }
389
- },
390
- anthropic: {
391
- "claude-3-5-sonnet-20241022": { input: 3, output: 15 },
392
- "claude-3-5-haiku-20241022": { input: 0.8, output: 4 },
393
- "claude-3-opus-20240229": { input: 15, output: 75 },
394
- "claude-3-sonnet-20240229": { input: 3, output: 15 },
395
- "claude-3-haiku-20240307": { input: 0.25, output: 1.25 }
396
- },
397
- gemini: {
398
- "gemini-2.0-flash-exp": { input: 0, output: 0 },
399
- "gemini-2.0-flash": { input: 0.075, output: 0.3 },
400
- "gemini-1.5-flash": { input: 0.075, output: 0.3 },
401
- "gemini-1.5-pro": { input: 1.25, output: 5 }
402
- },
403
- groq: {
404
- "openai/gpt-oss-120b": { input: 0.5, output: 0.8 }
405
- }
406
- };
407
- function setModelPricing(backend, model, inputCost, outputCost) {
408
- if (!MODEL_PRICING[backend]) {
409
- MODEL_PRICING[backend] = {};
410
- }
411
- MODEL_PRICING[backend][model] = { input: inputCost, output: outputCost };
412
- }
413
- function loadPricingFromEnv() {
414
- const env2 = typeof process !== "undefined" ? process.env : {};
415
- const pricingJson = env2.ELIZA_RLM_PRICING_JSON;
416
- if (!pricingJson) return;
417
- try {
418
- const customPricing = JSON.parse(pricingJson);
419
- for (const [backend, models] of Object.entries(customPricing)) {
420
- for (const [model, prices] of Object.entries(models)) {
421
- setModelPricing(backend, model, prices.input ?? 1, prices.output ?? 3);
422
- }
423
- }
424
- } catch (e) {
425
- console.warn(`[RLM] Failed to parse ELIZA_RLM_PRICING_JSON: ${e}`);
426
- }
427
- }
428
- loadPricingFromEnv();
429
- function estimateTokenCount(text) {
430
- return Math.ceil(text.length / 4);
431
- }
432
-
433
- // index.ts
434
- var env = typeof process !== "undefined" ? process.env : {};
435
- function resolveBackend(value) {
436
- return VALID_BACKENDS.includes(value) ? value : DEFAULT_CONFIG.backend;
437
- }
438
- function resolveEnvironment(value) {
439
- return VALID_ENVIRONMENTS.includes(value) ? value : DEFAULT_CONFIG.environment;
440
- }
441
- function getRuntimeConfig(runtime) {
442
- return runtime.rlmConfig;
443
- }
444
- function setRuntimeConfig(runtime, config) {
445
- runtime.rlmConfig = config;
446
- }
447
- var clientState = {
448
- client: null,
449
- initPromise: null,
450
- configHash: null
451
- };
452
- function computeConfigHash(config) {
453
- const key = [
454
- config.backend ?? "",
455
- config.environment ?? "",
456
- String(config.maxIterations ?? ""),
457
- String(config.maxDepth ?? ""),
458
- config.pythonPath ?? ""
459
- ].join("|");
460
- return key;
461
- }
462
- function getOrCreateClient(runtime) {
463
- const runtimeConfig = getRuntimeConfig(runtime);
464
- const configHash = computeConfigHash(runtimeConfig ?? {});
465
- if (clientState.client && clientState.configHash !== configHash) {
466
- logger.info("[RLM] Config changed, recreating client");
467
- clientState.client.shutdown().catch((err) => {
468
- logger.warn("[RLM] Error shutting down old client:", err);
469
- });
470
- clientState.client = null;
471
- clientState.initPromise = null;
472
- }
473
- if (clientState.client) {
474
- return clientState.client;
475
- }
476
- const client = new RLMClient(runtimeConfig);
477
- clientState.client = client;
478
- clientState.configHash = configHash;
479
- return client;
480
- }
481
- async function resetClient() {
482
- if (clientState.client) {
483
- await clientState.client.shutdown();
484
- }
485
- clientState.client = null;
486
- clientState.initPromise = null;
487
- clientState.configHash = null;
488
- }
489
- async function handleTextGeneration(runtime, params) {
490
- const client = getOrCreateClient(runtime);
491
- const input = params.prompt ?? "";
492
- const opts = {
493
- maxTokens: params.maxTokens,
494
- temperature: params.temperature,
495
- topP: params.topP,
496
- stopSequences: params.stopSequences,
497
- user: params.user
498
- };
499
- const cleanOpts = Object.fromEntries(Object.entries(opts).filter(([, v]) => v !== void 0));
500
- const runtimeConfig = getRuntimeConfig(runtime);
501
- const backend = runtimeConfig?.backend ?? DEFAULT_CONFIG.backend;
502
- const model = `${backend}:rlm`;
503
- const details = {
504
- model,
505
- systemPrompt: resolveEffectiveSystemPrompt({
506
- params,
507
- fallback: buildCanonicalSystemPrompt({ character: runtime.character })
508
- }) ?? "",
509
- userPrompt: input,
510
- temperature: params.temperature ?? 0,
511
- maxTokens: params.maxTokens ?? 0,
512
- purpose: "external_llm",
513
- actionType: "rlm.client.infer",
514
- promptTokens: estimateTokenCount(input)
515
- };
516
- const result = await recordLlmCall(runtime, details, async () => {
517
- const response = await client.infer(input, cleanOpts);
518
- details.response = response.text;
519
- details.completionTokens = estimateTokenCount(response.text);
520
- return response;
521
- });
522
- return result.text;
523
- }
524
- var rlmPlugin = {
525
- name: "rlm",
526
- description: "RLM (Recursive Language Model) adapter for elizaOS - enables processing of arbitrarily long contexts through recursive self-calls",
527
- config: {
528
- [ENV_VARS.BACKEND]: env[ENV_VARS.BACKEND] ?? DEFAULT_CONFIG.backend,
529
- [ENV_VARS.ENVIRONMENT]: env[ENV_VARS.ENVIRONMENT] ?? DEFAULT_CONFIG.environment,
530
- [ENV_VARS.MAX_ITERATIONS]: env[ENV_VARS.MAX_ITERATIONS] ?? String(DEFAULT_CONFIG.maxIterations),
531
- [ENV_VARS.MAX_DEPTH]: env[ENV_VARS.MAX_DEPTH] ?? String(DEFAULT_CONFIG.maxDepth),
532
- [ENV_VARS.VERBOSE]: env[ENV_VARS.VERBOSE] ?? "false",
533
- [ENV_VARS.PYTHON_PATH]: env[ENV_VARS.PYTHON_PATH] ?? DEFAULT_CONFIG.pythonPath
534
- },
535
- async init(config, runtime) {
536
- logger.info("[RLM] Initializing RLM plugin");
537
- setRuntimeConfig(runtime, {
538
- backend: resolveBackend(config[ENV_VARS.BACKEND]),
539
- environment: resolveEnvironment(config[ENV_VARS.ENVIRONMENT]),
540
- maxIterations: Number.parseInt(config[ENV_VARS.MAX_ITERATIONS] ?? "", 10) || DEFAULT_CONFIG.maxIterations,
541
- maxDepth: Number.parseInt(config[ENV_VARS.MAX_DEPTH] ?? "", 10) || DEFAULT_CONFIG.maxDepth,
542
- verbose: ["1", "true", "yes"].includes((config[ENV_VARS.VERBOSE] ?? "").toLowerCase()),
543
- pythonPath: config[ENV_VARS.PYTHON_PATH] ?? DEFAULT_CONFIG.pythonPath
544
- });
545
- const client = getOrCreateClient(runtime);
546
- const status = await client.getStatus();
547
- if (status.available) {
548
- logger.info(`[RLM] Backend available: ${status.backend}`);
549
- } else {
550
- logger.warn("[RLM] Backend not available - running in stub mode");
551
- }
552
- },
553
- models: {
554
- [ModelType.TEXT_SMALL]: handleTextGeneration,
555
- [ModelType.TEXT_LARGE]: handleTextGeneration,
556
- [ModelType.TEXT_REASONING_SMALL]: handleTextGeneration,
557
- [ModelType.TEXT_REASONING_LARGE]: handleTextGeneration,
558
- [ModelType.TEXT_COMPLETION]: handleTextGeneration
559
- },
560
- tests: [
561
- {
562
- name: "rlm_plugin_tests",
563
- tests: [
564
- {
565
- name: "rlm_test_stub_mode",
566
- fn: async (_runtime) => {
567
- const result = stubResult();
568
- if (!result.metadata.stub) {
569
- throw new Error("Stub result should have stub=true");
570
- }
571
- logger.info("[RLM Test] Stub mode test passed");
572
- }
573
- },
574
- {
575
- name: "rlm_test_text_generation",
576
- fn: async (runtime) => {
577
- const text = await runtime.useModel(ModelType.TEXT_LARGE, {
578
- prompt: "Say 'hello' in exactly one word."
579
- });
580
- if (typeof text !== "string") {
581
- throw new Error("TEXT_LARGE should return string");
582
- }
583
- logger.info(`[RLM Test] TEXT_LARGE generated: "${text.substring(0, 50)}..."`);
584
- }
585
- },
586
- {
587
- name: "rlm_test_message_format",
588
- fn: async (runtime) => {
589
- const text = await runtime.useModel(ModelType.TEXT_LARGE, {
590
- prompt: "What is 2 + 2?"
591
- });
592
- if (typeof text !== "string") {
593
- throw new Error("TEXT_LARGE with prompt should return string");
594
- }
595
- logger.info("[RLM Test] Message format test passed");
596
- }
597
- }
598
- ]
599
- }
600
- ]
601
- };
602
- var index_default = rlmPlugin;
603
- export {
604
- DEFAULT_CONFIG,
605
- ENV_VARS,
606
- RLMClient,
607
- configFromEnv,
608
- index_default as default,
609
- resetClient,
610
- rlmPlugin,
611
- stubResult
612
- };
613
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../index.ts","../client.ts","../types.ts","../cost.ts"],"sourcesContent":["/**\n * RLM (Recursive Language Model) plugin for elizaOS.\n *\n * This plugin integrates Recursive Language Models into elizaOS, enabling\n * LLMs to process arbitrarily long contexts through recursive self-calls\n * in a REPL environment.\n *\n * Reference:\n * - Paper: https://arxiv.org/abs/2512.24601\n * - Implementation: https://github.com/alexzhang13/rlm\n */\n\nimport type {\n GenerateTextParams,\n IAgentRuntime,\n Plugin,\n RecordLlmCallDetails,\n} from \"@elizaos/core\";\nimport {\n buildCanonicalSystemPrompt,\n logger,\n ModelType,\n recordLlmCall,\n resolveEffectiveSystemPrompt,\n} from \"@elizaos/core\";\n\nimport { RLMClient, stubResult } from \"./client\";\nimport { estimateTokenCount } from \"./cost\";\nimport type { RLMConfig } from \"./types\";\nimport { DEFAULT_CONFIG, ENV_VARS, VALID_BACKENDS, VALID_ENVIRONMENTS } from \"./types\";\n\n// Safe env access for browser/non-Node environments\nconst env: Record<string, string | undefined> = typeof process !== \"undefined\" ? process.env : {};\n\nfunction resolveBackend(value: string | undefined): RLMConfig[\"backend\"] {\n return VALID_BACKENDS.includes(value as RLMConfig[\"backend\"])\n ? (value as RLMConfig[\"backend\"])\n : DEFAULT_CONFIG.backend;\n}\n\nfunction resolveEnvironment(value: string | undefined): RLMConfig[\"environment\"] {\n return VALID_ENVIRONMENTS.includes(value as RLMConfig[\"environment\"])\n ? (value as RLMConfig[\"environment\"])\n : DEFAULT_CONFIG.environment;\n}\n\n// ============================================================================\n// Thread-safe Singleton Client Management\n// ============================================================================\n\n/**\n * Singleton state for thread-safe client initialization.\n *\n * In concurrent environments, multiple requests could try to initialize\n * the client simultaneously. We use a promise-based lock to ensure\n * only one initialization happens.\n */\ninterface ClientState {\n client: RLMClient | null;\n initPromise: Promise<RLMClient> | null;\n configHash: string | null;\n}\n\ntype RuntimeWithRLMConfig = IAgentRuntime & {\n rlmConfig?: Partial<RLMConfig>;\n};\n\nfunction getRuntimeConfig(runtime: IAgentRuntime): Partial<RLMConfig> | undefined {\n return (runtime as RuntimeWithRLMConfig).rlmConfig;\n}\n\nfunction setRuntimeConfig(runtime: IAgentRuntime, config: Partial<RLMConfig>): void {\n (runtime as RuntimeWithRLMConfig).rlmConfig = config;\n}\n\nconst clientState: ClientState = {\n client: null,\n initPromise: null,\n configHash: null,\n};\n\n/**\n * Compute a simple hash of config for detecting changes.\n */\nfunction computeConfigHash(config: Partial<RLMConfig>): string {\n const key = [\n config.backend ?? \"\",\n config.environment ?? \"\",\n String(config.maxIterations ?? \"\"),\n String(config.maxDepth ?? \"\"),\n config.pythonPath ?? \"\",\n ].join(\"|\");\n return key;\n}\n\n/**\n * Get or create the shared RLM client instance (thread-safe).\n *\n * This implementation ensures:\n * 1. Only one client is created even under concurrent initialization\n * 2. Config changes are detected and client is recreated\n * 3. Initialization errors are properly handled\n */\nfunction getOrCreateClient(runtime: IAgentRuntime): RLMClient {\n // Get config from runtime or environment\n const runtimeConfig = getRuntimeConfig(runtime);\n const configHash = computeConfigHash(runtimeConfig ?? {});\n\n // Check if config changed - need to recreate client\n if (clientState.client && clientState.configHash !== configHash) {\n logger.info(\"[RLM] Config changed, recreating client\");\n // Shutdown old client (fire and forget)\n clientState.client.shutdown().catch((err) => {\n logger.warn(\"[RLM] Error shutting down old client:\", err);\n });\n clientState.client = null;\n clientState.initPromise = null;\n }\n\n // Fast path: client already exists with same config\n if (clientState.client) {\n return clientState.client;\n }\n\n // Slow path: need to create client\n // Create synchronously to avoid Promise in synchronous getter\n const client = new RLMClient(runtimeConfig);\n clientState.client = client;\n clientState.configHash = configHash;\n\n return client;\n}\n\n/**\n * Reset the client singleton. Useful for testing or forced reinitialization.\n */\nexport async function resetClient(): Promise<void> {\n if (clientState.client) {\n await clientState.client.shutdown();\n }\n clientState.client = null;\n clientState.initPromise = null;\n clientState.configHash = null;\n}\n\n/**\n * Handle text generation using RLM.\n */\nasync function handleTextGeneration(\n runtime: IAgentRuntime,\n params: GenerateTextParams,\n): Promise<string> {\n const client = getOrCreateClient(runtime);\n\n // Use prompt from params\n const input = params.prompt ?? \"\";\n\n const opts = {\n maxTokens: params.maxTokens,\n temperature: params.temperature,\n topP: params.topP,\n stopSequences: params.stopSequences,\n user: params.user,\n };\n\n // Remove undefined values\n const cleanOpts = Object.fromEntries(Object.entries(opts).filter(([, v]) => v !== undefined));\n\n const runtimeConfig = getRuntimeConfig(runtime);\n const backend = runtimeConfig?.backend ?? DEFAULT_CONFIG.backend;\n const model = `${backend}:rlm`;\n const details: RecordLlmCallDetails = {\n model,\n systemPrompt:\n resolveEffectiveSystemPrompt({\n params,\n fallback: buildCanonicalSystemPrompt({ character: runtime.character }),\n }) ?? \"\",\n userPrompt: input,\n temperature: params.temperature ?? 0,\n maxTokens: params.maxTokens ?? 0,\n purpose: \"external_llm\",\n actionType: \"rlm.client.infer\",\n promptTokens: estimateTokenCount(input),\n };\n\n const result = await recordLlmCall(runtime, details, async () => {\n const response = await client.infer(input, cleanOpts);\n details.response = response.text;\n details.completionTokens = estimateTokenCount(response.text);\n return response;\n });\n return result.text;\n}\n\n/**\n * RLM plugin definition.\n */\nexport const rlmPlugin: Plugin = {\n name: \"rlm\",\n description:\n \"RLM (Recursive Language Model) adapter for elizaOS - enables processing of arbitrarily long contexts through recursive self-calls\",\n\n config: {\n [ENV_VARS.BACKEND]: env[ENV_VARS.BACKEND] ?? DEFAULT_CONFIG.backend,\n [ENV_VARS.ENVIRONMENT]: env[ENV_VARS.ENVIRONMENT] ?? DEFAULT_CONFIG.environment,\n [ENV_VARS.MAX_ITERATIONS]: env[ENV_VARS.MAX_ITERATIONS] ?? String(DEFAULT_CONFIG.maxIterations),\n [ENV_VARS.MAX_DEPTH]: env[ENV_VARS.MAX_DEPTH] ?? String(DEFAULT_CONFIG.maxDepth),\n [ENV_VARS.VERBOSE]: env[ENV_VARS.VERBOSE] ?? \"false\",\n [ENV_VARS.PYTHON_PATH]: env[ENV_VARS.PYTHON_PATH] ?? DEFAULT_CONFIG.pythonPath,\n },\n\n async init(config: Record<string, string>, runtime: IAgentRuntime): Promise<void> {\n logger.info(\"[RLM] Initializing RLM plugin\");\n\n // Store config on runtime\n setRuntimeConfig(runtime, {\n backend: resolveBackend(config[ENV_VARS.BACKEND]),\n environment: resolveEnvironment(config[ENV_VARS.ENVIRONMENT]),\n maxIterations:\n Number.parseInt(config[ENV_VARS.MAX_ITERATIONS] ?? \"\", 10) || DEFAULT_CONFIG.maxIterations,\n maxDepth: Number.parseInt(config[ENV_VARS.MAX_DEPTH] ?? \"\", 10) || DEFAULT_CONFIG.maxDepth,\n verbose: [\"1\", \"true\", \"yes\"].includes((config[ENV_VARS.VERBOSE] ?? \"\").toLowerCase()),\n pythonPath: config[ENV_VARS.PYTHON_PATH] ?? DEFAULT_CONFIG.pythonPath,\n });\n\n // Pre-initialize client\n const client = getOrCreateClient(runtime);\n const status = await client.getStatus();\n\n if (status.available) {\n logger.info(`[RLM] Backend available: ${status.backend}`);\n } else {\n logger.warn(\"[RLM] Backend not available - running in stub mode\");\n }\n },\n\n models: {\n [ModelType.TEXT_SMALL]: handleTextGeneration,\n [ModelType.TEXT_LARGE]: handleTextGeneration,\n [ModelType.TEXT_REASONING_SMALL]: handleTextGeneration,\n [ModelType.TEXT_REASONING_LARGE]: handleTextGeneration,\n [ModelType.TEXT_COMPLETION]: handleTextGeneration,\n },\n\n tests: [\n {\n name: \"rlm_plugin_tests\",\n tests: [\n {\n name: \"rlm_test_stub_mode\",\n fn: async (_runtime: IAgentRuntime): Promise<void> => {\n // Test that stub mode works\n const result = stubResult();\n if (!result.metadata.stub) {\n throw new Error(\"Stub result should have stub=true\");\n }\n logger.info(\"[RLM Test] Stub mode test passed\");\n },\n },\n {\n name: \"rlm_test_text_generation\",\n fn: async (runtime: IAgentRuntime): Promise<void> => {\n const text = await runtime.useModel(ModelType.TEXT_LARGE, {\n prompt: \"Say 'hello' in exactly one word.\",\n });\n\n if (typeof text !== \"string\") {\n throw new Error(\"TEXT_LARGE should return string\");\n }\n\n logger.info(`[RLM Test] TEXT_LARGE generated: \"${text.substring(0, 50)}...\"`);\n },\n },\n {\n name: \"rlm_test_message_format\",\n fn: async (runtime: IAgentRuntime): Promise<void> => {\n const text = await runtime.useModel(ModelType.TEXT_LARGE, {\n prompt: \"What is 2 + 2?\",\n });\n\n if (typeof text !== \"string\") {\n throw new Error(\"TEXT_LARGE with prompt should return string\");\n }\n\n logger.info(\"[RLM Test] Message format test passed\");\n },\n },\n ],\n },\n ],\n};\n\nexport default rlmPlugin;\n\n// Re-export types and client\nexport { configFromEnv, RLMClient, stubResult } from \"./client\";\nexport type {\n GenerateTextParams,\n RLMConfig,\n RLMInferOptions,\n RLMMessage,\n RLMMetadata,\n RLMResult,\n RLMStatusResponse,\n} from \"./types\";\nexport { DEFAULT_CONFIG, ENV_VARS } from \"./types\";\n","/** RLM Client - communicates with Python subprocess via JSON-RPC IPC. */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport * as path from \"node:path\";\nimport * as readline from \"node:readline\";\n\nimport { assertRecordedLlmCall } from \"@elizaos/core\";\nimport type {\n IPCReadyMessage,\n IPCRequest,\n IPCResponse,\n MetricsCallback,\n RLMConfig,\n RLMInferOptions,\n RLMMessage,\n RLMMetrics,\n RLMResult,\n RLMStatusResponse,\n} from \"./types\";\nimport { DEFAULT_CONFIG, ENV_VARS, validateConfig } from \"./types\";\n\nexport type { MetricsCallback, RLMMetrics };\nexport { DEFAULT_CONFIG };\n\ninterface Logger {\n info: (message: string, ...args: unknown[]) => void;\n warn: (message: string, ...args: unknown[]) => void;\n error: (message: string, ...args: unknown[]) => void;\n debug: (message: string, ...args: unknown[]) => void;\n}\n\nconst defaultLogger: Logger = {\n info: (msg, ...args) => console.log(`[RLM] ${msg}`, ...args),\n warn: (msg, ...args) => console.warn(`[RLM] ${msg}`, ...args),\n error: (msg, ...args) => console.error(`[RLM] ${msg}`, ...args),\n debug: (msg, ...args) => console.debug(`[RLM] ${msg}`, ...args),\n};\n\nexport function configFromEnv(env: NodeJS.ProcessEnv = process.env): RLMConfig {\n return {\n backend: (env[ENV_VARS.BACKEND] as RLMConfig[\"backend\"]) ?? DEFAULT_CONFIG.backend,\n backendKwargs: {},\n environment:\n (env[ENV_VARS.ENVIRONMENT] as RLMConfig[\"environment\"]) ?? DEFAULT_CONFIG.environment,\n maxIterations:\n Number.parseInt(env[ENV_VARS.MAX_ITERATIONS] ?? \"\", 10) || DEFAULT_CONFIG.maxIterations,\n maxDepth: Number.parseInt(env[ENV_VARS.MAX_DEPTH] ?? \"\", 10) || DEFAULT_CONFIG.maxDepth,\n verbose: [\"1\", \"true\", \"yes\"].includes((env[ENV_VARS.VERBOSE] ?? \"\").toLowerCase()),\n pythonPath: env[ENV_VARS.PYTHON_PATH] ?? DEFAULT_CONFIG.pythonPath,\n maxRetries: Number.parseInt(env[ENV_VARS.MAX_RETRIES] ?? \"\", 10) || DEFAULT_CONFIG.maxRetries,\n retryBaseDelay:\n Number.parseInt(env[ENV_VARS.RETRY_BASE_DELAY] ?? \"\", 10) || DEFAULT_CONFIG.retryBaseDelay,\n retryMaxDelay:\n Number.parseInt(env[ENV_VARS.RETRY_MAX_DELAY] ?? \"\", 10) || DEFAULT_CONFIG.retryMaxDelay,\n };\n}\n\nexport class RLMClient {\n private config: RLMConfig;\n private process: ChildProcess | null = null;\n private reader: readline.Interface | null = null;\n private requestId = 0;\n private pendingRequests = new Map<\n number,\n { resolve: (value: IPCResponse) => void; reject: (error: Error) => void }\n >();\n private isReady = false;\n private isAvailable = false;\n private hasStartupError = false;\n private logger: Logger;\n private metrics: RLMMetrics = {\n totalRequests: 0,\n successfulRequests: 0,\n failedRequests: 0,\n stubResponses: 0,\n totalRetries: 0,\n averageLatencyMs: 0,\n p95LatencyMs: 0,\n lastRequestTimestamp: 0,\n };\n private static readonly MAX_LATENCY_SAMPLES = 1000;\n private latencies: number[] = new Array(RLMClient.MAX_LATENCY_SAMPLES).fill(0);\n private latencyIndex = 0;\n private latencyCount = 0;\n private metricsCallback: MetricsCallback | null = null;\n\n constructor(config?: Partial<RLMConfig>, logger?: Logger, strictValidation = false) {\n this.config = { ...configFromEnv(), ...config };\n this.logger = logger ?? defaultLogger;\n\n const errors = validateConfig(this.config);\n if (errors.length > 0) {\n if (strictValidation) {\n throw new Error(`RLM configuration invalid: ${errors.join(\"; \")}`);\n }\n for (const error of errors) {\n this.logger.warn(`Configuration warning: ${error}`);\n }\n }\n }\n\n private async startServer(): Promise<void> {\n if (this.process) return;\n this.hasStartupError = false;\n\n this.logger.debug(\n `Starting RLM server: ${this.config.pythonPath} -m elizaos_plugin_rlm.server`,\n );\n\n try {\n this.process = spawn(this.config.pythonPath, [\"-m\", \"elizaos_plugin_rlm.server\"], {\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n env: {\n ...process.env,\n [ENV_VARS.BACKEND]: this.config.backend,\n [ENV_VARS.ENVIRONMENT]: this.config.environment,\n [ENV_VARS.MAX_ITERATIONS]: String(this.config.maxIterations),\n [ENV_VARS.MAX_DEPTH]: String(this.config.maxDepth),\n [ENV_VARS.VERBOSE]: this.config.verbose ? \"true\" : \"false\",\n },\n cwd: path.join(__dirname, \"..\", \"python\"),\n });\n } catch (error) {\n this.logger.warn(`Failed to start RLM server: ${error}`);\n this.isAvailable = false;\n return;\n }\n\n if (!this.process.stdout || !this.process.stdin) {\n this.logger.warn(\"RLM server process missing stdio streams\");\n this.isAvailable = false;\n return;\n }\n\n // Set up line reader for responses\n this.reader = readline.createInterface({\n input: this.process.stdout,\n crlfDelay: Number.POSITIVE_INFINITY,\n });\n\n // Handle incoming messages\n this.reader.on(\"line\", (line: string) => {\n this.handleMessage(line);\n });\n\n // Handle errors\n this.process.stderr?.on(\"data\", (data: Buffer) => {\n this.logger.debug(`RLM server stderr: ${data.toString()}`);\n });\n\n this.process.on(\"error\", (error: Error) => {\n this.logger.error(`RLM server error: ${error.message}`);\n this.isAvailable = false;\n this.hasStartupError = true;\n });\n\n this.process.on(\"exit\", (code: number | null) => {\n this.logger.debug(`RLM server exited with code ${code}`);\n this.isReady = false;\n this.isAvailable = false;\n this.process = null;\n });\n\n await this.waitForReady();\n }\n\n private waitForReady(): Promise<void> {\n return new Promise((resolve, reject) => {\n const TIMEOUT_MS = 10000;\n const POLL_INTERVAL_MS = 100;\n const deadline = Date.now() + TIMEOUT_MS;\n\n const checkReady = () => {\n if (this.isReady) {\n resolve();\n } else if (!this.process || this.hasStartupError) {\n reject(new Error(\"RLM server process failed before ready\"));\n } else if (Date.now() > deadline) {\n reject(new Error(\"RLM server startup timeout\"));\n } else {\n setTimeout(checkReady, POLL_INTERVAL_MS);\n }\n };\n checkReady();\n });\n }\n\n private handleMessage(line: string): void {\n try {\n const message = JSON.parse(line) as IPCResponse | IPCReadyMessage;\n\n // Check for ready message\n if (\"ready\" in message) {\n const readyMsg = message as IPCReadyMessage;\n this.isReady = true;\n this.isAvailable = readyMsg.available;\n this.logger.info(`RLM server ready, available: ${this.isAvailable}`);\n return;\n }\n\n // Handle response\n const response = message as IPCResponse;\n const pending = this.pendingRequests.get(response.id);\n if (pending) {\n this.pendingRequests.delete(response.id);\n pending.resolve(response);\n }\n } catch (_error) {\n this.logger.error(`Failed to parse RLM server message: ${line}`);\n }\n }\n\n private async sendRequest<T>(\n method: IPCRequest[\"method\"],\n params: Record<string, unknown> = {},\n ): Promise<T> {\n await this.ensureServer();\n\n if (!this.process?.stdin) {\n throw new Error(\"RLM server not running\");\n }\n\n const id = ++this.requestId;\n const request: IPCRequest = { id, method, params };\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.pendingRequests.delete(id);\n reject(new Error(`RLM request timeout: ${method}`));\n }, 60000);\n\n this.pendingRequests.set(id, {\n resolve: (response: IPCResponse) => {\n clearTimeout(timeout);\n if (response.error) {\n reject(new Error(response.error));\n } else {\n resolve(response.result as T);\n }\n },\n reject: (error: Error) => {\n clearTimeout(timeout);\n reject(error);\n },\n });\n\n this.process?.stdin?.write(`${JSON.stringify(request)}\\n`);\n });\n }\n\n private async ensureServer(): Promise<void> {\n if (!this.process || !this.isReady) {\n await this.startServer();\n }\n }\n\n get available(): boolean {\n return this.isAvailable;\n }\n\n getMetrics(): RLMMetrics {\n return { ...this.metrics };\n }\n\n onMetrics(callback: MetricsCallback): void {\n this.metricsCallback = callback;\n }\n\n private updateMetrics(\n latencyMs: number,\n success: boolean,\n isStub: boolean,\n error?: string,\n ): void {\n this.metrics.totalRequests++;\n this.metrics.lastRequestTimestamp = Date.now();\n\n if (isStub) {\n this.metrics.stubResponses++;\n } else if (success) {\n this.metrics.successfulRequests++;\n } else {\n this.metrics.failedRequests++;\n this.metrics.lastErrorTimestamp = Date.now();\n this.metrics.lastError = error;\n }\n\n // Track latency in circular buffer\n this.latencies[this.latencyIndex] = latencyMs;\n this.latencyIndex = (this.latencyIndex + 1) % RLMClient.MAX_LATENCY_SAMPLES;\n this.latencyCount = Math.min(this.latencyCount + 1, RLMClient.MAX_LATENCY_SAMPLES);\n\n // Calculate stats from valid samples\n if (this.latencyCount > 0) {\n const valid = this.latencies.slice(0, this.latencyCount);\n this.metrics.averageLatencyMs = valid.reduce((a, b) => a + b, 0) / this.latencyCount;\n this.metrics.p95LatencyMs =\n [...valid].sort((a, b) => a - b)[Math.floor(valid.length * 0.95)] ?? 0;\n }\n\n this.metricsCallback?.(this.getMetrics());\n }\n\n static normalizeMessages(messages: string | RLMMessage[]): RLMMessage[] {\n return typeof messages === \"string\" ? [{ role: \"user\", content: messages }] : messages;\n }\n\n async infer(messages: string | RLMMessage[], opts?: RLMInferOptions): Promise<RLMResult> {\n assertRecordedLlmCall({\n actionType: \"rlm.client.infer\",\n model: opts?.rootModel,\n purpose: \"external_llm\",\n });\n\n const startTime = Date.now();\n const { maxRetries = 3, retryBaseDelay = 1000, retryMaxDelay = 30000 } = this.config;\n const RETRYABLE_PATTERNS = [\"timeout\", \"rate limit\", \"connection\", \"503\", \"429\", \"econnreset\"];\n\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt < maxRetries; attempt++) {\n try {\n await this.ensureServer();\n\n if (!this.isReady) {\n this.updateMetrics(Date.now() - startTime, true, true);\n return stubResult();\n }\n\n const result = await this.sendRequest<RLMResult>(\"infer\", {\n messages: RLMClient.normalizeMessages(messages),\n opts: opts ?? {},\n });\n\n this.updateMetrics(Date.now() - startTime, true, false);\n return result;\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n const isRetryable = RETRYABLE_PATTERNS.some((p) =>\n lastError?.message.toLowerCase().includes(p),\n );\n\n if (!isRetryable || attempt === maxRetries - 1) {\n this.logger.error(`RLM inference failed after ${attempt + 1} attempts: ${error}`);\n this.updateMetrics(Date.now() - startTime, true, true, lastError.message);\n return stubResult(lastError.message);\n }\n\n const delay =\n Math.min(retryBaseDelay * 2 ** attempt, retryMaxDelay) * (0.75 + Math.random() * 0.5);\n this.metrics.totalRetries++;\n this.logger.warn(\n `RLM attempt ${attempt + 1}/${maxRetries} failed. Retrying in ${Math.round(delay)}ms`,\n );\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n\n this.updateMetrics(Date.now() - startTime, false, false, lastError?.message);\n return stubResult(lastError?.message);\n }\n\n async getStatus(): Promise<RLMStatusResponse> {\n try {\n await this.ensureServer();\n return await this.sendRequest<RLMStatusResponse>(\"status\");\n } catch {\n return {\n available: false,\n backend: this.config.backend,\n environment: this.config.environment,\n maxIterations: this.config.maxIterations,\n maxDepth: this.config.maxDepth,\n };\n }\n }\n\n async shutdown(): Promise<void> {\n if (!this.process) return;\n try {\n await this.sendRequest(\"shutdown\");\n } catch {\n /* ignore */\n }\n this.reader?.close();\n this.process?.kill();\n this.process = null;\n this.isReady = false;\n this.isAvailable = false;\n }\n}\n\nexport function stubResult(error?: string): RLMResult {\n return {\n text: \"[RLM STUB] RLM backend not available\",\n metadata: { stub: true, error },\n };\n}\n","/** Types for the RLM (Recursive Language Model) plugin. */\n\nexport type RLMBackend = \"openai\" | \"anthropic\" | \"gemini\" | \"groq\" | \"openrouter\";\nexport type RLMEnvironment = \"local\" | \"docker\" | \"modal\" | \"prime\";\n\nexport interface RLMConfig {\n backend: RLMBackend;\n backendKwargs: Record<string, string>;\n environment: RLMEnvironment;\n maxIterations: number;\n maxDepth: number;\n verbose: boolean;\n pythonPath: string;\n maxRetries?: number;\n retryBaseDelay?: number;\n retryMaxDelay?: number;\n}\n\nexport interface RLMMessage {\n role: \"user\" | \"assistant\" | \"system\";\n content: string;\n}\n\nexport interface RLMMetadata {\n stub: boolean;\n iterations?: number;\n depth?: number;\n error?: string;\n}\n\nexport interface RLMResult {\n text: string;\n metadata: RLMMetadata;\n}\n\nexport interface RLMInferOptions {\n /** Model identifier for this request */\n model?: string;\n /** Maximum tokens to generate */\n maxTokens?: number;\n /** Sampling temperature */\n temperature?: number;\n /** Top-p sampling parameter */\n topP?: number;\n /** Stop sequences */\n stopSequences?: string[];\n /** User identifier for tracking */\n user?: string;\n /** Enable streaming (not yet supported by RLM) */\n stream?: boolean;\n\n // Per-request RLM overrides (Paper Algorithm 1)\n /** Override max iterations for this request */\n maxIterations?: number;\n /** Override max recursion depth for this request */\n maxDepth?: number;\n /** Override root model for this request */\n rootModel?: string;\n /** Override subcall model for this request */\n subcallModel?: string;\n /** Enable trajectory logging for this request */\n logTrajectories?: boolean;\n /** Enable cost tracking for this request */\n trackCosts?: boolean;\n\n // NOTE: Custom REPL tool injection is NOT supported by the upstream RLM library.\n // See: https://arxiv.org/abs/2512.24601 Section 3.3 - the paper describes the concept\n // but the current library implementation does not expose this capability.\n}\n\nexport interface RLMStatusResponse {\n available: boolean;\n backend: string;\n environment: string;\n maxIterations: number;\n maxDepth: number;\n}\n\nexport interface IPCRequest {\n id: number;\n method: \"infer\" | \"status\" | \"shutdown\";\n params: Record<string, unknown>;\n}\n\nexport interface IPCResponse<T = unknown> {\n id: number;\n result?: T;\n error?: string;\n}\n\nexport interface IPCReadyMessage {\n ready: boolean;\n available: boolean;\n}\n\nexport interface GenerateTextParams {\n prompt?: string;\n system?: string;\n messages?: RLMMessage[];\n model?: string;\n maxTokens?: number;\n temperature?: number;\n topP?: number;\n stopSequences?: string[];\n user?: string;\n stream?: boolean;\n}\n\nexport const DEFAULT_CONFIG: RLMConfig = {\n backend: \"gemini\",\n backendKwargs: {},\n environment: \"local\",\n maxIterations: 4,\n maxDepth: 1,\n verbose: false,\n pythonPath: \"python\",\n maxRetries: 3,\n retryBaseDelay: 1000,\n retryMaxDelay: 30000,\n};\n\nexport interface RLMMetrics {\n totalRequests: number;\n successfulRequests: number;\n failedRequests: number;\n stubResponses: number;\n totalRetries: number;\n averageLatencyMs: number;\n p95LatencyMs: number;\n lastRequestTimestamp: number;\n lastErrorTimestamp?: number;\n lastError?: string;\n}\n\nexport type MetricsCallback = (metrics: RLMMetrics) => void;\n\nexport const ENV_VARS = {\n BACKEND: \"ELIZA_RLM_BACKEND\",\n ENVIRONMENT: \"ELIZA_RLM_ENV\",\n MAX_ITERATIONS: \"ELIZA_RLM_MAX_ITERATIONS\",\n MAX_DEPTH: \"ELIZA_RLM_MAX_DEPTH\",\n VERBOSE: \"ELIZA_RLM_VERBOSE\",\n PYTHON_PATH: \"ELIZA_RLM_PYTHON_PATH\",\n MAX_RETRIES: \"ELIZA_RLM_MAX_RETRIES\",\n RETRY_BASE_DELAY: \"ELIZA_RLM_RETRY_BASE_DELAY\",\n RETRY_MAX_DELAY: \"ELIZA_RLM_RETRY_MAX_DELAY\",\n} as const;\n\nexport const VALID_BACKENDS: readonly RLMBackend[] = [\n \"openai\",\n \"anthropic\",\n \"gemini\",\n \"groq\",\n \"openrouter\",\n];\nexport const VALID_ENVIRONMENTS: readonly RLMEnvironment[] = [\"local\", \"docker\", \"modal\", \"prime\"];\n\nexport class RLMConfigError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"RLMConfigError\";\n }\n}\n\n/** Validate config. Returns errors array, or throws if strict=true. */\nexport function validateConfig(config: Partial<RLMConfig>, strict = false): string[] {\n const errors: string[] = [];\n\n if (config.backend !== undefined && !VALID_BACKENDS.includes(config.backend)) {\n errors.push(`Invalid backend '${config.backend}'. Valid options: ${VALID_BACKENDS.join(\", \")}`);\n }\n\n if (config.environment !== undefined && !VALID_ENVIRONMENTS.includes(config.environment)) {\n errors.push(\n `Invalid environment '${config.environment}'. Valid options: ${VALID_ENVIRONMENTS.join(\", \")}`,\n );\n }\n\n if (config.maxIterations !== undefined && config.maxIterations < 1) {\n errors.push(\"maxIterations must be >= 1\");\n }\n\n if (config.maxDepth !== undefined && config.maxDepth < 1) {\n errors.push(\"maxDepth must be >= 1\");\n }\n\n if (config.maxRetries !== undefined && config.maxRetries < 0) {\n errors.push(\"maxRetries must be >= 0\");\n }\n\n if (config.retryBaseDelay !== undefined && config.retryBaseDelay < 0) {\n errors.push(\"retryBaseDelay must be >= 0\");\n }\n\n if (\n config.retryBaseDelay !== undefined &&\n config.retryMaxDelay !== undefined &&\n config.retryMaxDelay < config.retryBaseDelay\n ) {\n errors.push(\"retryMaxDelay must be >= retryBaseDelay\");\n }\n\n if (strict && errors.length > 0) {\n throw new RLMConfigError(errors.join(\"; \"));\n }\n\n return errors;\n}\n","/**\n * Cost estimation for RLM inference.\n *\n * Provides model pricing data and cost estimation utilities matching\n * the Python implementation (client.py).\n *\n * Pricing is per 1M tokens (USD). Override via ELIZA_RLM_PRICING_JSON env var.\n */\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Cost per 1M tokens for a model. */\nexport interface ModelPricingEntry {\n /** Cost per 1M input tokens (USD). */\n input: number;\n /** Cost per 1M output tokens (USD). */\n output: number;\n}\n\n/** Result of a cost estimation. */\nexport interface CostEstimate {\n /** Model name. */\n model: string;\n /** Backend name (openai, anthropic, gemini, groq). */\n backend: string;\n /** Number of input tokens. */\n inputTokens: number;\n /** Number of output tokens. */\n outputTokens: number;\n /** Cost for input tokens (USD). */\n inputCostUsd: number;\n /** Cost for output tokens (USD). */\n outputCostUsd: number;\n /** Total cost (USD). */\n totalCostUsd: number;\n}\n\ntype PricingTable = Record<string, Record<string, ModelPricingEntry>>;\n\n// ============================================================================\n// Pricing Data — matches Python MODEL_PRICING in client.py\n// ============================================================================\n\n/**\n * Default model pricing per 1M tokens (USD).\n *\n * Organized by backend → model → {input, output}.\n * Matches the Python MODEL_PRICING dictionary exactly.\n */\nexport const MODEL_PRICING: PricingTable = {\n openai: {\n \"gpt-5\": { input: 2.5, output: 10.0 },\n \"gpt-5-preview\": { input: 10.0, output: 30.0 },\n \"gpt-5-mini\": { input: 0.15, output: 0.6 },\n \"gpt-3.5-turbo\": { input: 0.5, output: 1.5 },\n },\n anthropic: {\n \"claude-3-5-sonnet-20241022\": { input: 3.0, output: 15.0 },\n \"claude-3-5-haiku-20241022\": { input: 0.8, output: 4.0 },\n \"claude-3-opus-20240229\": { input: 15.0, output: 75.0 },\n \"claude-3-sonnet-20240229\": { input: 3.0, output: 15.0 },\n \"claude-3-haiku-20240307\": { input: 0.25, output: 1.25 },\n },\n gemini: {\n \"gemini-2.0-flash-exp\": { input: 0.0, output: 0.0 },\n \"gemini-2.0-flash\": { input: 0.075, output: 0.3 },\n \"gemini-1.5-flash\": { input: 0.075, output: 0.3 },\n \"gemini-1.5-pro\": { input: 1.25, output: 5.0 },\n },\n groq: {\n \"openai/gpt-oss-120b\": { input: 0.5, output: 0.8 },\n },\n};\n\n/** Fallback pricing when model is not found in the table. */\nexport const DEFAULT_PRICING: ModelPricingEntry = { input: 1.0, output: 3.0 };\n\n// ============================================================================\n// Pricing Management\n// ============================================================================\n\n/**\n * Set or override pricing for a model (costs per 1M tokens USD).\n *\n * Matches Python `set_model_pricing()`.\n */\nexport function setModelPricing(\n backend: string,\n model: string,\n inputCost: number,\n outputCost: number,\n): void {\n if (!MODEL_PRICING[backend]) {\n MODEL_PRICING[backend] = {};\n }\n MODEL_PRICING[backend][model] = { input: inputCost, output: outputCost };\n}\n\n/**\n * Load custom pricing from ELIZA_RLM_PRICING_JSON environment variable.\n *\n * JSON format: `{ \"backend\": { \"model\": { \"input\": X, \"output\": Y } } }`\n *\n * Matches Python `load_pricing_from_env()`.\n */\nexport function loadPricingFromEnv(): void {\n const env: Record<string, string | undefined> = typeof process !== \"undefined\" ? process.env : {};\n const pricingJson = env.ELIZA_RLM_PRICING_JSON;\n if (!pricingJson) return;\n\n try {\n const customPricing = JSON.parse(pricingJson) as PricingTable;\n for (const [backend, models] of Object.entries(customPricing)) {\n for (const [model, prices] of Object.entries(models)) {\n setModelPricing(backend, model, prices.input ?? 1.0, prices.output ?? 3.0);\n }\n }\n } catch (e) {\n console.warn(`[RLM] Failed to parse ELIZA_RLM_PRICING_JSON: ${e}`);\n }\n}\n\n// Load custom pricing on module import\nloadPricingFromEnv();\n\n// ============================================================================\n// Cost Estimation Functions\n// ============================================================================\n\n/**\n * Estimate API cost in USD based on token counts.\n *\n * Looks up pricing for the given model. If `backend` is provided, searches\n * only that backend; otherwise searches all backends. Falls back to\n * DEFAULT_PRICING if the model is not found.\n *\n * Matches Python `estimate_cost()`.\n *\n * @param model - Model identifier (e.g. \"gpt-5\", \"claude-3-opus-20240229\")\n * @param inputTokens - Number of input tokens\n * @param outputTokens - Number of output tokens\n * @param backend - Optional backend to restrict search (e.g. \"openai\")\n * @returns CostEstimate with computed costs\n */\nexport function estimateCost(\n model: string,\n inputTokens: number,\n outputTokens: number,\n backend?: string,\n): CostEstimate {\n let pricing: ModelPricingEntry | undefined;\n let resolvedBackend = backend ?? \"\";\n\n if (backend) {\n pricing = MODEL_PRICING[backend]?.[model];\n } else {\n // Search all backends for the model\n for (const [b, models] of Object.entries(MODEL_PRICING)) {\n if (models[model]) {\n pricing = models[model];\n resolvedBackend = b;\n break;\n }\n }\n }\n\n if (!pricing) {\n pricing = DEFAULT_PRICING;\n }\n\n const inputCostUsd = (inputTokens / 1_000_000) * pricing.input;\n const outputCostUsd = (outputTokens / 1_000_000) * pricing.output;\n\n return {\n model,\n backend: resolvedBackend,\n inputTokens,\n outputTokens,\n inputCostUsd,\n outputCostUsd,\n totalCostUsd: inputCostUsd + outputCostUsd,\n };\n}\n\n/**\n * Estimate token count for a text string.\n *\n * Uses a len/4 approximation (~4 characters per token). This matches\n * the Python fallback when tiktoken is not available.\n *\n * Matches Python `estimate_token_count()`.\n *\n * @param text - Input text to estimate tokens for\n * @returns Estimated number of tokens\n */\nexport function estimateTokenCount(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\n/**\n * Detect RLM strategy from generated code.\n *\n * Strategies (from Paper Section 4.1):\n * - **peek**: Examining prefix/suffix of the prompt (`[:=`, `[:-`, `prompt[`)\n * - **grep**: Regex filtering (`re.search`, `re.findall`, `grep`)\n * - **chunk**: Splitting for parallel processing (`split(`, `partition(`, `chunk`)\n * - **stitch**: Combining sub-call results (`join(`, `concat`, `+=`)\n * - **subcall**: Recursive self-call (`rlm(`, `completion(`, `subcall`)\n * - **other**: Unclassified strategy\n *\n * Matches Python `detect_strategy()`.\n *\n * @param code - Code string to classify\n * @returns Strategy name\n */\nexport function detectStrategy(code: string): string {\n const c = code.toLowerCase();\n\n if (code.includes(\"[:=\") || code.includes(\"[:-\") || c.includes(\"prompt[\")) {\n return \"peek\";\n }\n if ([\"re.search\", \"re.findall\", \"grep\"].some((p) => c.includes(p))) {\n return \"grep\";\n }\n if ([\"split(\", \"partition(\", \"chunk\"].some((p) => c.includes(p))) {\n return \"chunk\";\n }\n if (c.includes(\"join(\") || c.includes(\"concat\") || code.includes(\"+=\")) {\n return \"stitch\";\n }\n if ([\"rlm(\", \"completion(\", \"subcall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