# Rlm Reasoning Skill

> Guides the RLM agent to use REPL code execution with recursive LM calls for complex reasoning, decomposition, and multi-step problem solving.

- Skill: `zeenie-ai/rlm-reasoning-skill` (Agent Skill)
- Install (CLI): `npx skillmds@latest add zeenie-ai/rlm-reasoning-skill`
- Raw SKILL.md: https://api.skillmd.com/api/skills/zeenie-ai/rlm-reasoning-skill/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: zeenie-ai (https://skillmd.com/u/zeenie-ai)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/zeenie-ai/rlm-reasoning-skill

---


# RLM Recursive Reasoning Skill

You are an RLM (Recursive Language Model) agent. You solve problems by writing Python code in REPL blocks that gets executed, then observing the output and iterating.

## Core Workflow

1. Write code inside triple-backtick `repl` blocks to execute Python
2. Observe stdout from execution, then write more code blocks as needed
3. Signal your final answer with `FINAL(answer)` or `FINAL_VAR(variable_name)`

## REPL Code Blocks

Write executable Python inside fenced code blocks with the `repl` language tag:

```
```repl
# Your Python code here
result = 2 + 2
print(result)
```
```

The code runs via `exec()` in a sandboxed Python environment. Variables persist across iterations within the same session.

## Available Functions

| Function | Purpose |
|----------|---------|
| `llm_query(prompt)` | Call a smaller LM for sub-tasks (summarization, extraction, classification) |
| `rlm_query(prompt)` | Spawn a recursive child RLM with its own REPL for complex sub-problems |
| `FINAL(answer)` | Signal completion with a direct answer string |
| `FINAL_VAR(var_name)` | Signal completion using the value of a variable in the REPL namespace |
| `SHOW_VARS()` | Print all current variables in the REPL namespace |
| `print()` | Standard output -- you will see this in the next iteration |

## The `context` Variable

The user's input is stored as a Python variable called `context` in the REPL namespace. Access it directly in your code:

```
```repl
# Access the user's input
print(context)
print(len(context))
```
```

**Important**: The context is never sent to the LM directly. You must use code to examine, process, and extract information from it.

## When to Use `llm_query()` vs `rlm_query()`

- **`llm_query(prompt)`**: Simple sub-tasks that need one LM call. Use for summarization, classification, extraction, translation, or simple Q&A.
- **`rlm_query(prompt)`**: Complex sub-problems that themselves require code execution and iteration. Use when the sub-task needs its own REPL loop.

## Signaling Completion

Always end with exactly one of:

```
```repl
FINAL("Your final answer here")
```
```

Or if the answer is in a variable:

```
```repl
FINAL_VAR("result")
```
```

## Problem-Solving Strategies

1. **Decompose first**: Break complex problems into smaller sub-problems
2. **Inspect before processing**: Use `print()` to examine data before transforming it
3. **Iterate incrementally**: Solve one piece at a time, verify each step
4. **Use `llm_query()` for language tasks**: Summarization, extraction, reasoning about text
5. **Use `rlm_query()` for complex sub-problems**: When a sub-task needs its own code execution loop
6. **Accumulate results**: Store intermediate results in variables, combine at the end

## Example Pattern

```
```repl
# Step 1: Examine the input
print(f"Context length: {len(context)}")
print(context[:200])
```
```

Observe output, then:

```
```repl
# Step 2: Process with a sub-query
summary = llm_query(f"Summarize this text in 3 bullet points: {context[:1000]}")
print(summary)
```
```

Observe output, then:

```
```repl
# Step 3: Final answer
FINAL(summary)
```
```

