Skip to main content

Recursive Language Model — fast agentic LLM orchestration

Project description

fast-rlm

A minimal implementation of Recursive Language Models (RLMs) using Deno and Pyodide.

Watch the full video for free RLM Tutorial

What are RLMs

RLMs are an inference technique where an LLM interacts with arbitrarily long prompts through an external REPL. The LLM can write code to explore, decompose, and transform the prompt. It can recursively invoke sub-agents to complete smaller subtasks. Crucially, sub-agent responses are not automatically loaded into the parent agent's context — they are returned as symbols or variables inside the parent's REPL.

Support

If you find this helpful, consider supporting on Patreon — it hosts all code, projects, slides, and write-ups from the YouTube channel.

Become a Patron!


Install

pip install fast-rlm

Requirements

  • Python 3.10+
  • Deno 2+ — curl -fsSL https://deno.land/install.sh | sh
  • (Optional) Bun — only needed for the TUI log viewer

Environment Variables

Set your LLM API key before running:

export RLM_MODEL_API_KEY=sk-or-...
Variable Description Default
RLM_MODEL_API_KEY API key for your LLM provider
RLM_MODEL_BASE_URL OpenAI-compatible base URL https://openrouter.ai/api/v1

By default, fast-rlm uses OpenRouter. You can point it at any OpenAI-compatible API by setting RLM_MODEL_BASE_URL.


Quick Start

import fast_rlm

result = fast_rlm.run("Summarize the history of Rome")
print(result["results"])
print(result["usage"])

Configuration

from fast_rlm import run, RLMConfig

config = RLMConfig.default()
config.primary_agent = "openai/gpt-4o"
config.sub_agent = "openai/gpt-4o-mini"
config.max_depth = 5
config.max_money_spent = 2.0

result = run(
    "Count the r's in 50 fruit names",
    prefix="r_count",
    config=config,
)

All config fields:

Field Type Default Description
primary_agent str z-ai/glm-5 Model for the root agent
sub_agent str minimax/minimax-m2.5 Model for child subagents
max_depth int 3 Max recursive subagent depth
max_calls_per_subagent int 20 Max LLM calls per subagent
truncate_len int 2000 Output chars shown to the LLM per step
max_money_spent float 1.0 Hard budget cap in USD

Log Viewer

TUI Log Viewer

Every run saves a .jsonl log file to logs/.

# Print stats (no extra dependencies)
fast-rlm-log logs/run_xxx.jsonl

# Interactive TUI viewer (requires bun)
fast-rlm-log logs/run_xxx.jsonl --tui

Development (from source)

1. Install Deno

curl -fsSL https://deno.land/install.sh | sh

Then add Deno to your PATH:

export DENO_INSTALL="$HOME/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"

2. Install Bun (for the log viewer)

curl -fsSL https://bun.sh/install | bash
cd tui_log_viewer && bun install

3. API Key Setup

Set your key in .env or .envrc:

export RLM_MODEL_API_KEY=sk-or-...

4. Configuration

Edit rlm_config.yaml at the project root:

max_calls_per_subagent: 20
max_depth: 3
truncate_len: 2000
primary_agent: "z-ai/glm-5"
sub_agent: "minimax/minimax-m2.5"
max_money_spent: 1.0

5. Running

# Run the example
deno task test_counting_r

# Run the subagent directly
echo "What is 2+2?" | deno task subagent

# View logs
./viewlog logs/<logfile>.jsonl

6. Benchmarks

uv sync --extra benchmarks
uv run benchmarks/oolong_synth_benchmark.py
uv run benchmarks/longbench_benchmark.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_rlm-0.1.1.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fast_rlm-0.1.1-py3-none-any.whl (49.5 kB view details)

Uploaded Python 3

File details

Details for the file fast_rlm-0.1.1.tar.gz.

File metadata

  • Download URL: fast_rlm-0.1.1.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for fast_rlm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0481a178af68fc5d8656fac888d627d1356b5dd9b201dd6ff08fffae24a07f70
MD5 00f9e3e2dbfa5d76d42a3ceec5cc6d02
BLAKE2b-256 c7c3e835a237b4e22ab2fae277598d2fe3ac09941449d008339aca73e8671b3c

See more details on using hashes here.

File details

Details for the file fast_rlm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fast_rlm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for fast_rlm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d9d3728660c1cfd8b96b962e7b3f0dddb4d299798b12d5ffc6dfd52e5583fb36
MD5 298a0f830a239b373757a22d180566ee
BLAKE2b-256 17e0f6dd237180e10dd5b9b47c3e011a9d60b29b83414c9cda031bffd7e3e13e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page