dspy-rlm
Installation
SKILL.md
Iterative Self-Refinement with dspy.RLM
Guide the user through using DSPy's RLM (Recursive Language Model) module. RLM lets the LM explore data programmatically in a sandboxed Python REPL, writing code to examine inputs, querying sub-LMs for semantic analysis, and iterating until it produces a final answer.
Experimental. RLM is marked as experimental in DSPy. The API may change in future releases.
What is RLM
dspy.RLM implements the Recursive Language Models approach (Zhang, Kraska, Khattab 2025). Instead of feeding the full input context into the LM's prompt, RLM:
- Shows metadata only -- the LM receives type, length, and a preview of each input, not the full content.
- Lets the LM write code -- the LM generates Python in a sandboxed REPL to search, filter, aggregate, or transform the data.
- Executes in a sandbox -- code runs in a WASM-based Python interpreter (Pyodide via Deno) for safety.
- Supports sub-LM queries -- the LM can call
llm_query(prompt)to do semantic analysis on slices of the data. - Iterates -- the LM loops through code-execute-observe cycles until it calls
SUBMIT(output)with a final answer.
This makes RLM ideal for tasks where the input is too large for the context window, or where the LM needs to programmatically explore the data to find the answer.