
Long-horizon agent workloads push single models past the point where a bigger window helps. A monolithic agent that holds every tool result, file read, and intermediate plan in one conversation eventually crowds out the very instructions it started with, and accuracy decays even in models whose windows stretch to hundreds of thousands of tokens. Sub-agent architectures attack the problem structurally rather than by squeezing harder: a lead agent decomposes work and delegates subtasks to agents that run in their own fresh context windows and return only distilled results. Anthropic's multi-agent research system, Claude Code's hybrid retrieval-plus-delegation strategy, and HuggingFace's sandboxed CodeAgent are three production examples of the same isolation principle applied through different mechanisms. This article is written for architects designing multi-agent systems in which a single agent keeps losing accuracy on complex tasks. It covers the orchestrator-worker pattern, the isolation-boundary decision, the token economics, and the well-known counterargument from teams that deliberately avoid parallel delegation.

A monolithic agent must keep the entire project state—prompts, tool outputs, intermediate plans, and final results—in a single conversation history. When the workload spans many steps, three related failure modes emerge.
Every tool call appends raw results to the same token window. As the window fills, earlier instructions and high‑level plans are pushed toward the truncation point. Anthropic’s early single‑agent prototype using Claude Opus 4 (200 K‑token context) demonstrated that a plan written on turn 1 disappears by turn 40, and after roughly twenty web‑search results the original query is effectively overwritten【https://theaiengineer.substack.com/p/how-anthropic-built-multi-agent-deep】. The model then “sees” a mixture of stale context and new data, diluting its reasoning ability—a phenomenon dubbed context pollution in the literature.
A single agent is expected to master an ever‑growing set of tools (search, code execution, file I/O, etc.). Each additional tool introduces new response formats and error modes, increasing the chance that successive calls contradict one another. When the agent mixes contradictory tool outputs inside the same window, its internal state becomes ambiguous, leading to unreliable long‑horizon reasoning.
Tool calls are processed one after another. In the same Anthropic experiment, a query that required 50 web searches incurred about 2 seconds per search, totaling ≈ 100 seconds before any synthesis began【https://theaiengineer.substack.com/p/how-anthropic-built-multi-agent-deep】. The latency compounds as the number of required tools grows, making the overall response time impractical for real‑time or even batch workloads.
These three symptoms—context pollution, tool overload, and sequential latency—are distinct from the “context rot” problem, which describes decay of relevance within a single window. Here the issue is structural: the monolithic design forces all information into one bounded context, so the degradation is inevitable once the token budget is exhausted.
The remedy is not to trim or compress the existing window (a cosmetic fix) but to isolate context across multiple agents. By delegating subtasks to worker agents, each with its own fresh window, the orchestrator retains only high‑level directives and distilled results, preserving both recall of the original plan and parallel execution speed. This structural approach sidesteps the hard limits observed in the April 2025 Claude 4 models; however, the cited latency (~2 s per search) and the 200 K‑token cap are version‑sensitive and should be re‑validated against newer models before drawing quantitative conclusions.

In an orchestrator‑worker architecture the lead agent (orchestrator) receives the user request, builds a high‑level plan, and then hands off each independent work item to a sub‑agent (worker).
Each worker runs in a fresh context window that contains only:
Because a worker cannot see any tokens outside its own window, the orchestrator must embed all of the above in the delegation prompt — otherwise the worker would lack the context needed to act responsibly.
Anthropic’s engineering write‑up reports that a sub‑agent can explore for tens of thousands of tokens (e.g., full‑text searches, code‑base scans) but returns a condensed summary of only 1 000–2 000 tokens to the orchestrator 【you.com】. This “separation‑of‑contracts” decision keeps the orchestrator’s context small enough to focus on synthesis, while the heavyweight reasoning stays isolated in the workers.
OpenAI’s Swarm library was explicitly created to enforce this separation of concerns: each swarm member owns its own system prompt, tool definitions, and context window, and the dispatcher (the orchestrator) only passes a self‑contained task specification to the worker 【agents‑lib.com】. The library’s design documents call this “delegation with isolated windows,” underscoring that the pattern predates LLMs and is now being codified in agent frameworks.
When delegating, always package the sub‑task as a self‑contained contract containing the four elements above. Because workers cannot read outside their window, any missing detail forces a costly round‑trip to the orchestrator. Clear contracts also reduce duplicated work when workers run in parallel, a problem observed in early Anthropic prototypes where two sub‑agents independently researched the same topic 【theaiengineer.substack.com】.
By structuring multi‑agent systems around the orchestrator‑worker pattern, architects can keep the lead agent’s context lean, achieve true parallelism, and scale to workloads that would otherwise exhaust even the largest context windows.

