rlm
Libraryalexzhang13/rlm
Inference library for Recursive Language Models with sandbox support.
Overview
RLMs replace standard LLM completion calls with a recursive, programmatic approach that enables handling near-infinite contexts. The library provides an extensible inference engine and training environment for API-based and local LLMs. It supports various sandbox environments like Docker, Modal, and Prime Intellect for isolated execution.
README Preview
\n---\n\n\nRecursive Language Models (RLMs)\n\n\n\n Full Paper •\n Blogpost •\n Documentation •\n RLM Minimal\n\n\n\n \n \n \n \n \n \n\n\n\n \n \n \n\n\n## Overview\nRecursive Language Models (RLMs) are a task-agnostic inference paradigm for language models (LMs) to handle near-infinite length contexts by enabling the LM to *programmatically* examine, decompose, and recursively call itself over its input. RLMs replace the canonical `llm.completion(prompt, model)` call with a `rlm.completion(prompt, model)` call, acting as a "language model". RLMs offload the context as a variable in a REPL environment that the LM can interact with and launch sub-LM calls inside of.\n\nRLMs are a bet on future "language model" design choices. We argue for a [CodeAct](https://arxiv.org/abs/2402.01030)-style harness (i.e. all language models should have access to a code environment) with sub-(R)LM calls as functions in code, and context / prompts as objects in code. RLMs explicitly defer code execution with sub-calls as functions to the language model itself, which is incredibly flexible and lends itself well to scale if trained correctly. We want to move away from the JSON tool-calling standard for both sub-agents and generic tool calls. The naming comes from the fact that such a system is itself a "language model" (a probabilistic mapping from text to text) that builds around and relies on recursive sub-LLM calls.\n\nThis repository provides both an extensible inference engine and training environment for using RLMs around standard API-based and local LLMs. The initial experiments and idea were proposed in a [blogpost](https://alexzhang13.github.io/blog/2025/rlm/) in 2025, with expanded results in an [arXiv preprint](https://arxiv.org/abs/2512.24601).\n\nWe now also include a [verifiers](https://github.com/PrimeIntellect-ai/verifiers) training environment based on Prime Intellect's [prime-rl](https://github.com/PrimeIntellect-ai/prime-rl) in the `training/` folder
FAQ (2)
TroubleshootingWhy does `pip install rlms` install v0.0.1a1 and fail with `ModuleNotFoundError: No module named 'rlm'` on Python 3.10?
rlms 0.1.0 requires Python >= 3.11, while the old 0.0.1a1 stub has no Python version constraint. On Python 3.10, pip therefore falls back to the incompatible stub and reports success. Install using Python 3.11 or newer:
python3.11 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip uninstall -y rlms
pip install rlms
pip show rlms # Must show Version: 0.1.0
python -c "from rlm import RLM"
On Python 3.10, pip install rlms==0.1.0 fails with No matching distribution found; 0.0.1a1 should not be used because it contains only a version string. The package maintainers can resolve the silent fallback by yanking 0.0.1a1 or releasing a Python 3.10-compatible version.
TroubleshootingHow do I make rlm_query_batched run independent RLM subqueries in parallel?
Upgrade to a release that includes PR #136. In that version, rlm_query_batched automatically runs 2 or more independent child RLM calls concurrently using a bounded ThreadPoolExecutor and returns results in the original submission order. This reduces wall time for N I/O-bound subcalls from approximately N × T to about T, subject to the configured concurrency limit. No code change is required beyond calling rlm_query_batched with multiple prompts.