
Dspy Rlm Module
When you have a 500k token log file or an entire codebase that won't fit in a single prompt, this skill gives Claude a sandboxed Python REPL to explore it recursively. The LLM writes code to grep, slice, and summarize chunks, issuing sub-queries until it can answer. Requires Deno installed locally. The big gotcha is cost: one RLM call can spawn dozens of inner LLM calls, so keep max_llm_calls tight and use a cheap model like gpt-4o-mini for the inner loop. Overkill for anything under 100k tokens, but genuinely useful for log analysis, codebase audits, or any task where the model needs to write code to probe data it can't hold in working memory.
- GitHub stars
- 250
- last updated
- May 25, 2026
Install
$ npx -y skills add intertwine/dspy-agent-skills --skill dspy-rlm-module --agent claude-codeInstalls into .claude/skills of the current project.
Files
dspy.RLM — Recursive Language Model
dspy.RLM runs the LLM in a sandboxed Python REPL (Pyodide/WASM via Deno) with access to the full context as variables. The LLM writes code to slice, grep, summarize, and recursively sub-query the data, iterating until it can answer. Use it when the context is too large to cram into a single prompt.
Prerequisites
- Deno installed (for the default
PythonInterpreter):brew install denoor see https://deno.land. The interpreter is a Pyodide-in-WASM sandbox spawned by Deno. - A sub-LM for inner calls — usually a cheaper model than the outer LM. Defaults to
dspy.settings.lm.
Canonical usage
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-4o"))
sub_lm = dspy.LM("openai/gpt-4o-mini") # cheap inner model
rlm = dspy.RLM(
"context, query -> answer",
max_iterations=20,
max_llm_calls=50,
max_output_chars=10_000,
sub_lm=sub_lm,
tools=[],
verbose=False,
)
result = rlm(
context=open("huge_log.txt").read(), # can be 500k+ tokens
query="Summarize every unique error class and how many times each appeared.",
)
print(result.answer)
Full constructor
Sponsors
Details
- Repository
- github.com/intertwine/dspy-agent-skills
- Categories
- Documentation, AI & Agent Building, Python
- License
- MIT
- First seen
- Jun 11, 2026