一键导入
swarm-map-reduce
Map-reduce orchestration. Parallel mappers process input chunks independently, then a dedicated reducer merges all outputs.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Map-reduce orchestration. Parallel mappers process input chunks independently, then a dedicated reducer merges all outputs.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Fan-out parallel specialists for concurrent analysis. Dispatch read-only reviewers, researchers, and analyzers against a target.
Dispatch a swarm using any orchestration pattern. Routes to the appropriate pattern-specific skill based on the selected preset.
Pipeline and task-graph orchestration. Sequential stages with dependency edges — linear chain or arbitrary DAG.
Speculative orchestration. Competing implementations in isolated worktrees, evaluated by a judge who selects the winner.
Self-claiming pool orchestration. Workers race to claim tasks from a shared pool, loop until the pool is empty.
| name | swarm-map-reduce |
| description | Map-reduce orchestration. Parallel mappers process input chunks independently, then a dedicated reducer merges all outputs. |
This skill is invoked by the
swarmdispatcher. You should already have the goal, target, and selected roles from the dispatcher. If invoked directly, start from step 1.
Fan-out with structured input splitting and a dedicated reduce phase. Mappers process independent chunks in parallel; a reducer teammate merges all mapper outputs into a unified result.
Delegate mode prevents the lead from reading files, running code,
or writing output. The reducer needs general-purpose access to
produce structured merged artifacts. It is spawned as a teammate,
not handled by the lead.
You MUST complete these steps in order:
Determine from the user's request (or dispatcher context):
If unclear, ask the user. Do not guess scope.
Read $CLAUDE_PLUGIN_ROOT/config/swarm-roles.yaml to get the
preset config.
From the preset, determine:
map_role: the role for mapper agents (default: mapper)reduce_role: the role for the reducer agent (default:
reducer)split_strategy: how to partition the targetThe dispatcher has already validated config shape (role existence,
required fields, subagent_type values). The checks below cover
map-reduce-specific semantics.
reduce_role must have
subagent_type: general-purpose. A reducer with Explore cannot
write merged output. If the reducer role uses Explore, warn
and recommend changing it — or note that isolation: worktree
will override it to general-purpose at spawn time.split_strategy must be present and
one of by-directory, by-file-count, or manual. If absent or
unrecognized, report the error and abort.Partition the target into chunks based on split_strategy:
by-directoryList top-level directories in the target path. One mapper per directory.
by-file-countCount files in the target. Split into roughly equal groups (default: ceil(total / 5) files per group, minimum 3 mappers).
manualAsk the user to specify the split. Present the target structure and let them define chunk boundaries.
The number of chunks determines the number of mappers.
Only one team can exist per session. Before creating a new team, check if one already exists.
If a team exists:
TeamDelete)./resume): agents
from the previous session are gone but the team and task list
persist. Offer the user two options:
TeamDelete the orphaned team, then
proceed with a fresh swarm.TaskList for completed
tasks, synthesize any available findings from completed tasks,
then TeamDelete and optionally re-run incomplete tasks.Present the dispatch plan using AskUserQuestion:
I'll dispatch a map-reduce with these parameters:
- Mappers: {N} (one per chunk)
- Reducer: 1 ({reduce_role})
- Split strategy: {strategy}
- Target: {target}
Chunks:
1. {chunk description / directory / file group}
2. {chunk description}
...
The reducer will merge all mapper outputs after they complete.
Proceed?
Do NOT spawn anything until the user confirms.
Use format: swarm-map-reduce-{goal-slug}-{timestamp}
Generate the timestamp from the current date/time as a Unix epoch.
TeamCreate with team_name: "swarm-map-reduce-{goal-slug}-{ts}"
Mapper tasks — one per chunk via TaskCreate:
subject: imperative title including chunk identifier
(e.g., "Audit src/auth/ directory")description: detailed scope, specific files in this chunk,
reporting format expectationsactiveForm: present-continuous spinner labelReducer task — one via TaskCreate:
subject: "Merge mapper outputs into unified report"description: merge instructions, expected input count,
output formatactiveForm: "Merging mapper outputs"addBlockedBy: all mapper task IDs — reducer auto-unblocks
when all mappers completeFor each chunk, spawn one mapper agent via Agent with:
team_name: the team name from step 6name: mapper-{n} (e.g., mapper-1, mapper-2)subagent_type: from the map role configmodel: from the map role config (if specified)run_in_background: trueprompt: composed from the parts belowBefore spawning, check the map role's isolation field:
isolation: worktree is set:
subagent_type to general-purposeRole {name}: using general-purpose (worktree isolation requires write access)isolation: "worktree" to the Agent tool callisolation is absent: use the role's subagent_type as-isYour name is {name}. You are part of team {team_name}.
You are mapper {n} of {N} in a map-reduce operation.
Instructions:
- Claim your task from TaskList, mark it in_progress, then
completed when done.
- Send your findings to the team lead via SendMessage when
complete.
- Include a summary field in your message (5-10 words).
- Use consistent output format so the reducer can merge easily.
The prompt field from swarm-roles.yaml for the map role.
## Goal
{goal description from user}
## Your Chunk
{specific chunk assignment — directories, files, or scope}
{any additional context the user provided}
Spawn one reducer agent via Agent with:
team_name: the team name from step 6name: reducersubagent_type: from the reduce role config
(typically general-purpose)model: from the reduce role config (if specified)run_in_background: trueprompt: composed from the parts belowYour name is reducer. You are part of team {team_name}.
You are the reducer in a map-reduce operation with {N} mappers.
Instructions:
- Your task is blocked until all mappers complete. It will unblock
automatically when dependencies finish — the lead will forward
mapper outputs to you shortly after.
- Once you receive all mapper outputs, merge them into a unified
result.
- Claim your task from TaskList, mark it in_progress, then
completed when done.
- Send your merged result to the team lead via SendMessage.
- Include a summary field in your message (5-10 words).
- Mark the task as completed.
The prompt field from swarm-roles.yaml for the reduce role.
## Goal
{goal description from user}
## Expected Input
You will receive {N} mapper outputs via SendMessage from the team
lead after all mappers complete.
{any additional context about desired output format}
Mappers send findings via SendMessage as they complete. Messages
are delivered automatically.
Track which mappers have reported. All mapper tasks must complete before proceeding to the reduce phase.
Error handling:
When all mappers have completed:
SendMessage in a
single message (or sequentially if too large)The reducer task auto-unblocks when all mapper tasks are marked complete. The reducer claims its task, merges the outputs, and sends the unified result back to the lead.
Once the reducer sends its merged result:
Present the unified report to the user. Include both the merged result and a note about how many mappers contributed.
## Map-Reduce Analysis Report
**Goal:** {goal}
**Target:** {target}
**Mappers:** {N} ({M} reported successfully)
**Reducer:** {reducer role name}
### Merged Findings
{reducer's unified output}
### Summary
{brief overall assessment — coverage, key themes, confidence}
After presenting the report:
Wait for the user to decide next steps.
When the user indicates they're done:
shutdown_request to each agent via SendMessage
(include the monitor agent if watchdog: true was active)shutdown_response from each. If an agent does not
respond after a reasonable wait, send one nudge message. If
still unresponsive, proceed — the agent may have crashed or
terminated.TeamDelete to clean up. TeamDelete is the authoritative
cleanup mechanism — it will fail if active agents remain. If
it fails, retry after unresponsive agents have timed out.general-purpose access