Skip to main content
Agents can delegate work to other agents. When you pass a subagents source, OpenHarness auto-registers a task tool that lets the parent spawn child agents by name.

Basic Setup

The parent model sees a task tool listing the available subagents. It can call task with an agent name and a prompt, and the child runs to completion autonomously.

Key Behaviors

  • Stateless by default — each task call creates a fresh subagent instance with no shared conversation state
  • No approval — subagents run autonomously without prompting for permission
  • Configurable nesting — by default subagents cannot themselves have subagents (maxSubagentDepth: 1). Set a higher depth to enable nested delegation.
  • Abort propagation — the parent’s abort signal is forwarded to the child
  • Concurrent execution — the model can call task multiple times in one response to run subagents in parallel
Existing behavior stays the same unless you explicitly opt into subagentSessions.

Dynamic Catalogs

subagents can be either a static Agent[] or a dynamic catalog:
The catalog is listed at run time, so the task tool schema and description stay in sync with whatever agents are currently available.

Nested Subagents

By default, subagents cannot delegate further. Set maxSubagentDepth to allow nesting:
The depth decrements at each level: the root agent has depth 2, its child explore gets depth 1, and search gets depth 0.

Resumable Subagent Sessions

To let subagents keep their own message history across multiple task calls, enable subagentSessions. This layers Session persistence on top of the built-in task tool while keeping Agent itself stateless.
With subagentSessions enabled, task accepts an optional session object:

Session Modes

Configuration

When a task runs in new, resume, or fork, the tool result includes session_id="...":
Subagent sessions are single-writer. If the same sessionId is already running, the next resume or fork attempt fails instead of interleaving histories.

Live Subagent Events

To observe what subagents are doing in real time, pass an onSubagentEvent callback:
The path parameter is a string[] representing the full ancestry from outermost to innermost agent. Events from nested subagents automatically bubble up through the chain.

Background Subagents

By default, all subagent calls are synchronous. Enable subagentBackground to let the parent spawn subagents in the background, do other work, and collect results later.
When enabled:
  1. task gains an optional background parameter. When true, the subagent is spawned in the background and the tool returns immediately with a run ID.
  2. agent_await is registered for waiting on background runs using different strategies.
  3. agent_status and agent_cancel are registered for checking and cancelling runs.
Example:
If resumable sessions are enabled, background spawns keep the same split:
  • run ID — returned as agent_id="bg-1" and used with agent_status, agent_await, and agent_cancel
  • session ID — returned as session_id="sub-123" and used with later task(..., session: { mode: "resume", id: "sub-123" })

Await Modes

Configuration

Pass true for sensible defaults, or an object for fine-grained control:

Cleanup

Background subagents respect the parent’s abort signal. When autoCancel is true, calling agent.close() cancels any still-running background runs.