Skip to main content

Production-grade RLMs (Recursive Language Models) with tool use, built on DSPy

Project description

[!NOTE] Read the launch post for our optimized SpreadsheetBench skill.

predict-rlm

Production focused Self-harnessed LM runtime (RLM) that allows the LM to call its sub-lm with DSPy signatures. Define your inputs, outputs, and tools — the model handles its own control flow. Get fully interpretable trajectories and performance that scales directly with model improvements. Without context rot.

Based on the Recursive Language Models paper by Alex L. Zhang, Tim Kraska, and Omar Khattab from MIT CSAIL.


Tests codecov PyPI Python Discord GitHub stars
crafted with ♥ in MTL · NYC · FLP
by Trampoline AI

Installation

uv add predict-rlm

Why RLMs?

Bitter Lesson Spectrum — from hand-written prompts to RLMs

  • Avoid context rot — The root LM only interacts with its context programmatically through the REPL, staying well within its comfortable operating range — enabling complex, long-horizon tasks that would otherwise cause models to silently degrade.
  • Bitter lesson-proof: RLMs improve as LMs improve — Unlike harnesses, which can cap or constrain the base model's capabilities, the performance, speed, and cost of RLM calls correlate directly with improvements to base model capabilities. If the base model handles 10M tokens tomorrow, the RLM handles 100M.
  • Symbolic reasoning & recursion — like algebra, RLMs express the structure of computation rather than performing each operation individually; a single line can represent 1M sub-calls — in direct contrast to agents like Claude Code that must mechanically emit each sub-agent call one at a time.
  • Interpretability — RLM trajectories are fully readable: you can trace every peek, chunk, sub-call, and verification step the model takes. This not only reveals how the model decomposed a problem, but provides concrete optimization signals which tools like GEPA can ingest to evolve the RLM's strategies.
  • Ideal for improving performance per token — RLMs allow small models to punch way above their weight (RLM(GPT-5-mini) outperforms base GPT-5) providing great opportunities for reducing costs or stretching limited compute budgets without sacrificing quality.

Features

Classic harness vs RLM architecture

  • Multimodal — process images, documents, audio, and video through sub-LM calls using native provider multimodal APIs.
  • Async tool calling — native RLM async support in the WASM sandbox, enabling concurrent sub-LM invocations and tool calls
  • Prompt-optimized skills & tools — predict-rlm skills comes tested and optimized to ensure maximum LM interoperability and performance, bundling instructions, PyPI packages, and tools for domain-specific tasks
  • Simple file I/O — pass local or cloud files as typed inputs and outputs via File, keeping interop with your existing data pipelines straightforward. (S3 files support soon)
  • Structured sub-LM calls — native Pydantic and DSPy signature support for type-safe sub-LM invocations with structured outputs

Demos

Description Input / Output Preview
Document Analysis — Analyze documents and extract key dates, entities, and financial information into a structured report Input: PDFs
Output: Structured briefing report (example output)
Document Redaction — Redact PII from PDFs based on a policy, then verify the redactions visually Input: PDFs
Output: Redacted PDFs (example output)
Invoice Processing — Extract vendor info, line items, and totals from PDF invoices into a consolidated Excel spreadsheet Input: PDF invoices
Output: Excel spreadsheet (example output)
Contract Comparison — Compare two contract versions and produce a structured diff report with per-section analysis Input: 2 PDF contracts
Output: Structured diff report (example output)

Quick start

With your coding agent

Install the predict-rlm skill in Claude Code, Codex, Cursor, or any compatible coding agent:

npx skills add Trampoline-AI/predict-rlm

Then ask your agent to build an RLM:

❯ /rlm build an RLM that extracts line items from PDF invoices into a spreadsheet

Quick Example

import dspy
from predict_rlm import File, PredictRLM

class AnalyzeImages(dspy.Signature):
    """Analyze images and answer the query. Load each image as a base64 data
    URI and use predict() with dspy.Image to extract visual information."""
    images: list[File] = dspy.InputField()
    query: str = dspy.InputField()
    answer: str = dspy.OutputField()

rlm = PredictRLM(
    AnalyzeImages,
    lm="openai/gpt-5.4",
    sub_lm="openai/gpt-5.1",
)

result = rlm(
    images=[File(path="page.png")],
    query="Extract all visible text, then count each letter A-Z (case-insensitive).",
)

print(result.answer)

Using the spreadsheet skill

The optimized spreadsheet skill is built in. Import it and pass it through skills=[spreadsheet] so the RLM gets the spreadsheet-specific instructions, openpyxl, pandas, formulas, and the formula_eval verification module inside its sandbox.

import dspy

from predict_rlm import File, PredictRLM
from predict_rlm.skills import spreadsheet


class UpdateWorkbook(dspy.Signature):
    """Update the workbook following the request.

    Use openpyxl for workbook edits, Excel formulas for derived values, and
    verify formulas before returning the final .xlsx file.
    """

    workbook: File = dspy.InputField(desc="Input .xlsx workbook")
    request: str = dspy.InputField(desc="Requested spreadsheet changes")
    updated_workbook: File = dspy.OutputField(desc="Updated .xlsx workbook")


rlm = PredictRLM(
    UpdateWorkbook,
    lm="openai/gpt-5.4",
    sub_lm="openai/gpt-5.1",
    skills=[spreadsheet],
)

result = rlm(
    workbook=File(path="model.xlsx"),
    request="Add a Summary sheet with revenue by quarter and formulas for totals.",
)

print(result.updated_workbook.path)

For workflows that combine source documents and spreadsheets, compose skills:

from predict_rlm.skills import pdf, spreadsheet

rlm = PredictRLM(ProcessInvoices, skills=[pdf, spreadsheet])

Next steps

  • How it works — understand the sandbox, REPL loop, signatures, and file I/O
  • API reference — constructor params for PredictRLM, File, and Skill
  • Skills — define, compose, and mount custom skills
  • Examples — end-to-end demos with setup instructions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

predict_rlm-0.4.0.tar.gz (120.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

predict_rlm-0.4.0-py3-none-any.whl (135.5 kB view details)

Uploaded Python 3

File details

Details for the file predict_rlm-0.4.0.tar.gz.

File metadata

  • Download URL: predict_rlm-0.4.0.tar.gz
  • Upload date:
  • Size: 120.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for predict_rlm-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5539b7da2898e6685ce0b24dfac1e911031efcda0924efa81166d7b2c71de496
MD5 d73aba34bb9e955e587b920ee453ae29
BLAKE2b-256 c8a36b8c42b0718b41413478bcbc8026c3539cd1bc341db661e7a9d1ea07428d

See more details on using hashes here.

Provenance

The following attestation bundles were made for predict_rlm-0.4.0.tar.gz:

Publisher: release.yml on Trampoline-AI/predict-rlm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file predict_rlm-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: predict_rlm-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 135.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for predict_rlm-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2fea12fc7f1c54a5fd003acfb0b4ecd36cec6284343e85dde945d7502816b63
MD5 9a6ca17c51ff8796a83c7b799a3f0f11
BLAKE2b-256 3d3d94f9019ac75fd8030efeb6514a6ceb29ed554d8c5e9319a0348c6e65f174

See more details on using hashes here.

Provenance

The following attestation bundles were made for predict_rlm-0.4.0-py3-none-any.whl:

Publisher: release.yml on Trampoline-AI/predict-rlm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page