Flows category icon
Agent Architecture
Advanced

Sub-Agent Delegation with Context Isolation

Delegate bounded work to sub-agents that run in fresh context and return only distilled results - the pattern behind scalable long tasks.

4 steps12 verify checks90-150 minutesWorks with: emergent · chatgpt · claude · cursor
Start Guided Walkthrough

The Route

0/4 verified

Context Pack

Paste this first. It briefs the AI on requirements, constraints, and the Definition of Done before your first build prompt.

Context Pack
PROJECT CONTEXT:
My agent's context fills with exploration noise (search results, file dumps) that crowds out the actual task. Analyses of Claude Code show its answer: spawn sub-agents that explore in their own context and report back only conclusions.

GOAL:
Implement a dispatch tool: the main agent delegates a bounded task to a sub-agent with a fresh context, and receives only the final distilled report.

REQUIREMENTS:
- A dispatch_agent tool: task description in, final report out
- Sub-agent runs its own loop with its own message history
- Sub-agent gets a restricted tool set (read-only by default)
- Only the sub-agent's final report enters the parent's context
- Depth limit (no sub-sub-agents in v1) and turn budget per sub-agent

CONSTRAINTS:
- Sub-agent transcripts are logged but never injected into the parent
- The parent must phrase tasks with explicit deliverables, not vague asks

DEFINITION OF DONE:
- A codebase question is answered via sub-agent with under 500 tokens entering parent context
- Sub-agent cannot call write tools when dispatched read-only
- Sub-agent hitting its turn budget returns a partial report, not an error
- Parent transcript shows only task + report, never raw exploration

COMMON FAILURES TO AVOID:
- Returning the sub-agent's whole transcript, defeating the purpose of isolation
- Vague task prompts producing vague reports the parent cannot use
- Unlimited recursion: sub-agents spawning sub-agents until the budget burns
- Giving sub-agents full write access for what should be a research errand

Paste this into your AI builder first. It teaches the AI what you want before you give it the build prompt.

Related routes

More Agent Architecture flows that share ground with this one.

Flows category icon
Agent Architecture

Design a Single-Loop Agent

Build the core agent loop the leading coding agents use: one model, one loop, tools in, results folded back into context.

01Define the loop contract
02Build the tool registry
03Implement the loop with result folding

+2 more steps to Done

Best forproduction-grade builds with strict verification

5 steps90-150 minutesAdvanced
Flows category icon
Agent Architecture

Assemble a System Prompt Like the Pros

Structure your agent's system prompt the way leading harnesses do: layered sections, dynamic context, and enforceable rules.

01Decompose the current prompt
02Build the section-based assembler
03Pair rules with enforcement

+1 more steps to Done

Best forbuilders who have shipped a basic app before

4 steps60-90 minutesIntermediate
Flows category icon
Agent Architecture

Choose the Right Dispatch: Spawn, Fork, or Direct

Three ways to hand work to a sub-agent - fresh-context spawn, cache-sharing fork, or just doing it yourself - and the decision matrix for picking per task.

01Implement spawn: fresh context specialists
02Implement fork: inherited context, shared cache
03Add guards and async lifecycle

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-150 minutesAdvanced

Made with Emergent