DEV Community

Hex
Hex

Posted on • Originally published at openclawplaybook.ai

Sub-Agents: How to Make Your AI Delegate Work Like a Manager

There's a ceiling to what a single AI agent can do at once. While you're asking it to write a blog post, it can't also be reviewing your pull requests, monitoring your inbox, and summarizing yesterday's analytics. At some point, you need your agent to do what any good manager does: delegate.

OpenClaw's sub-agent system is exactly that. A single main agent can spawn any number of background workers — each isolated, each focused on one task, each reporting back when done. While the main agent keeps your conversation fluid, its sub-agents are grinding in the background.

This is what turns an AI agent from a capable assistant into an actual operations layer.

What Is a Sub-Agent?

A sub-agent is a background agent run spawned from an existing agent session. When your main agent calls sessions_spawn, OpenClaw starts a new isolated session under a key like agent:main:subagent:<uuid>. That session runs its task, and when it's done, it automatically announces the result back to the requester's chat channel.

A few things make sub-agents different from just running more code:

  • Isolation — each sub-agent has its own session, its own context window, its own token budget. What happens in a sub-agent stays in that sub-agent.
  • Non-blockingsessions_spawn returns immediately. Your main agent doesn't wait. It just keeps doing its thing.
  • Auto-announce — when finished, the sub-agent posts its result back to the chat where the main agent lives. You see the output without polling.
  • Parallelism — you can run up to 8 sub-agents concurrently by default. That's 8 simultaneous workers on independent tasks.

Spawning Your First Sub-Agent

The primary tool is sessions_spawn. Your main agent calls it with a task description and optional parameters:

// Minimal spawn — main agent delegates a research task
sessions_spawn({
  task: "Research the top 5 Python libraries for async task queues. Summarize each with pros, cons, and best use case. Keep it under 500 words.",
  label: "async-queue-research"
})
Enter fullscreen mode Exit fullscreen mode

That's it. The sub-agent wakes up, does the work, and posts a summary back to your Slack DM (or wherever you're chatting). The main agent is free for the next request while this runs.

You can also control the model and timeout:

sessions_spawn({
  task: "Review this codebase for security vulnerabilities. Focus on auth flows and SQL queries.",
  model: "anthropic/claude-sonnet-4-6",
  runTimeoutSeconds: 900,
  label: "security-review"
})
Enter fullscreen mode Exit fullscreen mode

Cost tip: each sub-agent runs its own context and accumulates its own token usage. If you're running expensive tasks, set sub-agents to a cheaper model while keeping your main agent on a high-quality one.

Managing Running Sub-Agents

Once sub-agents are running, you control them with the /subagents command family:

# See all active sub-agents
/subagents list

# Send a follow-up message into the sub-agent's session
/subagents send 1 "Also check the rate limiting logic"

# Nudge a running agent mid-task without cancelling
/subagents steer 1 Prioritize the authentication module first

# Stop a specific sub-agent
/subagents kill 1
Enter fullscreen mode Exit fullscreen mode

The Orchestrator Pattern: Agents Spawning Agents

By default, sub-agents can't spawn their own sub-agents — the nesting depth is capped at 1. But if you enable maxSpawnDepth: 2, you unlock the orchestrator pattern: your main agent spawns an orchestrator, which then fans out to multiple worker sub-agents in parallel.

{
  "agents": {
    "defaults": {
      "subagents": {
        "maxSpawnDepth": 2,
        "maxChildrenPerAgent": 5,
        "maxConcurrent": 8
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Here's what the depth levels look like:

  • Depth 0 (main) — your main agent, always can spawn
  • Depth 1 (orchestrator) — spawned by main, can spawn depth-2 workers
  • Depth 2 (workers) — leaf workers, never spawn further

The announce chain flows upward: depth-2 workers report to the depth-1 orchestrator, which synthesizes the results and reports back to main, which delivers the final summary to you. You see one clean output, not a flood of individual reports.

Tool Access in Sub-Agents

By default, sub-agents get all tools except session tools. When you enable maxSpawnDepth: 2, depth-1 orchestrators automatically get sessions_spawn and management tools so they can manage their children.

You can restrict the tool set for all sub-agents via config:

{
  "tools": {
    "subagents": {
      "tools": {
        "deny": ["browser", "nodes"]
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Practical Delegation Patterns

Parallel Research — Instead of asking one agent to research three topics sequentially, spawn three workers simultaneously. Total time: the longest single research task, not the sum of all three.

Long Background Tasks — Any task that takes more than a few minutes should be a sub-agent. Cron jobs often work this way — the cron fires, the main agent spawns a sub-agent for the heavy work.

Specialist Workers — Give each worker a focused mandate. "You are a security reviewer. Look only at auth flows." Narrow mandates produce better outputs than one agent trying to do everything.

Fan-Out + Synthesize — The orchestrator pattern at its purest: spawn N workers with parallel workloads, collect all results, synthesize into one coherent output.

Getting Started

If you've got OpenClaw running and a main agent working, sub-agents are available immediately — no extra config needed for the basics. Just have your agent call sessions_spawn with a task, and the infrastructure handles the rest.

The mental model shift is simple: your main agent is the manager. Sub-agents are the team. Managers don't do every task themselves — they delegate, synthesize, and report up. Build your agent operations the same way.


Originally published at openclawplaybook.ai. Get The OpenClaw Playbook — $9.99

Top comments (0)