Skip to main content

Module programmatic_tool_caller

Module programmatic_tool_caller 

Source
Expand description

programmatic_tool_caller: lets the agent orchestrate its other tools with Python code.

The model calls this tool with a code string; the code runs in a Monty interpreter with every other registered tool exposed as an async function taking keyword arguments, so the model can chain, loop over, filter and parallelize tool calls in one turn. Only text the code passes to print() is returned to the model.

Monty’s VM implements no host operations: no filesystem, environment, network or process access exists in the bytecode, and time and recursion limits are enforced by the VM. The only way out is the tool functions handed in here, so the code reaches exactly what the agent’s tools reach.

§Isolation

The interpreter runs in a separate worker process when one is available, so a crash inside it (a stack overflow, an allocator abort) ends only the worker, and the memory limit is a hard cap on the worker’s allocations. The worker is the monty binary of monty-runtime at the exact version this crate pins (MONTY_WORKER_VERSION):

cargo install monty-runtime --version 1.5.0 --locked

Isolation::Auto (the default) looks for the binary in this order: the MONTY_BIN environment variable when it names a file, then monty on PATH, then a target/debug or target/release build in the cargo workspace of the running executable. Isolation::Subprocess names the binary explicitly. Without one, or when a found binary other than MONTY_BIN cannot start, the interpreter runs in this process with a warning. In-process, each interpreter step runs on its own thread with a 256 MiB stack and arguments are converted at most 128 levels deep, so nested data cannot overflow the host’s stack; the memory limit then only bounds single allocations (the VM checks each one against it, not the process total), so for a hard cap use a worker. The subprocess transport needs the monty-pool feature (on by default).

Inner calls run through ToolAgent::call_tool_without_interrupts, the agent’s full per-tool pipeline (hooks, interventions, middleware): a denied call raises a catchable RuntimeError in the code, and a call that needs approval is refused the same way, since the code cannot wait for a human. The outer call still completes, and is never run again on resume.

Structs§

MakeProgrammaticToolCallerOptions
Options for make_programmatic_tool_caller (MakeProgrammaticToolCallerOptions).
MakeProgrammaticToolCallerOptionsBuilder
Use builder syntax to set the inputs and finish with build().
ProgrammaticToolCaller
The programmatic_tool_caller tool: runs model-written Python with the agent’s other tools exposed as async functions.
ProgrammaticToolCallerConfig
The portable builtinTools.programmatic_tool_caller config (ProgrammaticToolCallerConfig).
ProgrammaticToolCallerConfigBuilder
Use builder syntax to set the inputs and finish with build().

Enums§

Isolation
Where the interpreter runs. See the module docs.

Constants§

DEFAULT_PROGRAMMATIC_TOOL_CALLER_DESCRIPTION
The description shown to the model (DEFAULT_PROGRAMMATIC_TOOL_CALLER_DESCRIPTION).
DEFAULT_PROGRAMMATIC_TOOL_CALLER_TIMEOUT
The wall-clock ceiling for a run, tool calls included, when none is configured.
MONTY_WORKER_ENV
The environment variable naming the worker binary for Isolation::Auto, shared with Monty’s other language bindings.
MONTY_WORKER_VERSION
The monty-runtime version whose monty binary serves as the worker: the protocol must match the monty-pool this crate links, so install exactly this version.

Functions§

make_programmatic_tool_caller
Creates a programmatic tool caller.
programmatic_tool_caller
Builds the tool from the portable config: the timeout is in seconds, and a negative or non-finite one ends every run at once.