General plug-and-play inference library for Recursive Language Models (RLMs), supporting various sandboxes.

★ 5,740⑂ 919👁 54▤ 6
PythonCreated 2025-12-21arxiv.org/abs/2512.24601
5,740
stars
+0+5+77
919
forks
54
watchers
–
prs
–
issues
6
releases
–
discussions

README

---


Recursive Language Models (RLMs)



  Full Paper •
  Blogpost •
  Documentation •
  RLM Minimal



  
    
  
  
    
  



  
    
  


 Overview
Recursive 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.

RLMs are a bet on future "language model" design choices. We argue for a CodeAct-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.

This 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 in 2025, with expanded results in our NeurIPS 2026 paper.

We now also include a verifiers training environment based on Prime Intellect's prime-rl in the training/ folder. Train your own RLMs, which directly can be plugged into our inference engine!

 [!NOTE]
 This repository contains inference code for RLMs with support for various sandbox environments. Open-source contributions are welcome. This repository is maintained by the authors of the paper from the MIT OASYS lab.

 Quick Setup
 [!NOTE]
 rlms requires Python 3.11 or later.

You can try out RLMs quickly by installing from PyPi:
bash
pip install rlms


The default RLM client uses a REPL environment that runs on the host process through Python exec calls. It uses the same virtual environment as the host process (i.e. it will have access to the same dependencies), but with some limitations in its available global modules. As an example, we can call RLM completions using GPT-5-nano:
python
from rlm import RLM

rlm = RLM(
    backend="openai",
    backend_kwargs={"model_name": "gpt-5-nano"},
    verbose=True,   For printing to console with rich, disabled by default.
)

print(rlm.completion("Print me the first 100 powers of two, each on a newline.").response)



Manual Setup

Set up the dependencies with uv (or your virtual environment of choice):
bash
curl -LsSf https://astral.sh/uv/install.sh | sh
uv init && uv venv --python 3.12   change version as need

Snapshot: 2026-11-04T14:00:00Z · Data license Apache-2.0 · JSON