{"id":35734260,"url":"https://github.com/code-rabi/rllm","last_synced_at":"2026-01-13T20:47:44.792Z","repository":{"id":332304613,"uuid":"1128895760","full_name":"code-rabi/rllm","owner":"code-rabi","description":null,"archived":false,"fork":false,"pushed_at":"2026-01-13T09:22:35.000Z","size":114234,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-13T10:58:55.137Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/code-rabi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-01-06T09:58:48.000Z","updated_at":"2026-01-13T09:22:38.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/code-rabi/rllm","commit_stats":null,"previous_names":["code-rabi/rllm"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/code-rabi/rllm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-rabi%2Frllm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-rabi%2Frllm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-rabi%2Frllm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-rabi%2Frllm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code-rabi","download_url":"https://codeload.github.com/code-rabi/rllm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-rabi%2Frllm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28400035,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-06T12:10:23.614Z","updated_at":"2026-01-13T20:47:44.787Z","avatar_url":"https://github.com/code-rabi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RLLM: Recursive Large Language Models (TypeScript)\n\nA TypeScript implementation of [Recursive Language Models](https://arxiv.org/abs/2512.24601) for processing large contexts with LLMs.\n\nInspired by [Cloudflare's Code Mode](https://blog.cloudflare.com/code-mode/) approach.\n\n**Key differences from the [Python version](https://github.com/alexzhang13/rlm):**\n- [V8 isolates](#why-v8-isolates-not-tcpcontainers) instead of subprocess/TCP\n- [Zod schema support](#structured-context-with-zod-schema) for typed context\n- TypeScript-native\n\n## Installation\n\n```bash\npnpm add rllm\n# or\nnpm install rllm\n```\n\n## Demo\n\nRLLM analyzing a `node_modules` directory — the LLM writes JavaScript to parse dependencies, query sub-LLMs in parallel, and synthesize a final answer:\n\nhttps://private-user-images.githubusercontent.com/24541325/535005656-2c6f2381-3af4-439d-83b7-1e686a51fa94.mp4\n\nBuilt with Gemini Flash 3. See the full interactive example in [`examples/node-modules-viz/`](./examples/node-modules-viz/).\n\n## Quick Start\n\nLLM writes JavaScript code that runs in a secure V8 isolate:\n\n```typescript\nimport { createRLLM } from 'rllm';\n\nconst rlm = createRLLM({\n  model: 'gpt-4o-mini',\n  verbose: true,\n});\n\n// Full RLM completion - prompt first, context in options\nconst result = await rlm.completion(\n  \"What are the key findings in this research?\",\n  { context: hugeDocument }\n);\n\nconsole.log(result.answer);\nconsole.log(`Iterations: ${result.iterations}, Sub-LLM calls: ${result.usage.subCalls}`);\n```\n\n### Structured Context with Zod Schema\n\nFor structured data, you can provide a Zod schema. The LLM will receive type information, enabling it to write better code:\n\n```typescript\nimport { z } from 'zod';\nimport { createRLLM } from 'rllm';\n\n// Define schema for your data\nconst DataSchema = z.object({\n  users: z.array(z.object({\n    id: z.string(),\n    name: z.string(),\n    role: z.enum(['admin', 'user', 'guest']),\n    activity: z.array(z.object({\n      date: z.string(),\n      action: z.string(),\n    })),\n  })),\n  settings: z.record(z.string(), z.boolean()),\n});\n\nconst rlm = createRLLM({ model: 'gpt-4o-mini' });\n\nconst result = await rlm.completion(\n  \"How many admin users are there? What actions did they perform?\",\n  {\n    context: myData,\n    contextSchema: DataSchema,  // LLM sees the type structure!\n  }\n);\n```\n\nThe LLM will know it can access `context.users`, `context.settings`, etc. with full type awareness.\n\nThe LLM will write code like:\n```javascript\n// LLM-generated code runs in V8 isolate\nconst chunks = [];\nfor (let i = 0; i \u003c context.length; i += 50000) {\n  chunks.push(context.slice(i, i + 50000));\n}\n\nconst findings = await llm_query_batched(\n  chunks.map(c =\u003e `Extract key findings from:\\n${c}`)\n);\n\nconst summary = await llm_query(`Combine findings:\\n${findings.join('\\n')}`);\nprint(summary);\ngiveFinalAnswer({ message: summary });\n```\n\n## API Reference\n\n### `createRLLM(options)`\n\nCreate an RLLM instance with sensible defaults.\n\n```typescript\nconst rlm = createRLLM({\n  model: 'gpt-4o-mini',      // Model name\n  provider: 'openai',         // 'openai' | 'anthropic' | 'gemini' | 'openrouter' | 'custom'\n  apiKey: process.env.KEY,    // Optional, uses env vars by default\n  baseUrl: undefined,         // Optional, required for 'custom' provider\n  verbose: true,              // Enable logging\n});\n```\n\n### Custom Provider (OpenAI-Compatible APIs)\n\nUse the `custom` provider to connect to any OpenAI-compatible API (e.g., vLLM, Ollama, LM Studio, Azure OpenAI):\n\n```typescript\nconst rlm = createRLLM({\n  provider: 'custom',\n  model: 'llama-3.1-8b',\n  baseUrl: 'http://localhost:8000/v1',  // Required for custom provider\n  apiKey: 'your-api-key',               // Optional, depends on your API\n  verbose: true,\n});\n```\n\n**Note:** When using `provider: 'custom'`, the `baseUrl` parameter is **required**. An error will be thrown if it's not provided.\n\n### `RLLM` Methods\n\n| Method | Description |\n|--------|-------------|\n| `rlm.completion(prompt, options)` | Full RLM completion with code execution |\n| `rlm.chat(messages)` | Direct LLM chat |\n| `rlm.getClient()` | Get underlying LLM client |\n\n### `CompletionOptions`\n\n| Option | Type | Description |\n|--------|------|-------------|\n| `context` | `string \\| T` | The context data available to LLM-generated code |\n| `contextSchema` | `ZodType\u003cT\u003e` | Optional Zod schema describing context structure |\n\n### Sandbox Bindings\n\nThe V8 isolate provides these bindings to LLM-generated code:\n\n| Binding | Description |\n|---------|-------------|\n| `context` | The loaded context data |\n| `llm_query(prompt, model?)` | Query sub-LLM |\n| `llm_query_batched(prompts, model?)` | Batch query sub-LLMs |\n| `giveFinalAnswer({ message, data? })` | Return final answer |\n| `print(...)` | Console output |\n\n### Real-time Events\n\nSubscribe to execution events for visualizations, debugging, or streaming UIs:\n\n```typescript\nconst result = await rlm.completion(\"Analyze this data\", {\n  context: myData,\n  onEvent: (event) =\u003e {\n    switch (event.type) {\n      case \"iteration_start\":\n        console.log(`Starting iteration ${event.iteration}`);\n        break;\n      case \"llm_query_start\":\n        console.log(\"LLM thinking...\");\n        break;\n      case \"code_execution_start\":\n        console.log(`Executing:\\n${event.code}`);\n        break;\n      case \"final_answer\":\n        console.log(`Answer: ${event.answer}`);\n        break;\n    }\n  }\n});\n```\n\n| Event Type | Description |\n|------------|-------------|\n| `iteration_start` | New iteration beginning |\n| `llm_query_start` | Main LLM query starting |\n| `llm_query_end` | Main LLM response received |\n| `code_execution_start` | V8 isolate executing code |\n| `code_execution_end` | Code execution finished |\n| `final_answer` | `giveFinalAnswer()` called with answer |\n\n## Architecture\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│  RLLM TypeScript                                            │\n│                                                             │\n│  ┌─────────────┐    ┌──────────────────────────────────┐   │\n│  │   RLLM      │    │  V8 Isolate (Sandbox)            │   │\n│  │   Class     │───▶│                                  │   │\n│  └─────────────┘    │  • context (injected data)       │   │\n│        │            │  • llm_query() ──┐               │   │\n│        │            │  • llm_query_batched()           │   │\n│        ▼            │  • print() / console             │   │\n│  ┌─────────────┐    │  • giveFinalAnswer()             │   │\n│  │  LLMClient  │◀───┼──────────────────┘               │   │\n│  │  (OpenAI)   │    │                                  │   │\n│  └─────────────┘    │  LLM-generated JS code runs here │   │\n│                     └──────────────────────────────────┘   │\n└─────────────────────────────────────────────────────────────┘\n\nNo TCP. No subprocess. Direct function calls via bindings.\n```\n\n## Why V8 Isolates? (Not TCP/Containers)\n\nThe Python RLLM uses subprocess + TCP sockets for code execution. We use **V8 isolates** instead:\n\n```\nPython RLLM:  LLM → Python exec() → subprocess → TCP socket → LMHandler\nTypeScript:   LLM → V8 isolate (same process) → direct function calls\n```\n\n\nBenefits:\n- **No TCP/network** - Direct function calls via bindings\n- **Fast startup** - Isolates spin up in milliseconds\n- **Secure** - V8's built-in memory isolation\n- **Simple** - No containers, no socket servers\n\n## Development\n\n```bash\n# Install dependencies\npnpm install\n\n# Build\npnpm build\n\n# Run example\npnpm example\n\n# Run tests\npnpm test\n```\n\n## License\n\nMIT - Same as the original Python RLLM.\n\n## Credits\n\nBased on the [Recursive Language Models](https://arxiv.org/abs/2512.24601) paper and [Python implementation](https://github.com/alexzhang13/rlm) by Alex Zhang et al.\n\nReference: [RLM Blogpost](https://alexzhang13.github.io/blog/2025/rlm/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-rabi%2Frllm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-rabi%2Frllm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-rabi%2Frllm/lists"}