Multi-Task: Parallel Batch Orchestration
Overview
When users present tasks that decompose into multiple independent work units, serial execution wastes time. This skill guides you to identify batch opportunities, construct self-contained prompts for each unit, and dispatch them as parallel subagents via the Task tool — completing in minutes what would otherwise take much longer sequentially.
The core insight: a single message can contain multiple Task tool calls, and they all execute concurrently. Your job is to make each subagent's prompt fully self-contained (they cannot see this conversation) and to coordinate the results.
When to Use This Skill
Strong signals:
- - User says "process all files in X folder"
- User provides a list: "do A, B, C, D for each of these..."
- User mentions "batch", "bulk", "every", "each", "all N files"
- A folder contains multiple files needing the same operation
- User wants multiple pages/components/reports generated
Also consider using when:
- - User describes repetitive work that you'd otherwise do in a loop
- The task involves 3+ independent units of similar type
- Processing time per unit is non-trivial (reading/transforming documents, generating code, etc.)
Do NOT use when:
- - Tasks have strict sequential dependencies (output of task N feeds into task N+1)
- There are fewer than 3 work units (overhead isn't worth it)
- The task is a single complex operation that can't be decomposed
- User explicitly asks for serial processing
The 6-Step Workflow
Step 1: ANALYZE — Understand the Work
Before dispatching anything, enumerate what needs to be done:
- 1. List all work units — files to process, pages to build, items to transform
- Identify the operation — what happens to each unit (extract, convert, summarize, generate, etc.)
- Check for shared context — do all units need the same template, config, or reference data? If so, read it once now and include it in every subagent prompt.
- Detect dependencies — are any units dependent on others? If yes, read
references/advanced-patterns.md for dependency handling strategies. If all units are independent (the common case), proceed directly. - Count the units — this determines your dispatch strategy:
- 3-10 units: single wave, all parallel
- 11-50 units: dispatch in waves of 8-10
- 50+ units: run 2-3 pilot tasks first to validate your prompt, then dispatch the rest in waves
Present your analysis to the user:
CODEBLOCK0
Wait for user confirmation before dispatching, especially for large batches.
Step 2: PLAN — Decompose into Task Units
For each work unit, define:
- - task-ID: Sequential identifier (task-001, task-002, ...)
- input: Absolute path(s) to input file(s) or data
- operation: What the subagent should do
- output: Absolute path for results (ensure no path conflicts between tasks)
- recommended skill: If the task matches an installed skill (see Skill Matching below)
Output path strategy: Create a dedicated output directory to keep results organized:
CODEBLOCK1
Use mkdir -p to create the output directory structure before dispatching.
Step 3: PROMPT — Construct Subagent Prompts
Each subagent starts with a blank context — it cannot see this conversation. Every prompt must be completely self-contained. Use this template:
CODEBLOCK2
Prompt quality checklist:
- - [ ] All paths are absolute
- [ ] No references to "the conversation" or "as discussed"
- [ ] Shared context is included verbatim, not by reference
- [ ] Output paths are unique per task (no conflicts)
- [ ] Instructions are specific enough for an agent with no prior context
- [ ] Skill recommendation is included if applicable
Step 4: DISPATCH — Send Tasks in Parallel
The critical mechanism: Include multiple Task tool calls in a single message. This is what makes them parallel. If you send them in separate messages, they run serially.
For 3-10 tasks: Send all in one message:
CODEBLOCK3
For 11-50 tasks: Dispatch in waves of 8-10. Wait for each wave to complete before starting the next:
CODEBLOCK4
For 50+ tasks: Run a pilot first:
- 1. Pick 2-3 representative tasks (include edge cases if possible)
- Dispatch them as a pilot wave
- Verify results are correct
- If issues found, fix the prompt template and re-pilot
- Once validated, dispatch the remaining tasks in waves of 8-10
Subagent type selection:
- - Default:
general-purpose (has access to all tools including Skill) - For pure shell/git tasks: INLINECODE3
- For code exploration only: INLINECODE4
Run tasks in background when appropriate: For large batches, use run_in_background: true so you can monitor progress and report to the user incrementally.
Step 5: MONITOR — Track Progress
As results come back:
- 1. Track completion — maintain a mental tally: "Wave 1: 8/10 complete"
- Check for failures — if a task fails:
- Analyze the error
- Fix the prompt if needed
-
Retry up to 2 times automatically
- If still failing after 2 retries, mark as failed and continue with others
- 3. Report progress to user after each wave:
Wave 1 complete: 9/10 succeeded, 1 failed (task-007: [reason])
Starting wave 2...
- 4. Failure isolation — one task's failure must never block or affect other tasks
Step 6: MERGE — Collect and Present Results
After all waves complete:
- 1. Sort results by task-ID — present in order regardless of completion time
- Summarize outcomes:
Batch complete: N/M tasks succeeded
Successful:
- task-001: [output path] — [brief description]
- task-002: [output path] — [brief description]
...
Failed (if any):
- task-007: [error reason] — [suggested fix]
- 3. Handle failed tasks — offer to retry failed tasks or let user fix input and rerun
- Merge outputs if requested — some batch operations need a final merge step (e.g., combining extracted text into one document). Do this after all tasks complete.
Skill Matching
When planning tasks, match each work unit against installed skills. This dramatically improves subagent performance because skills provide specialized, tested instructions.
Matching rules:
| Task involves... | Recommend skill |
|---|
| PDF files (read, create, merge, extract) | INLINECODE6 |
| Word documents (.docx read, create, edit) |
/docx |
| PowerPoint files (.pptx) |
/pptx |
| Spreadsheets (.xlsx, .csv, .tsv) |
/xlsx |
| Web pages, components, HTML/CSS |
/frontend-design |
| Visual design, posters, art |
/canvas-design |
| Styling artifacts with themes |
/theme-factory |
How to include skill recommendations in prompts:
In each subagent's prompt, add the skill invocation instruction:
CODEBLOCK7
If no installed skill matches, omit the skill recommendation section — the subagent will use its general capabilities.
Examples
Example 1: Batch PDF Text Extraction
User: "Extract text from all PDFs in /Users/me/reports/ and save as markdown files"
Analysis:
CODEBLOCK8
Subagent prompt (each task):
CODEBLOCK9
Example 2: Multi-Page Frontend Development
User: "Build 5 pages for our marketing site: Home, About, Pricing, Blog, Contact"
Analysis:
CODEBLOCK10
Key considerations:
- - Read any existing shared components/styles first
- Include the full shared context (brand colors, fonts, layout patterns) in each prompt
- Each subagent gets
/frontend-design skill recommendation - Output to separate directories:
pages/home/, pages/about/, etc.
Example 3: Batch Data Conversion
User: "Convert all CSV files in /data/raw/ to JSON format with proper types"
Analysis:
CODEBLOCK11
Key considerations:
- - Each subagent gets
/xlsx skill recommendation (handles CSV) - Include type inference rules in every prompt
- Standardize output format in the prompt template
Troubleshooting
| Problem | Cause | Fix |
|---|
| Tasks run serially, not parallel | Task calls sent in separate messages | Put ALL Task calls in a single message |
| Subagent says "I don't have context" |
Prompt references conversation history | Make prompt fully self-contained |
| File not found errors | Relative paths used | Use absolute paths everywhere |
| Output files overwrite each other | Same output path for multiple tasks | Use task-ID in output directory path |
| Subagent doesn't use recommended skill | Skill instruction unclear | Add explicit
Skill(skill="name") call instruction |
| Too many tasks overwhelm the system | Dispatching 50+ at once | Use waves of 8-10 |
| Results arrive in wrong order | Relying on completion order | Sort by task-ID, not completion time |
| One failure cascades to others | Shared state between tasks | Ensure full isolation — separate dirs, no shared files |
Advanced Patterns
For handling tasks with dependencies (linear chains, fan-in/fan-out, partial dependencies), dynamic batch sizing, and conditional dispatch, read references/advanced-patterns.md.
多任务:并行批量编排
概述
当用户提出的任务可分解为多个独立工作单元时,串行执行会浪费大量时间。本技能指导您识别批量处理机会,为每个单元构建自包含提示,并通过任务工具将其作为并行子代理分发——在几分钟内完成原本需要串行处理更长时间的工作。
核心要点:单条消息可包含多个任务工具调用,且它们会并发执行。您的工作是确保每个子代理的提示完全自包含(它们无法看到当前对话)并协调处理结果。
何时使用本技能
强信号:
- - 用户说处理X文件夹中的所有文件
- 用户提供列表:对每个文件执行A、B、C、D操作...
- 用户提到批量、大量、每个、所有N个文件
- 文件夹中包含多个需要相同操作的文件
- 用户希望生成多个页面/组件/报告
也可考虑使用:
- - 用户描述本需循环执行的重复性工作
- 任务涉及3个以上同类独立单元
- 每个单元的处理时间不可忽略(读取/转换文档、生成代码等)
请勿使用:
- - 任务存在严格串行依赖关系(任务N的输出是任务N+1的输入)
- 工作单元少于3个(开销不值得)
- 任务是无法分解的单一复杂操作
- 用户明确要求串行处理
六步工作流程
第一步:分析——理解工作内容
在分发任何任务前,列举需要完成的事项:
- 1. 列出所有工作单元——需处理的文件、需构建的页面、需转换的项目
- 确定操作类型——每个单元要执行的操作(提取、转换、总结、生成等)
- 检查共享上下文——所有单元是否需要相同的模板、配置或参考数据?如果是,立即读取一次并包含在每个子代理提示中
- 检测依赖关系——是否有单元依赖于其他单元?如果是,请阅读references/advanced-patterns.md了解依赖处理策略。如果所有单元都独立(常见情况),直接进行下一步
- 统计单元数量——这决定您的分发策略:
- 3-10个单元:单波次,全部并行
- 11-50个单元:按8-10个一批分波次分发
- 50个以上单元:先运行2-3个试点任务验证提示,然后按波次分发剩余任务
向用户展示分析结果:
发现N个工作单元:[简要列表]
操作类型:[每个单元将执行的操作]
共享上下文:[任何公共依赖]
依赖关系:[无/描述]
策略:[单波次/M波次每波约K个/试点+波次]
在分发前等待用户确认,尤其是大批量任务。
第二步:规划——分解为任务单元
为每个工作单元定义:
- - 任务ID:顺序标识符(task-001、task-002...)
- 输入:输入文件或数据的绝对路径
- 操作:子代理应执行的操作
- 输出:结果的绝对路径(确保任务间无路径冲突)
- 推荐技能:如果任务匹配已安装技能(参见技能匹配部分)
输出路径策略: 创建专用输出目录以保持结果有序:
<项目目录>/multi-task-output/
├── task-001/
├── task-002/
└── ...
在分发前使用mkdir -p创建输出目录结构。
第三步:提示——构建子代理提示
每个子代理从空白上下文开始——它无法看到当前对话。每个提示必须完全自包含。使用此模板:
任务 [任务ID]:[简要描述]
技能推荐
[如果有匹配技能]:
您可以使用/[技能名称]技能,该技能非常适合此任务。
请先使用技能工具调用它:Skill(skill=[技能名称])以获取专业指导。
上下文
[子代理需要的任何共享上下文——项目背景、约定、模板、参考数据。
包含实际内容,而非引用上述对话。]
输入
- - 文件:[绝对路径]
- [任何其他输入,使用绝对路径]
指令
[清晰、逐步的操作说明]
- 1. [步骤1]
- [步骤2]
...
输出
- - 保存结果至:[任务特定输出目录的绝对路径]
- 预期交付物:[输出文件列表]
- [任何格式要求]
重要提示
- - 所有文件操作使用绝对路径
- 不要修改输入文件
- 如果遇到错误,将错误详情保存至[输出目录]/error.log
提示质量检查清单:
- - [ ] 所有路径均为绝对路径
- [ ] 无对话或如上所述等引用
- [ ] 共享上下文逐字包含,非引用方式
- [ ] 每个任务的输出路径唯一(无冲突)
- [ ] 指令足够具体,适合无先前上下文的代理
- [ ] 如适用,包含技能推荐
第四步:分发——并行发送任务
关键机制: 在单条消息中包含多个任务工具调用。这是实现并行的关键。如果在不同消息中发送,它们将串行执行。
对于3-10个任务: 全部在一条消息中发送:
[单条消息包含:]
Task(subagent_type=general-purpose, prompt=## 任务 task-001:..., description=处理文件-001)
Task(subagent_type=general-purpose, prompt=## 任务 task-002:..., description=处理文件-002)
Task(subagent_type=general-purpose, prompt=## 任务 task-003:..., description=处理文件-003)
...
对于11-50个任务: 按8-10个一批分波次分发。等待每个波次完成后再开始下一波次:
波次1:task-001至task-010(单条消息,全部并行)
[等待完成,报告进度]
波次2:task-011至task-020(单条消息,全部并行)
[等待完成,报告进度]
...
对于50个以上任务: 先运行试点:
- 1. 选择2-3个代表性任务(如可能包含边界情况)
- 作为试点波次分发
- 验证结果正确
- 如发现问题,修复提示模板并重新试点
- 验证通过后,按8-10个一批的波次分发剩余任务
子代理类型选择:
- - 默认:general-purpose(可访问所有工具,包括技能)
- 纯shell/git任务:Bash
- 仅代码探索:Explore
适当时在后台运行任务: 对于大批量任务,使用runinbackground: true以便监控进度并逐步向用户报告。
第五步:监控——跟踪进度
随着结果返回:
- 1. 跟踪完成情况——保持心理计数:波次1:8/10完成
- 检查失败——如果任务失败:
- 分析错误
- 必要时修复提示
-
自动重试最多2次
- 如果重试2次后仍失败,标记为失败并继续处理其他任务
- 3. 向用户报告进度——每个波次后:
波次1完成:9/10成功,1失败(task-007:[原因])
开始波次2...
- 4. 失败隔离——一个任务的失败绝不能阻塞或影响其他任务
第六步:合并——收集并呈现结果
所有波次完成后:
- 1. 按任务ID排序结果——按顺序呈现,不论完成时间
- 总结结果:
批量完成:N/M个任务成功
成功:
- task-001:[输出路径] — [简要描述]
- task-002:[输出路径] — [简要描述]
...
失败(如有):
- task-007:[错误原因] — [建议修复]
- 3. 处理失败任务——提供重试失败任务或让用户修复输入后重新运行的选项
- 按要求合并输出——某些批量操作需要最终合并步骤(例如将提取的文本合并到一个文档中)。在所有任务完成后执行此操作。
技能匹配
规划任务时,将每个工作单元与已安装技能匹配。这能显著提升子代理性能,因为技能提供专业、经过测试的指令。
匹配规则:
| 任务涉及... | 推荐技能 |
|---|
| PDF文件(读取、创建、合并、提取) | /pdf |
| Word文档(.docx读取、创建、编辑) |
/docx |
| PowerPoint文件(.pptx) | /pptx |
| 电子表格(.xlsx、.csv、.tsv) | /xlsx |
| 网页、组件、HTML/CSS | /frontend-design |
| 视觉设计、海报、艺术 | /canvas-design |
| 主题样式制品 | /theme-factory |
如何在提示中包含技能推荐:
在每个子代理的提示中,添加技能调用指令:
技能推荐
您可以使用/pdf