Skip to main content

Crate adk_codeact_monty

Crate adk_codeact_monty 

Source
Expand description

A Python CodeRuntime for the ADK-Rust CodeActAgent, backed by Pydantic Monty — a minimal, secure, Rust-native Python interpreter built for running LLM-generated code.

MontyRuntime lets a CodeActAgent act by writing Python: the model emits a script each turn, invokes your Tools with the built-in call_tool("name", {"arg": value}) function, composes their results with real control flow, and returns a tagged value. Monty executes that script in-process in microseconds, with no container and no subprocess — and can snapshot a paused run to bytes, which is exactly what the CodeAct suspend/resume model (HITL confirmation, long-running tools, durable checkpoints) requires.

§OS access

Operating-system effects a script attempts — filesystem reads/writes, os.getenv/os.environ, and date.today()/datetime.now() — are serviced in-place by the runtime against a host-controlled OsAccess policy. They are not tools: they never pause the agent loop. By default a runtime is fully sandboxed (no filesystem access, empty environment), but you can grant a script specific read-only or read-write paths and an explicit environment map:

use adk_codeact_monty::{MontyRuntime, PathAccess};

let runtime = MontyRuntime::builder()
    .allow_path("/data", "/srv/agent/data", PathAccess::ReadOnly)
    .allow_path("/out", "/srv/agent/out", PathAccess::ReadWrite)
    .environ_var("PROJECT", "acme")
    .build();

Network and subprocess access have no Monty OS-call surface and remain unavailable regardless of policy.

§Quick start

use std::sync::Arc;
use adk_agent::codeact::CodeActAgent;
use adk_codeact_monty::MontyRuntime;
let agent = CodeActAgent::builder()
    .name("python_agent")
    .model(model)
    .runtime(Arc::new(MontyRuntime::new()))
    .instruction("Solve the task by writing Python.")
    // .tool(Arc::new(MyTool))
    .build()?;

§Resource limits

Cap a script’s time or memory with the builder — limits ride along inside a serialized continuation, so a resumed run stays bounded:

use std::time::Duration;
use adk_codeact_monty::MontyRuntime;

let runtime = MontyRuntime::builder()
    .max_duration(Duration::from_secs(2))
    .max_memory(64 * 1024 * 1024)
    .build();

Structs§

MontyRuntime
A Python CodeRuntime for the CodeActAgent, backed by the Monty interpreter.
MontyRuntimeBuilder
Builder for MontyRuntime.
OsAccess
The OS-access policy a MontyRuntime enforces while driving a script.
OsAccessBuilder
Builder for OsAccess.
ResourceLimits
Re-export of Monty’s resource-limit configuration, for MontyRuntimeBuilder::resource_limits. Sourced through adk-code’s Monty re-exports, so the Monty release is pinned exactly once. Configuration for resource limits.

Enums§

PathAccess
Access mode for a path made available to a script.