Anthropic’s Research feature (released April 2025) demonstrates a concrete orchestrator‑worker pipeline that avoids the context‑window bottleneck of a monolithic agent. The system consists of three dedicated components:
LeadResearcher (Claude Opus 4) – The entry point receives the user query, activates extended thinking mode to draft a high‑level strategy, and decides whether the task calls for breadth (many shallow investigations) or depth (few detailed dives). The plan is written to external memory before the lead’s context fills, after which it spawns 3 – 5 sub‑agents in parallel. Once the sub‑agents finish, the LeadResearcher synthesizes their condensed outputs into a single report.
Sub‑agents (Claude Sonnet 4) – Each sub‑agent runs in its own fresh context window, insulated from the others. A sub‑agent receives a self‑contained task description, invokes three or more tools (e.g., web search, code execution, document retrieval) in an interleaved “think‑act‑think” loop, evaluates the results, and returns a brief summary. Because the context never mixes unrelated tool results, token overflow and plan drift are prevented.
CitationAgent – After synthesis, a separate agent walks the final draft, verifies each claim against the source documents, and attaches a URL citation. This decouples verification from generation, eliminating the need for the LeadResearcher to retain all source material in memory.
Early prototypes ran all tool calls sequentially, incurring two hard limits: cumulative latency (e.g., 50 searches × ≈ 2 s ≈ 100 s) and context truncation once the 200 k‑token limit of Claude Opus 4 was reached. By delegating to independent sub‑agents, the wall‑clock time for a wave of work drops from the sum of sub‑task durations to the maximum of them, while each window stays well within its token budget.
The trade‑off is higher token usage (≈ 15 × a typical chat), which translates to higher cost. Anthropic therefore recommends the multi‑agent approach for high‑value domains—legal due‑diligence, competitive intelligence, biomedical literature—where the accuracy gains outweigh the additional compute expense.

The isolation boundary is the single most consequential design decision in any multi‑agent system. It defines what information a sub‑agent receives about its peers and, consequently, how the overall orchestration behaves.
Anthropic’s research‑oriented system deliberately gives each sub‑agent only a self‑contained task description, an output format, and a fresh context window. The sub‑agent does not know that other sub‑agents exist and cannot exchange messages during execution【1†https://theaiengineer.substack.com/p/how-anthropic-built-multi-agent-deep】. This strict isolation delivers three practical benefits:
The downside of zero peer awareness is occasional duplicated effort. In an early Anthropic prototype, one sub‑agent investigated the 2021 automotive chip crisis while two others simultaneously gathered current supply‑chain data, leading to unnecessary token consumption【2†https://theaiengineer.substack.com/p/how-anthropic-built-multi-agent-deep】. Since sub‑agents cannot query each other, the orchestrator must prevent overlap through delegation prompts, not through shared context.
Treat the delegation prompt as the sole coordination channel:
When these elements are well‑specified, the isolation boundary remains tight while the orchestrator preserves overall completeness.
By anchoring the isolation boundary in the delegation prompt, architects retain the scalability of parallel sub‑agents while mitigating duplicated effort and preserving token economy.

Claude Code tackles long‑horizon coding tasks by combining static preloading with dynamic, just‑in‑time retrieval.
CLAUDE.md files are inserted into the prompt at session start. They contain coding standards, architectural diagrams, and workflow rules that never need discovery during a run. This guarantees that every turn begins with a consistent, authoritative view of the project (Anthropic engineering blog).glob and grep let the agent explore the repository on demand, pulling only the files that are relevant to the current sub‑task. By avoiding a pre‑computed index or an in‑context syntax tree, the approach sidesteps stale metadata and the high token cost of loading large code trees (Anthropic engineering blog).Claude Code persists knowledge across sessions in two orthogonal stores:
CLAUDE.md hierarchy) – static, version‑controlled artifacts that remain part of every session’s context.A Claude Code session can spin up sub‑agents, each with its own fresh context window. Sub‑agents perform heavy‑weight operations such as bulk file searches, test execution, or dependency analysis, then return concise summaries to the orchestrator. This keeps search results, logs, and test output out of the main planning context, dramatically reducing token pressure (Program Strategy HQ).
Claude Code includes an auto‑compact guardrail that activates when the working context reaches roughly 90‑95 % of the model’s token window. The guardrail preserves essential architectural decisions and unresolved bugs while pruning redundant tool outputs. The exact trigger thresholds and related configuration fields are version‑sensitive and can be tuned via the /compact command or system settings (Claude Code token‑optimization guide).
Together, preloading, just‑in‑time retrieval, dual memory, and isolated sub‑agents give Claude Code a scalable approach to long‑horizon coding problems without sacrificing accuracy or incurring prohibitive token costs.

