Skip to main content

CodeRuntime

Trait CodeRuntime 

Source
pub trait CodeRuntime: Send + Sync {
    // Required methods
    fn start(
        &self,
        script: &str,
        script_name: &str,
    ) -> Result<RunStep, RuntimeError>;
    fn resume(
        &self,
        snapshot: &[u8],
        with: ResumeWith,
    ) -> Result<RunStep, RuntimeError>;

    // Provided methods
    fn capabilities(&self) -> RuntimeCapabilities { ... }
    fn render_tools(&self, tools: &[Arc<dyn Tool>]) -> String { ... }
}
Available on crate features agents and codeact only.
Expand description

A step-wise, language-agnostic code interpreter capable of suspend/resume at call boundaries.

Required Methods§

Source

fn start( &self, script: &str, script_name: &str, ) -> Result<RunStep, RuntimeError>

Parse and begin executing script, running until the first external call, completion, or error.

script_name is used by the runtime for error messages (e.g. a traceback filename). A parse/compile failure is a model mistake and should be returned as Ok(RunStep::Raised), not as a RuntimeError.

Source

fn resume( &self, snapshot: &[u8], with: ResumeWith, ) -> Result<RunStep, RuntimeError>

Restore a suspended continuation (from PendingCall::dump) and resume it with the given value or error.

Used on a later turn to resume after a human confirmation decision or a long-running tool completion. Interpreter-captured callbacks (e.g. a stdout sink) are not serialized and must be re-attached by the adapter.

Provided Methods§

Source

fn capabilities(&self) -> RuntimeCapabilities

Report what this runtime can do and which language/environment it accepts.

The default assumes a fully capable runtime with an empty prompt; concrete adapters override this to describe their real environment.

Source

fn render_tools(&self, tools: &[Arc<dyn Tool>]) -> String

Render the tool catalog for the system prompt, in this runtime’s language and conventions.

How a tool is named and called is language-dependent, so the runtime owns this rendering. This is a pure function of tools — called once per invocation purely to produce prompt text. A runtime does not need to remember anything from it: argument binding is handled centrally by the driver (see bind_call_args), so there is no need to stash schemas or parameter orderings here.

The default emits a generic, language-neutral listing via default_tool_catalog; a language-specific runtime (e.g. a Python runtime) overrides this to emit idiomatic signatures or stubs the model should call. Returns an empty string when there are no tools.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§