Skip to content
Search
Agentic8 min read

When to Use Subagents: Delegation Prompts That Keep a Long-Context Agent Focused

Brian Gagne
When to Use Subagents: Delegation Prompts That Keep a Long-Context Agent Focused

Updated November 2026. The patterns apply to any agent with subagents.

A large context window feels like permission to dump everything into the main agent. Repo tree, full files, all the grep output, every test log. Why spawn a subagent when you have room?

What fills the window matters more than how big it is. A context window is working memory, and every tool result spends some of it.

Anthropic's write-up of its multi-agent research system found that "token usage by itself explains 80% of the variance" in performance on the BrowseComp evaluation, which is part of why spreading work across subagents with their own context helped (Anthropic, How we built our multi-agent research system). More room doesn't fix the other half of the problem. Anthropic's context window docs say "as token count grows, accuracy and recall degrade, a phenomenon known as context rot" (Anthropic, Context windows). A window half full of grep output carries all of that text into every later decision. Subagents keep the orchestrator's working memory clean, and that matters even when there's space left.

This guide covers when to use subagents and how to write the prompts that make the split work. When to delegate, when to stay, and how to write return-format contracts that don't just shove the noise back up one level.

The delegation decision rule

Here's the rule I use. Delegate when the task produces more tokens than the orchestrator needs to read. Stay when the task requires reasoning about the orchestrator's in-progress state. This is the supervisor-worker pattern applied to reading and searching.

That's it. Everything else is a refinement.

A file search produces 200 matches you'll scan once and discard. Delegate. A refactor that depends on three decisions you just made two turns ago stays in the orchestrator, because shipping that context to a subagent is more expensive than just doing the work.

Put this rule in the orchestrator's system prompt explicitly. Don't count on the model applying it unprompted.

The Prompt:

You are an orchestrator agent coordinating work across sub-agents.