HuggingFace’s deep researcher replaces the usual JSON‑based tool‑calling pattern with a CodeAgent. Instead of asking the model to produce a structured payload that a separate service interprets, the model emits a short program that explicitly calls the required tools. That program is sent to a sandboxed execution environment—most commonly E2B, a Firecracker‑based microVM service. The sandbox runs the code, captures the tool output, and returns only the selected values to the LLM LangChain blog.
The sandbox creates a clear boundary: everything produced inside the environment—temporary files, large binary objects, intermediate state—is invisible to the language model unless the developer explicitly includes it in the return‑value contract. In practice this looks like:
# generated by the LLM
result = image_search(query)
print(json.dumps({"image_id": result.id}))
Only the JSON object printed to stdout is fed back to the LLM; the image file itself never enters the model’s context window. This mirrors the 1 000–2 000‑token summary contract used in sub‑agent orchestration, but the contract is now expressed in concrete program output rather than an abstract summary.
Token‑heavy artifacts—images, audio clips, large CSVs—can be stored as variables or files in the sandbox’s persistent state. Because the LLM never receives the raw bytes, the token budget is preserved for reasoning rather than for data transport. HuggingFace explicitly notes that “you can store this image / audio / other for later use… just assign it as a variable in your state” LangChain blog. Consequently, a single interaction can involve multiple heavy assets without inflating the model’s context window.
Running model‑generated code in a sandbox also provides a security perimeter: the code cannot escape the microVM, cannot access the host filesystem, and can only use whitelisted network endpoints. While this is primarily a safety concern, it reinforces production viability because the same sandbox can be instantiated on demand, executed, and torn down after each task. E2B’s sub‑150 ms cold‑start time enables fan‑out parallelism, allowing an orchestrator to spawn many independent CodeAgent instances for a large workload without sharing a single context window.
By moving the context store out of the model entirely and treating the sandbox’s output as the sole communication channel, HuggingFace’s CodeAgent demonstrates a practical, production‑ready pattern for handling long‑horizon, token‑intensive workflows.

Cognition’s “Don’t Build Multi‑Agents” paper warns that parallel sub‑agents can betray the original intent of a request when they operate in completely isolated windows. Their canonical scenario asks a lead agent to produce a Flappy Bird clone, then delegates the background to one sub‑agent and the bird sprite to another. The first sub‑agent generates a Super Mario‑style backdrop, while the second builds a bird that follows a cartoonish aesthetic. Both outputs satisfy their narrow prompts, yet the overall product lacks a coherent visual language because neither sub‑agent sees the shared “Flappy Bird” framing source 1.
Cognition’s alternative is to keep a single, long‑context agent that compresses intermediate results internally. By using a dedicated summarization model at “agent‑to‑agent” boundaries, the approach preserves an evolving narrative while avoiding the cost of multiple fresh windows source 1.
The debate collapses into a question of task independence. Anthropic’s research system deliberately isolates sub‑agents because its workloads are genuinely orthogonal—e.g., running separate scientific simulations or retrieving unrelated documents—so the absence of shared context never harms fidelity source 2. In contrast, most long‑horizon engineering tasks—coding, dialogue generation, or design pipelines—carry implicit shared constraints (API contracts, naming conventions, visual style guides). For these, isolation introduces a coordination problem rather than a prompt‑engineering one.
From a distributed‑systems perspective, multiple agents acting on a common codebase behave like independent processes with mutable shared state. They can make contradictory assumptions, revert one another’s intentional changes, or act on stale context that no agent invalidates. These are classic consistency and concurrency failures, not flaws in the language model itself source 3.
Recommendation

Multi‑agent pipelines consume far more tokens than a single‑agent conversation. Anthropic’s internal research system, for example, spends about 15 × the tokens of a comparable chat because the lead orchestrator adds a decomposition and aggregation round on top of every worker’s calls【source1】. A heavy research session can therefore expend millions of tokens, and Anthropic measured that token spend alone explains roughly 80 % of the observed performance variance【source2】. The implication is that the primary advantage of the pattern is raw token budget, not any mysterious “many‑heads‑are‑better” effect.
| Failure mode | Token impact | Operational impact |
|---|---|---|
| Sub‑agent recursively spawns more sub‑agents | ×10 or more extra tokens per level | Exponential growth of orchestration overhead |
| Tool returns an oversized payload (e.g., full file dump) | ×10 token multiplier for that path | Swallows context window of downstream agents |
| Synchronous wave execution | One slow sub‑agent stalls the entire batch | Increases latency and idle token consumption |
| Asynchronous coordination (ordering, state consistency, partial failures) | Added bookkeeping tokens + retry loops | Still an open research problem; may require custom protocols |
These failure modes can easily push a single query from the baseline 15 × multiplier to 100 × or more, quickly rendering the design cost‑inefficient.
If the answer is “no,” default to the three single‑agent levers that avoid the token blow‑up:
These techniques keep token usage linear and are sufficient for the majority of production workloads, which fall outside the high‑value parallel quadrant. Sub‑agent isolation should therefore be reserved for genuinely parallel, high‑impact tasks such as large‑scale literature review, legal due‑diligence, or multi‑modal data synthesis.
All token multipliers and cost figures cited above are Anthropic‑reported and era‑specific; changes in model pricing or architecture may shift the break‑even point, but the underlying decision logic remains applicable.