tools with an explicit JSON Schema and embedded source.
The source runs in Monty, with JSON arguments and a host-provided HTTP interface.
New to managed agents? Follow the Managed Agents quickstart
to test a function, save the configuration, and start a conversation. This page
is the reference for the function and HTTP interfaces.
name. Set entrypoint: main to use a
different function. The function must be async and accept one argument. Each
invocation starts with fresh script state.
Tool definition
The runtime groups these functions in the
managed_python toolkit. The model
sees the name, description, and schema. It supplies one JSON object and
MeshAgent calls the async entrypoint with that object as a dictionary.
You can return a JSON-compatible value or import a result type from
meshagent.api.messaging, such as TextContent, JsonContent, LinkContent,
EmptyContent, ErrorContent, or FileContent. Return a PDF with
FileContent(name="report.pdf", mime_type="application/pdf", data=pdf_bytes),
or an image with the corresponding image MIME type and bytes. OpenAI Responses
and Anthropic Messages pass supported PDFs and images to the model as
attachments. The CLI displays file results with their MIME type and base64
data field. Printing captures logs separately from the result.
Use context.caller.id for the authenticated caller’s identity and context.on_behalf_of.id for a verified delegated identity. Each principal is None when unavailable. A tool can raise PermissionError to report permission_denied and let the managed-agent turn continue.
The sandbox supports Python data processing and the injected HTTP interface. It
does not provide a general CPython environment: do not assume requests,
aiohttp, an SDK package, filesystem APIs, subprocesses, or arbitrary imports are
available. json and the examples on this page are supported; test additional
language or library features with the exact source using agent tools test.
Schemas
Use a JSON Schema Draft 2020-12 object schema. Put only mandatory properties inrequired. Omit additionalProperties to allow extra fields or
set it to false to reject them. References must resolve within the schema
document. Annotations in the Python source do not generate the schema.
MeshAgent validates the JSON arguments before running the script. An invalid
call returns error content to the agent with the failed constraint and, when
available, its JSON Pointer. The CLI displays the validation message even with
--no-debug.
When using OpenAI, MeshAgent enables constrained tool argument generation for
schemas that pass its strict-mode compatibility check. For other schemas,
OpenAI generates arguments in best-effort mode and MeshAgent still validates
them against the supplied schema.
HTTP and optional secrets
Use a direct URL for requests that do not need a configured connection:http.request supports GET, POST, PUT, PATCH, DELETE, HEAD, and
OPTIONS. Pass scalar query values in params, custom headers in headers,
and either a JSON value in json or a string in body. The response exposes
status, status_code, headers, text, json(), and raise_for_status().
HTTP error statuses are returned normally until raise_for_status() is called.
Transport errors and invalid requests raise Python exceptions.
Request arguments
response.json() and response.raise_for_status() are synchronous methods after
the awaited request. Response headers use lowercase names and omit set-cookie.
The interface returns text and JSON; it does not expose streaming responses,
binary uploads, multipart file uploads, or a Python HTTP client session.
Connections without secret references make ordinary HTTP requests. Connections
with a secret use MeshAgent’s secret proxy, which checks permission and injects
the configured headers. The managed agent’s run_as service account needs the
secrets:proxy scope and the secret’s use_proxy permission. Neither secret
values nor the runtime’s bearer token are supplied to the script. Secret-backed
requests cannot override the configured secret headers, and a connection’s path must
stay on its configured origin. Only configure trusted API destinations for secrets.
For an opaque secret, use_proxy_secret sends Authorization: Bearer <value>;
store only the token as the secret value. Use connection headers when an API
requires a different scheme or several headers:
prefix, which defaults
to an empty string. For HTTP Basic, store the base64-encoded username:password
as the secret value. Literal headers such as Accept are stored in the agent
configuration; do not put credentials in literal headers. The proxy checks
use_proxy for every referenced secret and sends no upstream request if any
check fails. Tool code cannot override a secret-backed header. OAuth secrets
continue to use their saved token_type and access token.
Set run_as on the agent to the service account that will make deployed calls:
run_service_as; the runtime identity also needs use_proxy_secrets on the
secret’s owning service account, as well as use_proxy on the secret itself.
See Service Account Secrets and the
HTTP Secret Proxy for permission and secret setup.
Host-controlled transport headers cannot be overridden. Direct requests do not
follow redirects. Deployed tools can call public HTTP(S) destinations; private
addresses are blocked. The runtime does not expose filesystem access, process
execution, or arbitrary Python packages.
Environment variables
Declare values inenvironment using the same name, value, and secret
shape as container environment entries. Only declared variables are visible to
the embedded Python tool through os.getenv() and os.environ:
run_as identity and
secrets:read scope. The secret must belong to that service account and allow
value access; http_only secrets cannot be exposed as environment variables.
Use connection secret headers when the script does not need to read the secret.
The tool sees only these declared entries, never the host process environment.
Test the current source before deploying
Run the actual source in your agent YAML file:result, captured logs, and HTTP request summaries. Invalid
arguments, Python errors, and timeouts fail the command with a nonzero exit code.
The local runner sets context.caller to the identity authenticated by the CLI.
When you run the test without signing in, context.caller is None. Local
tests have no room participant or delegated caller.
The Python and Rust CLIs show sanitized tool diagnostics on stderr by default.
Use the exception type and source positions to find the failing line in the
tool’s source block. Pass --no-debug to show the error code and message
alone. Local tests use the same failure codes as
room toolkits.
A PermissionError reports permission_denied, invalid tool arguments report
invalid_request, and other unhandled script errors report
tool_execution_failed. The debug flag applies to the local test and requires
no deployment management permission.
HTTP requests are live and can change data. Secret-backed local tests use your
current CLI identity and its proxy permissions. They do not impersonate the
deployed agent’s service account. Use --allow-private-http only when testing
against a local development server.
Managed agents use a dedicated Monty execution pool when deployed with the default Helm configuration. HTTP calls and secret-proxy credentials stay in the managed-agent host. Each active Python invocation reserves an interpreter until it completes, including time waiting on HTTP; idle agent connections do not reserve interpreters. The pool scales independently of managed agents.
The Python CLI installs Monty and its worker with the pydantic-monty dependency;
its packaged executable includes the worker. No separate runner installation is
needed. For a local Rust CLI source checkout, install the pinned Monty worker:
MESHAGENT_MONTY_BIN to its executable for the Rust CLI.
Execution limits
Each tool invocation has a 64 MiB sandbox memory limit and a 120-second wall-clock execution deadline. Time spent waiting on HTTP counts toward the deadline. Deployed tools and Rust CLI tests allow 10 seconds of active interpreter execution per feed, including execution after each resume. Python CLI tests allow up to 30 seconds per feed and 10 seconds per uninterrupted interpreter turn. A feed is one submission of code to Monty. It can pause for a host call and resume when the result is ready. A tool can make up to 32 HTTP calls. Each request has a 15-second timeout within the invocation deadline. HTTP request data, response bodies, and returned JSON are limited to 1 MiB. Captured logs are capped at 16 KiB, and source is limited to 64 KiB per tool.Run the local managed-agent end-to-end suite
The dedicated suite exercises the real router, room tunnel, managed-agent runtime, Monty worker, and secret-proxy IAM. A recording HTTP service and a deterministic Responses provider run on the host. The provider supports both WebSockets and SSE and requests the exact function advertised by the agent. No external LLM is needed. From a source checkout, deploy the changed components tok3s-local:
RUN_MESHAGENT_CLOUD_SMOKE=1. It requires exactly one node in
k3s-local, with this host’s name and instance type k3s, and refuses endpoints
that resolve outside this host. It temporarily points the test project’s OpenAI
settings at the fixture, creates separate secret-owner and agent service accounts,
and adds an exact-origin HTTP exception and an exact-address/port network policy
for the managed-agent pool. The roompool controller rolls out the configuration.
The suite restores settings and pool configuration, removes the network policy,
and deletes its agents, secrets, and service accounts on teardown.
The eight live cases assert:
- Saved source, schema, and connection round trips; real HTTP method, headers, query, body, and a fresh response nonce; parity with the CLI using the same YAML.
- Secret injection, denial at both the secret
use_proxyand service-accountuse_proxy_secretsgates, no upstream request on denial, and recovery after restoring permission. Secret values must not appear in provider traffic or client events. - Python exceptions, invalid arguments, missing functions, HTTP errors, and execution timeouts reaching the client as tool failures. Each case then runs a successful turn on the same agent connection.
- An explicit entrypoint and updated source after terminating and restarting the agent session.
MESHAGENT_PYTHON_HTTP_ALLOWED_ORIGINS (a JSON array), also exposed as Helm value
meshagent.kubernetes.managedAgentsRoomPool.pythonHttpAllowedOrigins. Agent specs
cannot grant this exception. Other private destinations remain blocked.
Dedicated execution pool
Helm settings undermeshagent.monty control worker resources, session admission,
gateway replicas, and autoscaling bounds. The chart configures the managed-agent
host with MESHAGENT_MONTY_ENDPOINT, MESHAGENT_MONTY_TOKEN, and
MESHAGENT_MONTY_MAX_CONNECTIONS. These are deployment settings, not agent YAML
fields. Set meshagent.monty.enabled=false to retain local interpreter execution.
Capacity exhaustion returns an error before execution. A lost worker or expired
session fails the tool call without replaying it, since an HTTP request may already
have taken effect. The execution pool drains active calls during shutdown.
Run rust/meshagent-monty-service/run-tests.sh with MESHAGENT_MONTY_BIN set to a
pinned 1.2.0 interpreter to validate the remote transport and the production HTTP
host locally. ./local-build.sh --k3s --managed-agents builds the managed-agent and
Monty service images and applies the Helm configuration.