# Dspy Rlm Module

> When to use RLM vs ReAct vs plain ChainOfThought

- Skill: `j33bs/dspy-rlm-module` (Agent Skill)
- Install (CLI): `npx skillmds@latest add j33bs/dspy-rlm-module`
- Raw SKILL.md: https://api.skillmd.com/api/skills/j33bs/dspy-rlm-module/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: j33bs (https://skillmd.com/u/j33bs)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/j33bs/dspy-rlm-module

---


# RLM (Recurrent Language Model) Module

## 🎯 Trigger Conditions
Use when deciding between RLM, ReAct, and ChainOfThought for tool use or multi-step reasoning.

## 📚 Prerequisites
- `dspy` package installed
- Understanding of tool use patterns
- Clear reasoning requirements

## 🛠️ Module Comparison

### 1. ChainOfThought (CoT)
```python
class CoTReasoning(dspy.Module):
    def __init__(self):
        self.reason = dspy.ChainOfThought("question -> reasoning -> answer")
    
    def forward(self, question):
        return self.reason(question=question)
```

**When to use:**
- Simple reasoning tasks
- No tool use required
- Single-step reasoning sufficient

### 2. ReAct (Reason + Act)
```python
class ReActAgent(dspy.Module):
    def __init__(self, tools):
        self.react = dspy.ReAct(tools, max_steps=5)
    
    def forward(self, question):
        return self.react(question=question)
```

**When to use:**
- Tool use required
- Multi-step reasoning
- Dynamic decision making

### 3. RLM (Recurrent Language Model)
```python
class RLMAgent(dspy.Module):
    def __init__(self):
        self.rlm = dspy.RLM(
            signature=YourSignature,
            n=3,  # Number of recurrences
            temperature=0.7
        )
    
    def forward(self, question):
        return self.rlm(question=question)
```

**When to use:**
- Complex multi-step reasoning
- Iterative refinement needed
- High-quality output required
- Can afford compute cost

## 📊 Decision Matrix

| Pattern | Tool Use | Multi-Step | Quality | Cost |
|---|---|---|---|---|
| CoT | ❌ | ❌ | Good | Low |
| ReAct | ✅ | ✅ | Very Good | Medium |
| RLM | ✅ | ✅ | Excellent | High |

## ⚠️ Pitfalls
- **RLM complexity**: Can be overkill for simple tasks
- **ReAct loops**: Watch for infinite loops
- **CoT depth**: Limited to single reasoning step
- **Compute budget**: RLM requires significant resources

## 📖 References
- [DSPy Modules](https://dspy-docs.vercel.app/docs/building-blocks/modules)
- [ReAct Pattern](https://arxiv.org/abs/2210.03629)
- [RLM Documentation](https://dspy-docs.vercel.app/docs/deep-dive/modules/rlm)

