Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Run manually: pre-commit run --all-files

default_language_version:
python: python3.12
python: python3

repos:
# Ruff - Fast Python linter and formatter
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ All notable changes to this project are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.15] - 2026-12-03

### Changed
- Pinned the `dspy` dependency to `>=3.5,<3.6` so fresh installs get DSPy 3.5, where `dspy.RLM` is a stable module.
- Updated the DSPy RLM adapter to the 3.5 constructor: `max_iters` replaces the removed `max_iterations` argument. `sub_lm` and `dspy.LM(...)` construction are unchanged and work without a LiteLLM install, because DSPy 3.5 uses the built-in lm15 engine by default.
- Raised the recorded latest-known and minimum-recommended DSPy versions in the version checker to 3.5.0, matching the pin.

### Added
- Optional DSPy RLM History passthrough: if `context["history"]` is a `dspy.History`, a JSON string, or a dict, it is passed into the RLM call. The returned history is serialized as `history_json` in episode metadata so a later run can reload it. History replays conversation evidence only; it does not restore live interpreter variables.

### Notes
- This is the first intended PyPI release since 0.1.13. It also includes the 0.1.14 GitHub Actions dependency bumps (`actions/checkout` 4 to 6, `actions/cache` 4 to 5, `astral-sh/setup-uv` 4 to 7, and `actions/upload-artifact` 4 to 7), which were tagged on GitHub but not published to PyPI.
- LiteLLM is optional in DSPy 3.5. Install `dspy[litellm]` only if you need the compatibility engine for a provider the native lm15 engine does not support.

## [0.1.14] - 2026-09-05

