跪拜 Guibai
← All articles
AI Programming · AIGC

When to Delegate to Subagents: Token Savings, Parallel Red Lines, and a Three-Layer Setup

By oil欧哟 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Long AI coding sessions hit a hard wall when context fills up and compression degrades output quality. A three-layer subagent setup keeps the main context lean and cuts token costs, but only when cheap models are explicitly assigned, because delegating itself adds overhead.

Summary

Dozens of file reads, long logs, and multi-option evaluations balloon a main agent's context fast. The fix is subagents: isolated worker agents that take a task, run it in their own context, and return only a short summary. That keeps the main thread clean and lets several tasks run in parallel. But not every task suits delegation. Tasks that touch the same files, require strict sequential steps, or carry high-risk actions like deployments should stay in the main context.

The guide lays out a three-layer configuration: global settings that cap concurrent subagents and nesting depth, per-role configs that pin a cheap model and a role-specific prompt, and a dispatch Skill that tells the main agent when to spawn which role. The key savings come from pairing heavyweight work with cheap lightweight models. An Explorer role scans code with the cheapest tier, an Executor handles bounded edits, and a Reviewer does independent code review. Because subagents start fresh without the main conversation's history, they review changes without the author's bias.

Delegation isn't automatically cheaper. Each new subagent re-reads project context and reports back, so total token count usually rises. It pays off only when the subagent's model is drastically cheaper. Simple tasks with one or two edits should stay in the main agent. The guide also shows how to delegate to an entirely different agent via CLI, wrapping commands in a Skill with scripts, and open-sources that mechanism as oil-delegate.

Takeaways
— Subagents run in isolated contexts, so they don't inherit the main thread's history; use them for tasks that generate lots of intermediate data but return only a small summary.
— Avoid parallel subagents when they would edit the same files, when steps must run sequentially, or when actions involve permissions, deployments, or deletions.
— In Claude Code and Codex, you can create a custom subagent by telling the main agent its name, duty, and model; it writes the config file automatically.
— Global settings cap concurrent subagents (often 6) and nesting depth; one level of nesting is enough, and default values usually suffice.
— Keep execution details in each subagent's own config, not in the dispatch Skill, so the main agent doesn't re-output those words every time it dispatches.
— Cheap lightweight models work well as executor subagents despite weak recall, because the main agent pre-specifies all context and boundaries.
— A Reviewer subagent reviews code with a fresh context, avoiding the main agent's historical bias and producing more accurate checks.
— Delegation adds token overhead—re-reading context, outputting prompts and reports—so it pays off only when the subagent's model is much cheaper.
— For trivial one-line edits, don't spawn a subagent; let the main agent do it directly to avoid dispatch overhead.
— You can delegate to a different agent via CLI, wrapping its command in a Skill and scripts; oil-delegate does this for Claude Code, Codex, Antigravity, and Kimi Code.
Conclusions

The strongest cost lever isn't parallelism; it's the price gap between a cheap subagent model and the main agent's model, because every spawned subagent re-reads project context.

The recommendation that subagents should not recursively spawn more subagents conflicts with the promise of autonomous scaling; the guide deliberately caps nesting to one level for stability.

Using a low-tier model as a subagent while keeping a stronger main agent sidesteps the weak recall problem, suggesting orchestration matters more than raw model strength.

A fresh-context reviewer is a practical workaround for a known LLM bias: an agent that wrote code tends to follow its own reasoning inertia, so a separate, history-free reviewer catches more real issues.

Concepts & terms
Subagent
An agent instance spawned by a main agent that runs in its own isolated context, receives a specific task, and returns only the result or summary, keeping the main thread's context uncluttered.
Skill
A reusable package of instructions and optional scripts that an agent loads on demand to perform a specific workflow, as opposed to a global file like AGENTS.md that is always read.
Three-layer configuration
A setup for managing subagents across tools: global settings cap concurrency and nesting; per-role configs define model, prompt, and duties; a dispatch Skill tells the main agent when to spawn which role.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