dspy.RLM module supports custom tools that the model can invoke programmatically from within its Python REPL code. For production environments, the default local execution runtime (Deno WASM) can be replaced with remote, isolated cloud sandboxes (such as E2B or Daytona) using interpreter_factory.
Quickstart: Custom Tools with Real-Time Text Streaming
Pass host-side functions to thetools=[...] parameter and wrap the RLM module with dspy.streamify to observe intermediate reasoning and function invocations in real time:
How Custom Tools Work in RLM
Functions passed viatools are exposed directly in the Python interpreter’s namespace:
- Host-Side Execution: Functions execute within your host Python environment with access to databases, internal credentials, or external calculation APIs.
- Serialization: Tool outputs must be JSON-serializable (such as
int,float,str,dict, orlist). - Docstring Prompting: DSPy automatically parses docstrings and type hints so the RLM orchestrator knows when and how to call the function.
Connecting Remote Cloud Sandboxes
By default, DSPy executes generated code in a local Deno/WASMPythonInterpreter. For production workloads requiring strict hardware isolation or arbitrary package installation, you can implement the CodeInterpreter protocol and provide it via interpreter_factory.