Recursive Delegation

Let agents spawn child agents with scoped sub-contexts. Instead of stuffing everything into one window, the parent splits work, delegates with focused context, and aggregates results.

The Problem This Solves

Some tasks require processing more information than any single context window can hold effectively. Analyzing an entire codebase, researching across hundreds of documents, synthesizing data from multiple large sources. Even with Isolate, someone has to decide how to split the work and what each sub-agent gets. If the orchestrator makes that decision upfront, it needs to understand the full scope, which may itself exceed its effective context.

How It Works

Give the top-level agent the ability to spawn child agents, each with their own context windows. Critically, let the child agents do the same: spawn their own children with further-scoped contexts. The decomposition happens recursively based on what each agent discovers, not based on a static upfront plan.

The recursion:

  1. Parent agent receives a high-level task and an overview of available information.
  2. Parent decomposes the task into subtasks, deciding what scope of information each subtask needs.
  3. Parent spawns child agents, each with a focused brief and relevant context subset.
  4. Each child either completes its task or further decomposes and delegates.
  5. Results flow back up the tree. Each parent summarizes and integrates its children’s outputs.

The context at every node in the tree stays focused and manageable. The total information processed across the entire tree can be orders of magnitude larger than any single window.

Example

Task: “Audit this 500-file codebase for security vulnerabilities.”

A single agent would need to read all 500 files. Even with progressive disclosure, it would lose track of patterns across files as its context fills up.

With recursive delegation:

No single agent in the tree ever holds more than 20-30 files in context. The full 500-file codebase is covered.

Pseudocode for the pattern:

def audit_security(file_tree, context, max_files=25, depth=0, max_depth=3):
    """
    Recursively audit security across a file tree.
    Each agent spawns children if scope exceeds max_files.
    """
    
    # Base case: small enough to handle directly
    if len(file_tree.files) <= max_files or depth >= max_depth:
        return audit_files_directly(file_tree.files, context)
    
    # Recursive case: decompose and delegate
    subsystems = identify_subsystems(file_tree)
    child_results = []
    
    for subsystem in subsystems:
        child_context = build_context_for(subsystem, context)
        child_result = spawn_agent(
            task=audit_security,
            file_tree=subsystem.files,
            context=child_context,
            max_files=max_files,
            depth=depth + 1,
            max_depth=max_depth
        )
        child_results.append(child_result)
    
    # Aggregate results from children
    return synthesize_findings(child_results, subsystems)

Each call operates on a manageable context. The tree depth adapts to the codebase structure. Total coverage scales without individual context bloat.

Requirements

This pattern requires infrastructure that most simple agent setups don’t have:

When to Use

When Not to Use