Skip to content

refactor(interpreter): support backend-specific code execution - #75

Draft
isaacbmiller wants to merge 1 commit into
monty-upstream-basefrom
feature/interpreter-backend-support
Draft

refactor(interpreter): support backend-specific code execution#75
isaacbmiller wants to merge 1 commit into
monty-upstream-basefrom
feature/interpreter-backend-support

Conversation

@isaacbmiller

Copy link
Copy Markdown

Summary

Makes DSPy's existing code-execution modules work cleanly with constrained or remote CodeInterpreter implementations without adding a runtime abstraction or coupling core to any backend.

  • route CodeAct tools through the existing mutable CodeInterpreter.tools capability boundary instead of copying host function source into the guest
  • preserve closures, host policy, callable signatures, sync tools, and async tools during registration
  • let interpreters optionally provide generated-code guidance through execution_instructions
  • apply that guidance through immutable call-local RLM and CodeAct signatures, preserving persisted predictor schemas, demos, and concurrent calls
  • describe the existing Deno/Pyodide environment through the same optional mechanism
  • make non-UTF-8 SandboxSerializable transport independent of the base64 standard-library module by using bytes.fromhex
  • forward allow_unsafe_lm_state to any custom Parameter.load_state implementation that accepts it, rather than special-casing Predict

Motivation

Implementing a second real interpreter backend exposed places where RLM and CodeAct accidentally depended on Deno/Pyodide details despite already accepting a generic CodeInterpreter factory. These changes keep backend ownership behind the existing interpreter interface and are independently useful for constrained, remote, and capability-based interpreters.

No Monty implementation or dependency is included in this PR.

Compatibility

  • execution_instructions is optional and does not expand the required runtime-checkable CodeInterpreter protocol
  • backend guidance is appended to a call-local signature; predictor field schemas and serialized state are unchanged
  • interpreters without guidance retain existing behavior
  • caller-owned and factory-owned interpreter lifecycle semantics are unchanged

Validation

  • 120 passed, 58 skipped across RLM, CodeAct, and BaseModule focused tests
  • Deno-enabled CodeAct: 15 passed
  • Ruff passed on touched implementation and focused CodeAct tests
  • git diff --check passed

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, the exact upstream parent commit (0312f0d), so the diff contains only this upstreamable commit. The eventual target is stanfordnlp/dspy:main.

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>
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