Skip to content

feat(experimental): add capability-limited Monty programs - #74

Closed
isaacbmiller wants to merge 2 commits into
monty-upstream-basefrom
feature/monty-rlm
Closed

feat(experimental): add capability-limited Monty programs#74
isaacbmiller wants to merge 2 commits into
monty-upstream-basefrom
feature/monty-rlm

Conversation

@isaacbmiller

Copy link
Copy Markdown

Summary

Adds an experimental Monty backend for optimizable, capability-limited DSPy programs and recursive code execution.

  • add MontyProgram, an optimizable DSPy Module/Parameter whose source composes real dspy.Predict, ChainOfThought, RLM, CodeAct, ProgramOfThought, ReAct, and ReActV2 syntax
  • add a persistent MontyInterpreter with stateful sessions, typed/untyped SUBMIT, recoverable guest errors, terminal worker failures, and resource limits
  • support depth-two nested RLM execution with distinct child sessions, attenuated tools, shared predictor/tool budgets, and a hard depth policy
  • validate guest predictor annotations before DSPy's general signature parser can resolve host imports
  • route CodeAct tools through CodeInterpreter.tools instead of copying host source into the guest
  • pass optional backend guidance through immutable call-local RLM/CodeAct signatures, preserving predictor schemas, demos, serialization, and concurrency
  • make non-UTF-8 SandboxSerializable transport portable with bytes.fromhex
  • generalize BaseModule.load_state flag forwarding for custom Parameter implementations

Why Monty

Monty is constrained Python rather than full CPython. With warm caches in the development orb, a usable Monty session started in roughly 3 ms and used roughly 7.5 MiB per worker, versus roughly 2.4 seconds and 165 MiB for Deno/Pyodide. This makes nested interpreter trees practical while retaining Deno as the compatibility backend.

The guest receives copied values and explicit capabilities—not ambient DSPy objects, LM credentials, host filesystem, environment, network, or arbitrary imports.

Scope

This draft intentionally excludes filesystem mounts, network access, AsyncMonty, shared pools, snapshots, and broad CPython compatibility. Those remain use-case-driven follow-ups.

Validation

  • focused Monty/RLM/CodeAct/PythonInterpreter suite: 138 passed, 124 skipped
  • Deno-enabled affected suite reached 271 passed with three stale CodeAct expectations; after correcting them, Deno-enabled CodeAct passed 15 passed
  • Ruff passed on touched implementation and focused tests
  • git diff --check passed
  • final blocker-only review found no remaining merge blockers

Repository-wide collection is blocked in this orb by unrelated missing optional dependencies: numpy, datamodel_code_generator, and Pillow.

Review setup

The GitHub App token cannot create a PR directly against stanfordnlp/dspy. This fork draft targets monty-upstream-base, which is the exact upstream parent commit (0312f0d), so the diff contains only the two intended commits. The eventual upstream target is stanfordnlp/dspy:main.

isaacbmiller and others added 2 commits July 31, 2026 14:45
Route CodeAct tools through the CodeInterpreter capability boundary, pass backend guidance through call-local signatures, support custom Parameter state loading, and make binary RLM payload transport portable across constrained interpreters.

Amp-Thread-ID: https://ampcode.com/threads/T-019fb0dc-8d11-7510-abc9-4bc180e4e6e4
Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
Add an optimizable MontyProgram and persistent MontyInterpreter with real DSPy syntax, approved host capabilities, shared budgets, resource limits, and depth-two nested RLM execution.

Amp-Thread-ID: https://ampcode.com/threads/T-019fb0dc-8d11-7510-abc9-4bc180e4e6e4
Co-authored-by: Isaac Miller <isaac@cmpnd.ai>

Copy link
Copy Markdown
Author

Superseded by #75, which contains only the generic upstreamable DSPy interpreter changes. The Monty implementation remains available on feature/monty-rlm as a separate-library/reference branch and is intentionally not proposed for DSPy main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant