Installation
Prerequisites
- Python 3.11 or higher
- An API key from a supported LLM provider (OpenAI, Anthropic, etc.)
Using uv (Recommended)
Optional: Modal Support
For cloud-based sandboxed execution:Optional: Docker Support
For containerized execution, ensure Docker is installed and running:Your First RLM Call
Step 1: Set Up API Keys
Create a.env file in your project root:
Step 2: Basic Usage
Step 3: Enable Verbose Output
- Each iteration’s LM response
- Code blocks being executed
- Stdout/stderr from execution
- Final answer when reached
Understanding the RLM Class
Constructor Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
backend | str | "openai" | LM provider backend |
backend_kwargs | dict | None | Backend-specific configuration |
environment | str | "local" | Execution environment type |
environment_kwargs | dict | None | Environment configuration |
max_depth | int | 1 | Maximum recursion depth |
max_iterations | int | 30 | Max REPL iterations per call |
custom_system_prompt | str | None | Override default system prompt |
other_backends | list | None | Additional backends for sub-calls |
other_backend_kwargs | list | None | Configs for additional backends |
logger | RLMLogger | None | Logger for trajectory tracking |
verbose | bool | False | Enable console output |
The completion() Method
prompt: The main context/input (string or dict). This becomes thecontextvariable in the REPL.root_prompt: Optional hint shown to the root LM (useful for Q&A tasks).
RLMChatCompletion with:
response: The final answer stringusage_summary: Token usage statisticsexecution_time: Total time in secondsroot_model: Model name usedprompt: Original input
Choosing an Environment
RLM supports three execution environments:Local (Default)
Code runs in the same Python process with sandboxed builtins.Cons: Less isolation from host process
Docker
Code runs in a Docker container with full isolation.Cons: Requires Docker, slower startup
Modal
Code runs in Modal’s cloud sandboxes for full isolation.Cons: Requires Modal account, network latency
Choosing a Backend
OpenAI
Anthropic
Portkey (Router)
OpenRouter
vLLM (Local)
Logging and Debugging
Enable Logging
Log File Format
Logs are JSON-lines files with:Visualizer
Use the included visualizer to explore trajectories:.jsonl log files to visualize:
- Iteration timeline
- Code execution results
- Sub-LM call traces
- Token usage