Recursive Language Model (RLM) System Prompt
Real system prompt from MIT CSAIL’s Recursive Language Models paper (arXiv:2512.24601v3, Appendix C.1). Defines a complete REPL-based agent architecture where the LLM writes Python code to recursively decompose and process arbitrarily long prompts.
Prompt Definition
The RLM system prompt is provided to the root LLM at the start of each interaction. It establishes a persistent Python REPL environment where the user’s prompt is stored as a string variable prompt, and the LLM interacts by writing code that executes in the REPL.
You are a Recursive Language Model (RLM). Your job is to answer the user's prompt by interacting with a Python REPL environment.
The user's prompt is stored in the variable `prompt` as a string. You can access it by writing Python code. For example:
- `len(prompt)` returns the length of the prompt
- `prompt[:100]` returns the first 100 characters
- `prompt[1000:2000]` returns characters 1000-2000
- You can also use string methods like `prompt.find("needle")`, `prompt.split("\n")`, etc.
You have access to a function `sub_RLM(sub_prompt: str) -> str` that invokes a sub-RLM with a new prompt. This allows you to recursively call yourself on smaller pieces of the prompt. Use this to decompose the task.
Your response should be Python code that will be executed in the REPL. You can:
1. Explore the prompt by slicing, searching, etc.
2. Call `sub_RLM()` on pieces of the prompt to get answers about those pieces
3. Build up intermediate results in variables
4. Print intermediate results (but keep output concise to avoid context overflow)
5. When you have the final answer, assign it to the variable `Final`
The REPL will execute your code and return any printed output plus updated variable state. You will then get to write more code. This loop continues until you set `Final`.
Think step by step. Start by exploring the prompt to understand the task.Architecture Analysis
This prompt implements a task-state-machine pattern encoded entirely in natural language:
| State | Description | Transition Trigger |
|---|---|---|
EXPLORE | Slice, search, measure the prompt variable | LLM writes exploration code |
DECOMPOSE | Call sub_RLM() on sub-prompts | LLM identifies sub-tasks |
AGGREGATE | Build intermediate results in variables | Sub-call returns complete |
FINALIZE | Assign Final variable | LLM determines answer ready |
Key Design Elements
-
Symbolic prompt handle — The prompt lives in the REPL as
promptvariable, not in the LLM’s context window. This is the core innovation: the LLM manipulates the prompt symbolically via code. -
Recursive self-invocation —
sub_RLM()enables the LLM to spawn child instances on prompt slices. This creates a recursive decomposition tree where each node processes a manageable chunk. -
Code-as-action — The LLM’s output is executable Python, not natural language. The REPL executes it and returns state changes. This avoids “verbalizing” sub-calls (which would consume output tokens).
-
Explicit termination condition — Setting
Finalvariable ends the loop. This is a clean plan-gate pattern: the LLM decides when it has enough information. -
Context overflow prevention — Instruction to “keep output concise” acknowledges the REPL stdout is also fed back (truncated). The LLM must use variables for large intermediate data.
Performance Claims (from paper)
- 26% median gain over context compaction on GPT-5 across 4 long-context benchmarks
- 130% gain over CodeAct with sub-calls
- 13% gain over Claude Code (with context offloading)
- Scales to 10M+ token inputs (vs. 272K context window)
- Comparable or lower cost than baselines
Implications
This prompt demonstrates that inference-time scaling can be achieved purely through prompt design — no architectural changes, no fine-tuning required for the base pattern. The RLM prompt transforms any capable code-generation LLM into a long-context processor by giving it a REPL and a recursion primitive.
The pattern is model-agnostic: the paper evaluates on GPT-5 and Qwen3-Coder-480B-A35B. The prompt only requires the model to write Python and understand function calling.
Open Questions:
- How sensitive is performance to the exact wording of the system prompt? (Paper ablates in-context examples in Figure 4a)
- Can this pattern be adapted for non-code tasks (e.g., legal doc review, scientific literature synthesis)?
- What are the failure modes when
sub_RLMcalls produce syntax errors? (Paper notes Qwen3-Coder has higher syntax error rates)
Related Pages
- recursive-language-model — The paradigm concept
- longcot-mini-decomposition-prompt — Variant for complex reasoning (Appendix C.3)
- summary-agent-baseline-prompt — Baseline prompt for comparison (Appendix C.2)
- inference-time-scaling-via-prompt — Prompt-engineering framing of this achievement
- task-state-machine — Pattern used in this prompt
- code-generation — Core capability required
- context-compaction — Baseline method this outperforms
Sources
Footnotes
-
raw/prompts/articles/recursive-language-models-arxiv-2512-24601v3.md ↩