A minimal implementation of Recursive Language Models (RLMs) using Deno and Pyodide.
📺 Watch the full video for free RLM Tutorial
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.
If you find this helpful, consider supporting on Patreon — it hosts all code, projects, slides, and write-ups from the YouTube channel.
curl -fsSL https://deno.land/install.sh | shThen follow the instructions to add Deno to your PATH, or add it manually:
export DENO_INSTALL="$HOME/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"Verify:
deno --versionTo use from python scripts, or try benchmarking with huggingface datasets
curl -LsSf https://astral.sh/uv/install.sh | shcurl -fsSL https://bun.sh/install | bashcd tui_log_viewer && bun installfast-rlm uses OpenRouter for LLM access. Set your API key in either a .env file or .envrc (for direnv users):
.env
OPENROUTER_API_KEY=sk-or-...
.envrc
export OPENROUTER_API_KEY=sk-or-...Deno picks up .env automatically. If using .envrc, run direnv allow once in the project root.
All hyperparameters are set in rlm_config.yaml at the project root:
max_calls_per_subagent: 20 # max LLM calls a single subagent can make
max_depth: 3 # max recursive subagent depth
truncate_len: 5000 # output characters shown to the LLM per step
primary_agent: "z-ai/glm-5" # model used for the root agent
sub_agent: "minimax/minimax-m2.5" # model used for child subagents
max_money_spent: 1.0 # hard budget cap in USD — crashes if exceededEdit this file to change any setting before running. If the file is missing, built-in defaults are used.
A working example is in test_counting_r.ts. Run it with:
deno task test_counting_rTo write your own script, copy test_counting_r.ts and edit the PROMPT and PREFIX constants at the top. Then run it directly:
FORCE_COLOR=1 deno run --allow-read --allow-env --allow-net --allow-sys=hostname --allow-write your_script.tsOr add it as a task in deno.json the same way test_counting_r is defined.
First install Python dependencies (only needed for benchmarks):
uv syncAll benchmarks are under benchmarks/ and use uv run:
uv run benchmarks/oolong_synth_benchmark.py
uv run benchmarks/longbench_benchmark.pyEvery run saves a .jsonl log file to logs/. Use the viewlog script to open it in the interactive TUI viewer:
./viewlog logs/<logfile>.jsonlYou can also pass just the filename if the log is in the logs/ directory:
./viewlog my_run_abc123.jsonlRun ./viewlog with no arguments to list recent logs.
The viewer is a Bun + OpenTUI app in tui_log_viewer/. Install its dependencies once:
cd tui_log_viewer && bun installAfter that ./viewlog handles launching it automatically.