DELEGATION RULES:
- Delegate read-only search and discovery tasks (grep, file listing, "where
  is X defined") to the Explore sub-agent. Do NOT read the output directly
  into your context. Ask for a summary.
- Delegate verification tasks (does this test pass, does this file compile,
  does this API return what we expect) to a worker sub-agent. Ask for a
  pass/fail and one-line reason, not the full output.
- Stay in-context for: decisions that depend on your in-flight reasoning,
  single-file edits, one-line fact lookups, any task where delegation
  overhead exceeds the token savings.

When you delegate, you MUST specify:
1. The exact question to answer
2. A return-format contract (what shape, what length)
3. What NOT to return (raw tool output, reasoning traces, full file dumps)

Anthropic's prompting guide includes a similar rule for models that over-delegate: "Use subagents when tasks can run in parallel, require isolated context, or involve independent workstreams that don't need to share state. For simple tasks, sequential operations, single-file edits, or tasks where you need to maintain context across steps, work directly rather than delegating" (Anthropic, Prompting best practices).

Why This Works: Most orchestrators over-fan-out or under-delegate because the default behavior wasn't written down. Making the rule explicit, with concrete examples of "stay" cases, prevents the model from spawning 50 subagents for trivial queries (a real failure mode: Anthropic reports early versions of its research agent "spawning 50 subagents for simple queries" until it added scaling rules to its prompts (Anthropic)).

Expected Output:

The orchestrator now triages each incoming task against the rule before acting. For "find all callers of parseInvoice," it spawns an Explore subagent with a word-limited brief. For "given the three decisions we just made, draft the migration," it stays in-context and writes the migration itself.

The return-format contract

A subagent without a return contract will hand you back the problem you delegated, plus extra framing.

Every delegation prompt needs four things. What to answer. What shape to answer in. A length cap. A "what NOT to include" list.

The Prompt:

Task: Find every file that imports `legacyAuth` and classify each as
(a) safe to migrate now, (b) blocked by a TODO or test gap, or
(c) already migrated but import not yet removed.

Return format:
- A markdown table with columns: file path, classification, one-sentence reason
- Under 400 words total
- Sort by classification, then alphabetically by path

Do NOT return:
- The grep output itself
- File contents
- Your reasoning about individual files beyond the one-sentence reason
- Any preamble like "I'll start by..." or "Here are the results"

If you find fewer than 5 files, return the table anyway and note the count.
If you find more than 50, stop and return a summary with the first 20.

Why This Works: The "Do NOT return" list is the load-bearing part. Without it, the subagent defaults to showing its work, which is exactly the noise you paid the delegation overhead to avoid. The overflow clause (fewer than 5, more than 50) prevents the subagent from making the wrong judgment call under edge conditions.

Expected Output:

A clean 18-row table. The orchestrator reads it in one pass, makes a migration plan, and never sees the 200 grep hits, the file contents, or the subagent's internal deliberation about whether auth_test.ts counts as a test gap.

For the case where one agent hands work to the next, see stop writing supervisors, write handoffs and the agent handoff entry.

The artifact return pattern

For anything larger than a short report, skip the return payload entirely. Have the subagent write to disk and return only the path plus a headline.

Anthropic's research system does this. Its write-up recommends "artifact systems where specialized agents can create outputs that persist independently" and pass lightweight references back to the coordinator (Anthropic). The orchestrator reads the artifact only when it needs to, and only the sections it needs.

The Prompt:

Task: Audit the entire /api directory for endpoints that don't validate
request bodies against a schema.

Write your findings to /tmp/audit-{run_id}/unvalidated-endpoints.md in this
structure:

# Unvalidated Endpoints Audit
## Summary
[3 bullets: total endpoints scanned, unvalidated count, highest-risk file]
## Findings
[One H3 per file, with line numbers and the missing validation]
## Suggested Fix Order
[Ordered list, ranked by exposure]

Return to me ONLY:
- The artifact path
- The three summary bullets
- Nothing else. No preamble, no sign-off.

Why This Works: The orchestrator now carries about 80 tokens of context from this subagent instead of 4,000. It decides based on the summary whether to read the artifact, and if so, can Read only the Findings section for the file it cares about. The compression loss of a traditional summary return is avoided because nothing was summarized. The full fidelity lives on disk.

Expected Output:

The orchestrator receives: "Audit complete. /tmp/audit-a7f2/unvalidated-endpoints.md. 142 endpoints scanned, 9 unvalidated, highest risk in routes/billing.ts." It can now plan the next step without the full report bloating its window.

When to stay

Three cases where you should not delegate, even though the task looks like a candidate.

Coding with tight dependencies. Research tasks are embarrassingly parallel. You can spawn ten subagents to look up ten companies and merge the results. Coding rarely works this way. Most refactors require agents to share an evolving file state, and subagents start clean without the context of what just changed. Anthropic's post says "most coding tasks involve fewer truly parallelizable tasks than research", which is why its multi-agent result (90.2% better than a single agent on its internal research eval) is not a promise for coding work (Anthropic).

One-line fact lookups. Delegation has fixed overhead: the prompt you write, the subagent's context warm-up, the return parse. For a task that takes three seconds in-context, that overhead is larger than the savings.

Reasoning about in-flight decisions. If the task is "given what we just decided about the schema, write the migration," a subagent can't help. It doesn't have what we just decided, and packaging that state into a prompt is equivalent to just doing the task.

The hierarchy question

One more pattern worth knowing. As a rule of thumb, if your orchestrator is about to spawn more than four peer subagents, consider a second layer instead. Spawn two feature leads and let them each spawn their specialists.

Single-layer fan-out fragments the orchestrator's context with every return. Hierarchical delegation keeps the top-level conversation narrow (two children, not six) and pushes the coordination work down to the leads.

Tools differ on how deep nesting can go. In Claude Code, for example, "a subagent can spawn subagents of its own, up to three layers below the main conversation", and the limit is configurable (Claude Code docs, Subagents). Being able to nest doesn't mean you should: most work still fits in two layers. If your subagents run in parallel on code, see prompting parallel coding agents.

The shortest version

A large context window is not a license to stop delegating. It's an argument for delegating better, because accuracy and recall still degrade as the context fills, however much space is left (Anthropic, Context windows). Write delegation rules into the orchestrator's system prompt. Give every subagent a return-format contract with a "do not return" list. Use artifacts for anything longer than a paragraph. Stay in-context when the task depends on state you're holding right now.

For managing what one agent sees over a long run, read context engineering for agents.

More in Agentic.


If your team is standing up multi-agent workflows and the orchestrator keeps losing the thread, the delegation prompts are a good place to start looking. Want hands-on training on delegation prompts and agentic workflows for your team? Connect with Kief Studio on Discord or schedule a session.

Frequently asked questions

When should I use a subagent?

When a task produces lots of output the main agent will read once and discard (searches, logs, file dumps), when tasks can run in parallel, or when a task needs its own isolated context. Claude Code's docs describe the use case as a side task that "would flood your main conversation with search results, logs, or file contents you won't reference again" (Claude Code docs).

When should I not use a subagent?

For single-file edits, sequential steps, quick lookups, and anything that depends on decisions the main agent is holding right now. Anthropic's guide says to "work directly rather than delegating" in those cases (Anthropic, Prompting best practices).

Does a bigger context window remove the need for subagents?

No. Anthropic's docs say "more context isn't automatically better" because accuracy and recall degrade as token count grows (Anthropic, Context windows). Subagents keep the main agent's context small and relevant.

What should a subagent return?

The answer in a fixed shape and length, with a list of what not to return. For long results, have it write a file and return the path and a short summary. Anthropic's research system uses this artifact approach to avoid what it calls a "game of telephone" between agents (Anthropic).

Can subagents spawn their own subagents?

It depends on the tool. Claude Code allows nesting up to three layers below the main conversation by default (Claude Code docs). Keep nesting shallow unless you've measured a benefit.

Rather have someone set it up for you?

That's a fair call. LTFI, the agentic business operating system from Kief Studio, can set up the work these guides describe and run it with you. No website yet? Kief Studio will build you one for free.