coordinationmediumcommon

Sub-Agent Delegation Pattern

Complex tasks requiring context isolation and recursive decomposition

Overview

The Challenge

Main agents become overloaded with context as tasks grow complex. Long conversations accumulate irrelevant information, degrading performance and increasing costs.

The Solution

Spawn specialized sub-agents for isolated subtasks. Each sub-agent receives only relevant context, executes independently, and returns results to the parent. Sub-agents can recursively spawn their own sub-agents.

When to Use
  • Long-running, complex tasks
  • When context windows are constrained
  • Tasks with clear subtask boundaries
  • Research and investigation workflows
When NOT to Use
  • Simple, quick tasks (overhead not justified)
  • When full context is always needed
  • Highly interdependent subtasks

Trade-offs

Advantages
  • +Prevents context bloat
  • +Enables parallel execution
  • +Clear separation of concerns
  • +Improved focus per subtask
Considerations
  • Coordination overhead
  • Information loss between agents
  • Harder to debug across agents
  • Cost of spawning multiple agents
New to agent evaluation?
Start Learning

Deep Dive

Overview

Sub-agent delegation enables hierarchical task decomposition while maintaining context isolation. This pattern is fundamental to modern agentic systems.

Key Principles

Context Isolation

  • Each sub-agent gets only relevant context
  • Parent doesn't see sub-agent's internal reasoning
  • Only final results propagate up

Recursive Decomposition

  • Sub-agents can spawn their own sub-agents
  • Creates natural hierarchies for complex tasks
  • Each level handles appropriate abstraction

Result Aggregation

  • Parent synthesizes results from multiple sub-agents
  • Can run sub-agents in parallel when independent
  • Handles partial failures gracefully

Patterns

Worker Pool

Pre-defined set of specialized workers, tasks routed by type.

Dynamic Spawning

Create sub-agents on-demand based on task analysis.

Hierarchical Task Network

Use formal task decomposition (HDDL) to plan sub-agent structure.

References

Example Scenarios

Research Report Generation

A main agent receives a request to write a market analysis. It spawns sub-agents for: data collection, competitor analysis, trend identification, and writing. Each works independently and returns findings.

OutcomeReport quality improved while main agent context stayed under 8K tokens

Code Examples

Sub-agent delegationpython
async def delegate_to_subagent(task, relevant_context):
    """Spawn a sub-agent for isolated task execution."""
    subagent = await spawn_agent(
        role=task.required_role,
        context=relevant_context,  # Only what's needed
        max_turns=task.complexity_estimate
    )

    result = await subagent.execute(task.instruction)

    # Return only the essential result, not full conversation
    return result.summary
Ready to implement?
Get RepKit
Considerations

Balance between isolation (information loss) and sharing (context bloat). Design clear interfaces for sub-agent results.

Dimension Scores
Safety
3/5
Accuracy
4/5
Cost
3/5
Speed
3/5
Implementation
Complexitymedium
Implementation Checklist
Agent spawning capability
Context serialization
Result aggregation
0/3 complete
Tags
delegationhierarchycontextdecompositionsub-agents

Was this pattern helpful?