Skip to content
Français

Delegate to subagents

Give the built-in harness bounded child agents that share its sandbox.

Use this guide to let an existing built-in harness ask a bounded reviewer for help. The child uses the parent’s sandbox, so delegation does not create an isolated branch or an independently writable workspace.

Declare a subagent with defineHarnessSubagent() and expose it as a tool of the parent harness. It borrows the parent’s sandbox but keeps its own conversation history, permissions and limits.

import { createOpenAIModelProvider } from "@elie-laloum/outpost/harness";

export const modelProvider = createOpenAIModelProvider({
  baseUrl: "https://api.openai.com/v1",
  api: "responses",
  apiKey: process.env.OPENAI_API_KEY ?? "",
});
export const model = process.env.MODEL_NAME ?? "";
import { createAgent } from "@elie-laloum/outpost/core";
import {
  createHarness,
  createHarnessFileTools,
} from "@elie-laloum/outpost/harness";
import { model, modelProvider } from "./model.ts";

export const reviewer = createAgent({
  model,
  harness: createHarness({
    modelProvider,
    instructions: "Inspect files and report findings. Do not edit files.",
    tools: [createHarnessFileTools()],
    limits: { maxSteps: 6, usage: { output: 2_000 } },
  }),
});
import { defineHarnessSubagent } from "@elie-laloum/outpost/harness";
import { reviewer } from "./reviewer.ts";

export const tools = [
  defineHarnessSubagent({
    name: "review",
    description: "Ask a reviewer to inspect repository files.",
    agent: reviewer,
  }),
];
import { createAgent } from "@elie-laloum/outpost/core";
import { createHarness } from "@elie-laloum/outpost/harness";
import { model, modelProvider } from "./model.ts";
import { tools } from "./delegation.ts";

export const coordinator = createAgent({
  model,
  harness: createHarness({
    modelProvider,
    tools,
    limits: { maxSteps: 8, maxDelegationDepth: 1, usage: { output: 5_000 } },
  }),
});
import { dispatch } from "@elie-laloum/outpost/core";
import { repository, sandboxProvider } from "./outpost.config.ts";
import { coordinator } from "./coordinator.ts";

export const result = await dispatch({
  repository,
  sandboxProvider,
  agent: coordinator,
  brief: { text: "Have the validation code reviewed, then list the risks." },
});
console.log(result.text);
// Example output: The reviewer found unchecked input in src/validation.ts.

The coordinator decides when to call review. Each call starts the reviewer with a fresh history; result.text holds the coordinator’s final answer and result.usage includes the reviewer’s tokens.

Drag to move · Ctrl + scroll to zoom
100 %
  • DelegateThe parent sends a prompt, without its conversation history. (Shared sandbox)
    • → Child : prompt
  • ChildWork with a separate history in the parent’s sandbox and files. (Shared sandbox)
    • → Parent resumes : child result
  • Parent resumesRead the child’s result and continue the main task. (Shared sandbox)

Children share the parent’s sandbox: they allocate no provider and open no workspace, so the parent sees their edits at once. Delegations run one at a time, even when the parent’s other tools run in parallel.

Each loop keeps its own step and tool-call counts, while token budgets add up across descendants.

API reference: HarnessLimits.

A tool error goes back to the parent model, unless the parent sets toolExecution: { onError: "fail" }. Cancelling the dispatch also stops the child’s model requests and commands.

API reference: HarnessLimits and HarnessSubagentOptions.

The parent’s and the child’s permissions both apply to every child tool call, including inputs rewritten by a hook. Hooks run only in the harness that declares them: the parent’s hooks do not see the child’s tool calls.

The child’s transcript goes to its harness’s conversation store and records parentConversation and parentCallId. Pass its conversation ID as continuation: { id } to a dispatch() whose agent is the child to continue it on its own.

Resuming the parent does not run the child again: the parent replays the recorded tool results. Set conversations: false on the child harness to keep no child transcript.

Each delegation emits a subagent event when it starts, finishes or fails. Every other event from the child, including usage, carries its run id in subagentId.

import type { DispatchOptions } from "@elie-laloum/outpost/core";

const observe: DispatchOptions["observe"] = (event) => {
  if (event.kind === "subagent")
    console.log(event.name, event.status, event.id, event.conversation);
  // Example output: review started subagent-1 undefined
};

API reference: AgentEvent.

To send an instruction to a running child, pass its id as subagent to steering.send(). See Steering a running agent.

  • The child must be a built-in harness agent; defineHarnessSubagent() rejects CLI agents.
  • Token budgets use reported usage: a response in flight can pass a ceiling before Outpost sees it. They are not prepaid spending caps.
  • When you resume a parent whose delegation was interrupted, that call comes back to the model as a tool error. Outpost does not restart the child.
  • A child cannot release the shared sandbox.

API: defineHarnessSubagent · HarnessSubagentOptions · HarnessLimits · AgentEvent.

A delegated agent is also a parent tool call. The parent’s toolExecution.deadlineMs bounds the entire delegation, including model requests; the default is five minutes. Increase that parent limit for longer child work, alongside the child’s step and token limits. On a delegation deadline, its failure event precedes the tool result; late child completion does not emit another terminal lifecycle event.