AgentSkillsCN

subagent-teams

通过委派工作给并行子代理团队来统筹复杂任务,同时保持主上下文窗口的完整性,避免自动压缩。 当用户提出“应用子代理团队”、执行复杂的多步骤任务、上下文窗口逐渐变大,或独立子任务可以并行运行时,可选用此技能。

SKILL.md
--- frontmatter
name: subagent-teams
description: |
  Orchestrate complex tasks by delegating work to parallel subagent teams, preserving the main context window and preventing auto-compact.
  This skill should be used when users ask to apply subagent-teams, when performing complex multi-step tasks, when context window is getting large, or when independent subtasks can run in parallel.

Subagent Teams

Maintain optimum Claude performance by delegating heavy work to subagent teams, minimizing auto-compact of the main context window.

What This Skill Does

  • Decomposes complex tasks into independent subtasks for parallel execution
  • Delegates exploration, research, testing, and implementation to specialized subagents
  • Keeps main orchestrator context lean (decision-making and synthesis only)
  • Prevents auto-compact by isolating heavy work in separate context windows
  • Selects optimal model per subtask (Opus for complex, Sonnet for moderate, Haiku for simple)

What This Skill Does NOT Do

  • Handle tasks with strict sequential dependencies (use normal flow)
  • Replace the main orchestrator's decision-making role
  • Work for single-step trivial tasks (no delegation needed)
  • Manage persistent state across subagent sessions

Before Implementation

Gather context to ensure successful delegation:

SourceGather
User RequestFull scope of the task, constraints, preferences
CodebaseProject structure, key files, existing patterns
Skill ReferencesDelegation patterns from references/
Task ComplexityNumber of independent subtasks, dependencies between them

Only ask user for THEIR specific requirements (delegation strategy is in this skill).


Core Principle: Context Isolation

code
WITHOUT subagent-teams:
  Main Context: [Explore + Search + Read + Analyze + Plan + Implement + Test]
  Result: Context fills → Auto-compact triggers → Quality degrades

WITH subagent-teams:
  Main Context: [Decompose → Delegate → Synthesize → Decide]
  Subagent 1: [Explore codebase] → returns summary
  Subagent 2: [Run tests] → returns pass/fail
  Subagent 3: [Implement feature] → returns code
  Result: Main context stays lean → No auto-compact → Consistent quality

Workflow

Phase 1: Task Decomposition

Analyze the user's request and break it into independent subtasks:

  1. Identify the full scope of what needs to be done
  2. Map dependencies — which tasks depend on others?
  3. Group independent tasks — these can run in parallel
  4. Identify sequential gates — tasks that must complete before others start
code
User Request
     │
     ▼
┌─────────────────────────┐
│ Dependency Analysis      │
│ - Independent tasks → parallel batch
│ - Dependent tasks → sequential order
│ - Gates → sync points  │
└─────────────────────────┘
     │
     ▼
[Parallel Batch 1] → [Gate] → [Parallel Batch 2] → [Gate] → [Final Synthesis]

Phase 2: Team Assignment

For each subtask, select the optimal subagent configuration:

Subtask Typesubagent_typeModelTools
Codebase explorationExplorehaikuRead, Grep, Glob
Architecture designPlansonnetAll read tools
Multi-step implementationgeneral-purposesonnet/opusAll tools
Simple file searchExplorehaikuGlob, Grep
Code reviewExploresonnetRead, Grep
Test executiongeneral-purposehaikuBash, Read

Phase 3: Parallel Dispatch

Launch independent subagents in a single message with multiple Task tool calls:

code
# CORRECT: Single message, multiple tool calls (parallel)
Message contains:
  - Task tool call 1: Explore agent for codebase research
  - Task tool call 2: Explore agent for pattern analysis
  - Task tool call 3: General-purpose agent for test execution

# WRONG: Sequential messages (wastes time)
Message 1: Task tool call 1
[wait for result]
Message 2: Task tool call 2
[wait for result]

Phase 4: Result Synthesis

After subagents return:

  1. Collect all subagent outputs (compact summaries only enter main context)
  2. Analyze findings for conflicts or gaps
  3. Synthesize into unified action plan
  4. Execute final decisions in main context (or delegate next batch)

Phase 5: Sequential Gates (if needed)

When later tasks depend on earlier results:

  1. Wait for Batch 1 subagents to complete
  2. Synthesize Batch 1 results
  3. Use synthesized results to inform Batch 2 prompts
  4. Launch Batch 2 subagents in parallel
  5. Repeat until task is complete

Delegation Decision Matrix

ConditionAction
Task has 3+ independent subtasksUse subagent-teams
Context window already largeDelegate ALL exploration
Task involves multiple file readsDelegate to Explore agents
Task requires testing + implementationSeparate into different agents
Task is single-step and simpleDo NOT delegate (overhead not worth it)
Tasks have strict sequential dependencyUse sequential gates, not parallel
User explicitly requests subagent-teamsAlways apply this skill

Subagent Prompt Engineering

Write clear, focused prompts for each subagent:

Must Include

  • Specific goal: What exactly to find/do/produce
  • Scope boundary: What files/areas to focus on
  • Output format: How to structure the response
  • Context: Relevant information from earlier steps

Must NOT Include

  • Unnecessary background (wastes subagent context)
  • Multiple unrelated tasks in one agent (breaks specialization)
  • Vague instructions ("look around the codebase")

Template

code
"[Action verb] [specific target] in [scope].
Focus on [key aspects].
Return: [structured output format].
Context: [relevant prior findings if any]."

Anti-Patterns

Anti-PatternWhy It's BadCorrect Approach
Reading 10+ files in main contextFills context → auto-compactDelegate to Explore agent
Long grep/search chains in mainEach result adds to contextSingle Explore agent does all searching
Explore AND implement in same sessionDouble context usageExplore agents first, then implement
One mega-agent for everythingNo specialization, bloated contextMultiple focused agents
Not using run_in_backgroundBlocks main sessionUse background for long tasks
Asking subagent for info you already haveWastes subagent contextPass known context in prompt

Model Selection Strategy

Task ComplexityModelCostUse When
Simple search/grephaikuLowFinding files, simple patterns
Moderate analysissonnetMediumCode review, architecture design
Complex reasoningopusHighMulti-step implementation, critical decisions
Default (unspecified)inherits-When unsure, let it inherit

Error Handling

ScenarioRecovery
Subagent returns incomplete resultsRe-launch with more specific prompt
Subagent times outCheck with AgentOutputTool, adjust scope
Conflicting results from agentsSynthesize manually, prioritize authoritative source
Too many parallel agentsLimit to 3-5 concurrent, batch the rest
Background agent still runningUse AgentOutputTool with block=false to check status

Output Checklist

Before completing a subagent-teams workflow, verify:

  • All subtasks identified and categorized (independent vs dependent)
  • Subagent types correctly matched to task types
  • Independent tasks launched in parallel (single message)
  • Sequential gates properly handled
  • Results synthesized into coherent output
  • Main context remains lean (no unnecessary file reads)
  • Model selection optimized for cost/performance

Reference Files

FileWhen to Read
references/delegation-patterns.mdComplex task decomposition examples
references/prompt-templates.mdSubagent prompt engineering patterns
references/context-management.mdContext window optimization strategies