Skip to content

Tool Runtime Execution API

Document ID: TRT-002
File Path: docs/07-tool-runtime/execution-api.md
Version: 1.0.0
Status: Draft
Owner: AI Platform Team
Last Updated: 2026-06-27


This document defines the external contract of the Tool Runtime — how callers invoke a tool, stream its output, and cancel it, independent of the sandbox backend that runs it.

The contract is exposed over REST (HTTP/JSON) and gRPC with identical semantics, and conforms to the tool input/output schemas from the Tool Framework.


  1. Callers reference a tool by name + optional version; the Runtime resolves it.
  2. Inputs/outputs conform to the tool’s declared JSON schema.
  3. Every response includes an execution block (timing, resources, sandbox).
  4. Streaming and non-streaming share the same request schema.
  5. Executions are addressable by execution_id for status and cancellation.
  6. The contract is versioned under /v1.

MethodPathPurpose
POST/v1/executionsInvoke a tool (sync or async)
GET/v1/executions/{id}Fetch execution status/result
GET/v1/executions/{id}/streamStream output (SSE)
POST/v1/executions/{id}/cancelCancel a running execution
GET/v1/toolsList available tools (registry view)
GET/v1/tools/{name}Tool metadata + input schema
GET/healthz, /readyz, /metricsOperations

gRPC exposes Invoke, InvokeStream, GetExecution, Cancel, ListTools on the ToolRuntime service.


{
"tool": "http.request",
"version": "1.2.0",
"tenant": "acme",
"project": "support-bot",
"input": {
"method": "GET",
"url": "https://api.example.com/orders/123"
},
"context": {
"workflow_id": "wf_01H...",
"agent": "order-assistant",
"correlation_id": "trace_01H..."
},
"limits": {
"timeout_ms": 30000,
"max_output_bytes": 1048576
},
"mode": "sync",
"stream": false,
"idempotency_key": "exec-order-123"
}
FieldNotes
tool / versionResolved via registry; omitting version uses the active version
inputValidated against the tool’s input schema before execution
contextPropagated to the tool’s execution context
limitsPer-call overrides bounded by tenant/tool maximums
modesync (block for result) or async (return id, poll/stream)
idempotency_keyDedupes retried invocations

{
"execution_id": "exec_01H...",
"tool": "http.request",
"version": "1.2.0",
"status": "succeeded",
"output": {
"status_code": 200,
"body": "{\"order\":\"123\",\"state\":\"shipped\"}"
},
"execution": {
"sandbox": "wasm",
"worker": "worker-7",
"queued_ms": 3,
"started_ms": 12,
"duration_ms": 84,
"resources": { "cpu_ms": 70, "peak_memory_mb": 22 }
}
}

Output is validated against the tool’s output schema before return.


With mode: "async", the Runtime returns immediately:

{ "execution_id": "exec_01H...", "status": "running" }

Callers then poll GET /v1/executions/{id} or attach to the stream. Async is preferred for long-running tools and for workflow steps that checkpoint (see Worker Pool §8).


When stream: true (or via /stream), output is delivered as ordered events, aligned with the framework’s streaming protocol:

Event typeMeaning
startExecution started; carries sandbox + worker
stdout / stderrIncremental output chunks
progressStructured progress (0–100 or stage)
partialIncremental structured output
logTool-emitted log line
doneTerminal success; carries final output + execution
errorTerminal failure; carries normalized error

REST uses Server-Sent Events; gRPC uses a server stream. Exactly one terminal event (done or error) is emitted.


POST /v1/executions/{id}/cancel requests cooperative cancellation, escalating to forced sandbox teardown:

1. Signal the tool (cancellation token / SIGTERM)
2. Grace period (configurable, default 5s)
3. Force-destroy the sandbox (SIGKILL + reclaim)

Cancellation is idempotent. A cancelled execution returns status: "cancelled" with any partial output captured before teardown.


queued → scheduled → running → (succeeded | failed | cancelled | timed_out)

GET /v1/executions/{id} returns the current status, and for terminal states the full result. Execution records are retained for a configurable window for status queries and audit.


{
"error": {
"code": "resource_exceeded",
"message": "Execution exceeded memory limit (1Gi).",
"type": "execution_error",
"retryable": false,
"details": { "limit": "1Gi", "observed": "1.1Gi" }
}
}
CodeHTTPRetryableMeaning
unauthenticated401noMissing/invalid credentials
forbidden403noPermission/policy denied
tool_not_found404noUnknown tool or version
invalid_input400noInput failed schema validation
invalid_output502noTool produced schema-invalid output
timeout504yesExceeded execution timeout
resource_exceeded400noHit CPU/memory/disk limit
sandbox_unavailable503yesCould not provision a sandbox
tool_error422maybeTool ran but returned an error
rate_limited429yesTenant/tool rate limit hit

  • idempotency_key dedupes retried invocations within its TTL, returning the original execution.
  • Only tools declared idempotent in their manifest are auto-retried by the Retry Engine; others surface the error to the caller.

/v1 is additive-compatible; breaking changes introduce /v2. Sandbox backend changes never affect the contract version.




VersionDateDescription
1.0.02026-06-27Initial Tool Runtime Execution API