### Changed
Expand Down Expand Up @@ -157,3 +171,5 @@ Initial public release of **RLM Code**.
[0.1.9]: https://github.com/SuperagenticAI/rlm-code/releases/tag/v0.1.9
[0.1.8]: https://github.com/SuperagenticAI/rlm-code/releases/tag/v0.1.8
[0.1.7]: https://github.com/SuperagenticAI/rlm-code/releases/tag/v0.1.7
[0.1.15]: https://github.com/SuperagenticAI/rlm-code/releases/tag/v0.1.15
[0.1.14]: https://github.com/SuperagenticAI/rlm-code/releases/tag/v0.1.14
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ RLM Code implements the [Recursive Language Models](https://arxiv.org/abs/2512.2

RLM Code wraps this algorithm in an interactive terminal UI with built-in benchmarks, trajectory replay, and observability.

## Release v0.1.15

DSPy 3.5 compatibility release: pin `dspy` to `>=3.5,<3.6`, and update the DSPy RLM adapter to the 3.5 `max_iters` constructor. Optional RLM History save and reload is available through `context["history"]` and `history_json` in episode metadata.

This is the first intended PyPI release since 0.1.13. It also includes the 0.1.14 GitHub Actions dependency bumps, which were tagged on GitHub but not published to PyPI.

## Release v0.1.14

Hygiene release: GitHub Actions dependency bumps so CI, pre-commit, docs deploy, and release workflows stay current.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<p class="rlm-tagline">Research Playground & Evaluation OS for Recursive Language Model Agentic Systems</p>

<span class="rlm-badge rlm-badge--purple">v0.1.14</span>
<span class="rlm-badge rlm-badge--purple">v0.1.15</span>
<span class="rlm-badge rlm-badge--green">Python 3.11+</span>
<span class="rlm-badge rlm-badge--blue">Apache 2.0</span>

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "rlm-code"
version = "0.1.14"
version = "0.1.15"
description = "RLM Code: Research Playground & Evaluation OS for Recursive Language Model Agentic Systems"
readme = "README.md"
license = "Apache-2.0"
Expand All @@ -31,7 +31,7 @@ classifiers = [
requires-python = ">=3.11"
dependencies = [
"click",
"dspy",
"dspy>=3.5,<3.6",
"rich",
"requests",
"pyyaml",
Expand Down
2 changes: 1 addition & 1 deletion rlm_code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
through natural language interactions.
"""

__version__ = "0.1.14"
__version__ = "0.1.15"
__author__ = "Super Agentic AI"
4 changes: 2 additions & 2 deletions rlm_code/core/version_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from rich.panel import Panel

# Minimum recommended DSPy version
MIN_RECOMMENDED_VERSION = "2.5.0"
LATEST_KNOWN_VERSION = "3.0.4"
MIN_RECOMMENDED_VERSION = "3.5.0"
LATEST_KNOWN_VERSION = "3.5.0"


def get_dspy_version() -> str | None:
Expand Down
90 changes: 74 additions & 16 deletions rlm_code/rlm/frameworks/dspy_rlm_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def doctor(self) -> tuple[bool, str]:
except Exception:
return (
False,
"dspy not installed. Install with: pip install dspy",
"dspy not installed. Install with: pip install 'dspy>=3.5,<3.6'",
)

try:
Expand Down Expand Up @@ -75,45 +75,58 @@ def run_episode(
llm_connector=llm_connector,
)

# DSPy 3.5 renamed this constructor argument from max_iterations to max_iters.
rlm = dspy.RLM(
"context, query -> answer",
max_iterations=max(2, int(max_steps)),
max_iters=max(2, int(max_steps)),
sub_lm=lm,
)

# The runner only passes lightweight metadata today; preserve it as context.
context_payload: Any = context if context is not None else {"workdir": workdir}
# A context["history"] value is RLM conversation History, not task context.
context_payload, history = self._prepare_context(context, workdir)
call_kwargs: dict[str, Any] = {"context": context_payload, "query": task}
if history is not None:
call_kwargs["history"] = history
with dspy.context(lm=lm):
prediction = rlm(context=context_payload, query=task)
prediction = rlm(**call_kwargs)

answer = self._extract_answer(prediction)
reward = 0.35 if answer else -0.1
history_json = self._serialize_history(getattr(prediction, "history", None))
observation: dict[str, Any] = {
"answer": answer,
"raw_prediction_type": type(prediction).__name__,
}
if history_json is not None:
observation["history_json"] = history_json
steps = [
FrameworkStepRecord(
action="dspy_rlm_answer",
observation={
"answer": answer,
"raw_prediction_type": type(prediction).__name__,
},
observation=observation,
reward=reward,
done=bool(answer),
)
]

metadata: dict[str, Any] = {
"framework": self.framework_id,
"adapter_mode": self.adapter_mode,
"reference_impl": self.reference_impl,
"model_provider": provider or None,
"model_name": model_name or None,
"timeout_seconds": exec_timeout,
}
if history_json is not None:
metadata["history_json"] = history_json

return FrameworkEpisodeResult(
completed=bool(answer),
final_response=answer or "DSPy RLM run completed with empty output.",
steps=steps,
total_reward=reward,
usage_summary=self._usage_summary(llm_connector),
metadata={
"framework": self.framework_id,
"adapter_mode": self.adapter_mode,
"reference_impl": self.reference_impl,
"model_provider": provider or None,
"model_name": model_name or None,
"timeout_seconds": exec_timeout,
},
metadata=metadata,
)

def _resolve_lm(
Expand Down Expand Up @@ -158,6 +171,51 @@ def _resolve_model_spec(*, provider: str, model_name: str) -> str:
normalized_provider = aliases.get(provider, provider)
return f"{normalized_provider}/{model_name}"

@staticmethod
def _prepare_context(context: dict[str, Any] | None, workdir: str) -> tuple[Any, Any]:
if context is None:
return {"workdir": workdir}, None
if not isinstance(context, dict):
return context, None
payload = dict(context)
raw_history = payload.pop("history", None)
if raw_history is None:
return payload, None
return payload, DSPyRLMFrameworkAdapter._coerce_history(raw_history)

@staticmethod
def _coerce_history(raw: Any) -> Any:
if raw is None:
return None
if not isinstance(raw, (str, dict)):
return raw
try:
import dspy
except Exception as exc:
raise RuntimeError("dspy is required to load RLM History from context.") from exc
history_cls = getattr(dspy, "History", None)
if history_cls is None:
raise RuntimeError(
"Installed dspy version does not expose dspy.History. Upgrade DSPy to 3.5 or later."
)
try:
if isinstance(raw, str):
return history_cls.model_validate_json(raw)
return history_cls.model_validate(raw)
except Exception as exc:
raise RuntimeError(f"Failed to load dspy.History from context: {exc}") from exc

@staticmethod
def _serialize_history(history: Any) -> str | None:
dump = getattr(history, "model_dump_json", None)
if not callable(dump):
return None
try:
value = dump()
except Exception:
return None
return value if isinstance(value, str) else None

@staticmethod
def _extract_answer(prediction: Any) -> str:
# Prediction object path (preferred)
Expand Down
95 changes: 88 additions & 7 deletions tests/rlm/test_dspy_rlm_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,27 @@ def test_doctor_reports_missing_rlm_feature():
assert "does not expose dspy.RLM" in detail


def test_run_episode_with_mocked_dspy():
adapter = DSPyRLMFrameworkAdapter(workdir="/tmp/w")

def _install_fake_dspy(*, history=None, capture=None):
class _FakeLM:
def __init__(self, model_spec: str):
self.model_spec = model_spec

class _FakeRLM:
def __init__(self, signature: str, max_iterations: int, sub_lm): # noqa: ARG002
def __init__(self, signature: str, max_iters: int, sub_lm): # noqa: ARG002
self.signature = signature

def __call__(self, *, context, query): # noqa: ARG002
return SimpleNamespace(answer="dspy rlm result")
self.max_iters = max_iters
self.sub_lm = sub_lm
if capture is not None:
capture["max_iters"] = max_iters
capture["sub_lm"] = sub_lm

def __call__(self, *, context, query, history=None): # noqa: ARG002
if capture is not None:
capture["context"] = context
capture["query"] = query
capture["history"] = history
returned_history = history
return SimpleNamespace(answer="dspy rlm result", history=returned_history)

fake_dspy = ModuleType("dspy")
fake_dspy.LM = _FakeLM
Expand All @@ -52,6 +60,13 @@ def _ctx(lm): # noqa: ARG001
yield

fake_dspy.context = _ctx
return fake_dspy


def test_run_episode_with_mocked_dspy():
adapter = DSPyRLMFrameworkAdapter(workdir="/tmp/w")
capture: dict = {}
fake_dspy = _install_fake_dspy(capture=capture)
connector = SimpleNamespace(current_model="gpt-4o-mini", model_type="openai")

with patch.dict(sys.modules, {"dspy": fake_dspy}):
Expand All @@ -67,3 +82,69 @@ def _ctx(lm): # noqa: ARG001
assert result.completed is True
assert result.final_response == "dspy rlm result"
assert result.metadata["framework"] == "dspy-rlm"
assert capture["max_iters"] == 4
assert capture["query"] == "test task"


def test_run_episode_history_passthrough():
adapter = DSPyRLMFrameworkAdapter(workdir="/tmp/w")
capture: dict = {}
fake_dspy = _install_fake_dspy(capture=capture)
incoming = SimpleNamespace(
messages=[{"role": "user", "content": "prior"}],
model_dump_json=lambda: '{"messages":[{"role":"user","content":"prior"}]}',
)
connector = SimpleNamespace(current_model="gpt-4o-mini", model_type="openai")

with patch.dict(sys.modules, {"dspy": fake_dspy}):
result = adapter.run_episode(
task="what next",
llm_connector=connector,
max_steps=3,
exec_timeout=30,
workdir="/tmp/w",
context={"workdir": "/tmp/w", "history": incoming, "note": "keep-me"},
)

assert capture["history"] is incoming
assert capture["context"] == {"workdir": "/tmp/w", "note": "keep-me"}
assert result.metadata["history_json"] == '{"messages":[{"role":"user","content":"prior"}]}'
assert result.steps[0].observation["history_json"] == result.metadata["history_json"]


def test_coerce_and_serialize_real_dspy_history():
import dspy

saved = dspy.History(messages=[]).model_dump_json()
loaded = DSPyRLMFrameworkAdapter._coerce_history(saved)
assert isinstance(loaded, dspy.History)
assert loaded.messages == []
reloaded = DSPyRLMFrameworkAdapter._coerce_history({"messages": []})
assert isinstance(reloaded, dspy.History)
assert DSPyRLMFrameworkAdapter._serialize_history(reloaded) == saved


def test_real_dspy_35_constructs_lm_and_rlm():
import importlib.metadata

import dspy

version = importlib.metadata.version("dspy")
assert version.startswith("3.5"), version

adapter = DSPyRLMFrameworkAdapter(workdir="/tmp/w")
ok, detail = adapter.doctor()
assert ok is True
assert "available" in detail

lm = adapter._resolve_lm(
dspy=dspy,
model_name="gpt-4o-mini",
provider="openai",
llm_connector=SimpleNamespace(current_model="gpt-4o-mini", model_type="openai"),
)
assert isinstance(lm, dspy.LM)

rlm = dspy.RLM("context, query -> answer", max_iters=2, sub_lm=lm)
assert rlm.max_iters == 2
assert rlm.sub_lm is lm
Loading