Supervise agents with agent-runtime
@tangle-network/agent-runtime runs an AgentProfile
as an exact execution: the coding agent, provider and model you declare are the
ones that run, and spend is recorded as measured, never guessed. Its
supervise() runs a supervisor agent that spawns workers, each in its own
sandbox, under one budget they all draw from.
Use it when one agent should split a task across workers and you want a hard budget over the whole tree. For a fixed set of agents with their own tasks, use fleets. For a fixed topology written as data, use agent graphs.
Supervise from the CLI
tangle supervise "Add input validation to every API route and cover it with tests" \
--harness codex --max-tokens 200000 --max-iterations 50 --max-workers 4| Flag | Default | Effect |
|---|---|---|
--harness | claude-code | The coding agent each worker runs: Claude Code (claude-code), OpenCode (opencode), Codex (codex), Kimi Code (kimi-code) or prime. |
--model | A fast Router model | The supervisor’s model, and the only model workers may use. Pass a canonical id with its provider, such as google/<model-id>. |
--max-tokens | 200000 | Token budget for the whole run. |
--max-iterations | 50 | Iteration budget for the whole run. |
--max-workers | none | Each worker reserves max-tokens / n tokens and max-iterations / n iterations, so at most n run at once. |
--json | off | Prints the task, result, worker sandboxes, token usage and cost. Exits 1 without a winner. |
The supervisor runs on the Tangle Router with your key; each worker is a sandbox running the chosen coding agent. The command prints the result, input and output tokens, and cost, or “Unavailable” where a provider did not report them.
Supervise from TypeScript
npm install @tangle-network/agent-runtime @tangle-network/agent-interface @tangle-network/sandboxagent-runtime needs Node.js 22.19 or later.
import { randomUUID } from "node:crypto";
import * as kernel from "@tangle-network/agent-runtime/kernel";
import type { MakeWorkerAgent, SupervisorProfile } from "@tangle-network/agent-runtime/kernel";
import { Sandbox } from "@tangle-network/sandbox";
const apiKey = process.env.TANGLE_API_KEY!;
const client = new Sandbox({ apiKey, baseUrl: "https://sandbox.tangle.tools" });
const workerSeam = kernel.workerFromBackend({
backend: "sandbox",
sandboxClient: client,
maxIterations: 1,
});
const makeWorkerAgent: MakeWorkerAgent = (profile, context) =>
workerSeam({ ...profile, harness: "claude-code" }, context);
const supervisor: SupervisorProfile = {
name: "supervisor",
harness: "cli-base",
model: { default: "gemini-3.5-flash-lite", provider: "google" },
tools: {
agent_runtime_coordination_spawn_worker: true,
agent_runtime_coordination_observe_agent: true,
},
};
const result = await kernel.supervise(
supervisor,
{ goal: "Add input validation to every API route and cover it with tests" },
{
budget: { maxTokens: 200_000, maxIterations: 50 },
perWorker: { maxTokens: 50_000, maxIterations: 12 },
makeWorkerAgent,
router: { routerBaseUrl: "https://router.tangle.tools/v1", routerKey: apiKey },
runId: `supervise-${randomUUID()}`,
},
);
if (result.kind === "winner") console.log(result.out);
else console.log("no winner:", result.reason);
console.log(result.spentTotal);harness: "cli-base" makes the supervisor a model that calls tools, not a
coding agent process. The two coordination tools let it spawn workers and
watch them. Each worker is a fresh sandbox from sandboxClient.create().
result.kind is "winner", with the delivered output in out, or
"no-winner", with a reason. spentTotal holds usd, tokens and
iterations for the whole tree; usdKnown: false or tokensKnown: false
means a provider did not report that number, and it is not zero.
The model list for the supervisor is GET /v1/router-models with your Sandbox
key, or the model list.
Other entry points
| Function | Use it for |
|---|---|
runAgentTaskStream | One agent turn and a normalized event stream. |
runToolLoop | A model calling tools until it answers or stops. |
runAgentRounds | Your own plan and decide loop over agent turns. |
supervise | A supervisor driving workers under one budget. |
runGraph | A fixed topology expressed as data. See agent graphs. |
startRetainedRun | Work that must outlive the process that started it. |
Every function takes an AgentProfile, so the same profile runs on a Tangle
sandbox, in a local process or on another sandbox cloud through
providerAsSandboxClient. See Run on E2B, Daytona and more.