$npx -y skills add aaddrick/claude-pipeline --skill dispatching-parallel-agentsUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies
| 1 | # Dispatching Parallel Agents |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | When you have multiple unrelated failures (different test files, different subsystems, different bugs), investigating them sequentially wastes time. Each investigation is independent and can happen in parallel. |
| 6 | |
| 7 | **Core principle:** Dispatch one agent per independent problem domain. Let them work concurrently. |
| 8 | |
| 9 | ## When to Use |
| 10 | |
| 11 | ```dot |
| 12 | digraph when_to_use { |
| 13 | "Multiple failures?" [shape=diamond]; |
| 14 | "Are they independent?" [shape=diamond]; |
| 15 | "Single agent investigates all" [shape=box]; |
| 16 | "One agent per problem domain" [shape=box]; |
| 17 | "Can they work in parallel?" [shape=diamond]; |
| 18 | "Sequential agents" [shape=box]; |
| 19 | "Parallel dispatch" [shape=box]; |
| 20 | |
| 21 | "Multiple failures?" -> "Are they independent?" [label="yes"]; |
| 22 | "Are they independent?" -> "Single agent investigates all" [label="no - related"]; |
| 23 | "Are they independent?" -> "Can they work in parallel?" [label="yes"]; |
| 24 | "Can they work in parallel?" -> "Parallel dispatch" [label="yes"]; |
| 25 | "Can they work in parallel?" -> "Sequential agents" [label="no - shared state"]; |
| 26 | } |
| 27 | ``` |
| 28 | |
| 29 | **Use when:** |
| 30 | - 3+ test files failing with different root causes |
| 31 | - Multiple subsystems broken independently |
| 32 | - Each problem can be understood without context from others |
| 33 | - No shared state between investigations |
| 34 | |
| 35 | **Don't use when:** |
| 36 | - Failures are related (fix one might fix others) |
| 37 | - Need to understand full system state |
| 38 | - Agents would interfere with each other |
| 39 | |
| 40 | ## The Pattern |
| 41 | |
| 42 | ### 1. Identify Independent Domains |
| 43 | |
| 44 | Group failures by what's broken: |
| 45 | - File A tests: Tool approval flow |
| 46 | - File B tests: Batch completion behavior |
| 47 | - File C tests: Abort functionality |
| 48 | |
| 49 | Each domain is independent - fixing tool approval doesn't affect abort tests. |
| 50 | |
| 51 | ### 2. Create Focused Agent Tasks |
| 52 | |
| 53 | Each agent gets: |
| 54 | - **Specific scope:** One test file or subsystem |
| 55 | - **Clear goal:** Make these tests pass |
| 56 | - **Constraints:** Don't change other code |
| 57 | - **Expected output:** Summary of what you found and fixed |
| 58 | |
| 59 | ### 3. Dispatch in Parallel |
| 60 | |
| 61 | ```typescript |
| 62 | // In Claude Code / AI environment |
| 63 | Task("Fix agent-tool-abort.test.ts failures") |
| 64 | Task("Fix batch-completion-behavior.test.ts failures") |
| 65 | Task("Fix tool-approval-race-conditions.test.ts failures") |
| 66 | // All three run concurrently |
| 67 | ``` |
| 68 | |
| 69 | ### 4. Review and Integrate |
| 70 | |
| 71 | When agents return: |
| 72 | - Read each summary |
| 73 | - Verify fixes don't conflict |
| 74 | - Run full test suite |
| 75 | - Integrate all changes |
| 76 | |
| 77 | ## Agent Prompt Structure |
| 78 | |
| 79 | Good agent prompts are: |
| 80 | 1. **Focused** - One clear problem domain |
| 81 | 2. **Self-contained** - All context needed to understand the problem |
| 82 | 3. **Specific about output** - What should the agent return? |
| 83 | |
| 84 | ```markdown |
| 85 | Fix the 3 failing tests in src/agents/agent-tool-abort.test.ts: |
| 86 | |
| 87 | 1. "should abort tool with partial output capture" - expects 'interrupted at' in message |
| 88 | 2. "should handle mixed completed and aborted tools" - fast tool aborted instead of completed |
| 89 | 3. "should properly track pendingToolCount" - expects 3 results but gets 0 |
| 90 | |
| 91 | These are timing/race condition issues. Your task: |
| 92 | |
| 93 | 1. Read the test file and understand what each test verifies |
| 94 | 2. Identify root cause - timing issues or actual bugs? |
| 95 | 3. Fix by: |
| 96 | - Replacing arbitrary timeouts with event-based waiting |
| 97 | - Fixing bugs in abort implementation if found |
| 98 | - Adjusting test expectations if testing changed behavior |
| 99 | |
| 100 | Do NOT just increase timeouts - find the real issue. |
| 101 | |
| 102 | Return: Summary of what you found and what you fixed. |
| 103 | ``` |
| 104 | |
| 105 | ## Common Mistakes |
| 106 | |
| 107 | **❌ Too broad:** "Fix all the tests" - agent gets lost |
| 108 | **✅ Specific:** "Fix agent-tool-abort.test.ts" - focused scope |
| 109 | |
| 110 | **❌ No context:** "Fix the race condition" - agent doesn't know where |
| 111 | **✅ Context:** Paste the error messages and test names |
| 112 | |
| 113 | **❌ No constraints:** Agent might refactor everything |
| 114 | **✅ Constraints:** "Do NOT change production code" or "Fix tests only" |
| 115 | |
| 116 | **❌ Vague output:** "Fix it" - you don't know what changed |
| 117 | **✅ Specific:** "Return summary of root cause and changes" |
| 118 | |
| 119 | ## When NOT to Use |
| 120 | |
| 121 | **Related failures:** Fixing one might fix others - investigate together first |
| 122 | **Need full context:** Understanding requires seeing entire system |
| 123 | **Exploratory debugging:** You don't know what's broken yet |
| 124 | **Shared state:** Agents would interfere (editing same files, using same resources) |
| 125 | |
| 126 | ## Real Example from Session |
| 127 | |
| 128 | **Scenario:** 6 test failures across 3 files after major refactoring |
| 129 | |
| 130 | **Failures:** |
| 131 | - agent-tool-abort.test.ts: 3 failures (timing issues) |
| 132 | - batch-completion-behavior.test.ts: 2 failures (tools not executing) |
| 133 | - tool-approval-race-conditions.test.ts: 1 failure (execution count = 0) |
| 134 | |
| 135 | **Decision:** Independent domains - abort logic separate from batch completion separate from race conditions |
| 136 | |
| 137 | **Dispatch:** |
| 138 | ``` |
| 139 | Agent 1 → Fix agent-tool-abort.test.ts |
| 140 | Agent 2 → Fix batch-completion-behavior.test.ts |
| 141 | Agent 3 → Fix tool-approval-race-conditions.test.ts |
| 142 | ``` |
| 143 | |
| 144 | ** |