Agent skill · Backend & API

agentsop-map-reduce-fanout

Decision protocol for the map-reduce / dynamic fan-out pattern in LM pipelines — "given list L, run f(item) for each item in parallel, then combine". Activates when the coder agent is about to process N items with N LM calls (per-doc summarize, per-query retrieve, per-candidate rank, parallel tool fan-out). Encodes the *when*, *how many at once*, *what to do when one fails*, and *how to reduce* — not the API of any single framework. Cross-framework: LangGraph `Send`, CrewAI parallel tasks / Flow, `asyncio.gather`, `ThreadPoolExecutor`, LlamaIndex batch retrieval.

agentsopegithub.com/agentsopeGitHub ↗
claude-codeMIT
Install
npx skills add agentsope/SkillAlchemy --skill agentsop-map-reduce-fanout --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 1
SKILL.md size: 32 KB
Bundled scripts: none
Version: 0.1.0
Path: skills/agentsop-map-reduce-fanout/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 255
Language: Python

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

Review
written from the skill's own SKILL.md · Aug 5, 2026

What it does

Describes a protocol for running per-item LM calls in parallel and then merging results with a reducer. It activates when the coder is about to process N items with N LM calls and covers when to fan out, how many concurrent executions to allow, how to handle failures, and how to reduce to a final result. It references cross-framework patterns such as LangGraph Send, CrewAI parallel tasks / Flow, asyncio.gather, ThreadPoolExecutor, and LlamaIndex batch retrieval. It does not specify the API of any single framework.

How it works

  • Activation is triggered by scenarios where per-item LM calls are made in parallel and items are independent, or when existing code uses asyncio.gather, ThreadPoolExecutor, Send, or CrewAI kickoff_for_each.
  • The Core Mental Model explains fan-out for latency and fan-in for coherence, with the unit of fan-out being the item and the reducer shaping the final output.
  • Standard workflow steps include confirming item independence, estimating cost and budgets, choosing N_concurrent, deciding failure policy, selecting a reducer, and setting per-call and total timeouts. It also covers verifying the sanity of the reduction after it runs.
  • Operation models provide concrete patterns: OP-1 via asyncio.gather with bounded concurrency; OP-2 for first-K results via asyncio.as_completed; OP-3 through LangGraph Send for dynamic fan-out; OP-4 using a reducer to merge parallel writes; OP-5 through OP-7 for parallel invocations with CrewAI, ThreadPoolExecutor, and LlamaIndex batch retrieval; OP-8 describes tree-reduce for large N; OP-9 adds a per-item retry wrapper; OP-10 adds item-level and reduce-step observability.

When to use it

  • Activate when any activation rule is met, such as a task description describing per-item LM calls, an independent for item in items: lm(item) loop, or evidence of existing parallel patterns and potential fan-out concerns.
  • Use when you need to decide how many concurrent calls to run and how to reduce results, especially if a LangGraph Send-based fan-out or CrewAI parallelization is involved.

What it can touch

  • Tools and concepts named: LangGraph Send, CrewAI, asyncio.gather, ThreadPoolExecutor, LlamaIndex batch retrieval, and per-call timeouts. Specific code patterns demonstrate how to implement bounded concurrency, early completion (first-K), and parallel writes with reducers.

Caveats

  • Mentions policies for failure handling (Abort-all, Best-effort, Retry-then-skip, Quorum) and various reducers (concatenate, summarize, vote, rank-top-K, merge-dedupe, tree-reduce), with safety and budgeting considerations. It emphasizes choosing semantics before fan-out and setting timeouts.
  • Describes that a reducer is mandatory when multiple parallel writes occur to the same state key in LangGraph, and that parallel patterns require explicit reduction to produce a coherent output.
From the SKILL.md

# Map-Reduce / Dynamic Fan-Out · SOP > Pattern: `results = reduce(combine, parallel_map(f, L))` where `f` is one > or more LM calls. The *only* reason to fan out is that latency or > throughput matters more than the cost of doing it. The *only* reason to > fan in is that the consumer wants one answer, not N. > Source posture: claims grounded in primary docs and 2026 production > write-ups, cited inline with short tags resolved in the citation index. --- ## 1. 何时激活 (Activation Rules) Activate this skill when **any** of these is true: - The task description contains "for each X, do Y" where Y involves an LM call, a retriever hit, or any I/O-bound step costing >100ms. - The coder is about to write a `for item in items: result = llm(item)` loop and the items are independent (no item depends on the previous result). - The codebase already has `asyncio.gather(...)`, `ThreadPoolExecutor(...)`, `Send(...)`, `Process.hierarchical` parallel branches, or `crew.kickoff_for_each(...)` and the question is *how* to use them safely. - The user mentions any of: "summarize N docs", "rank top-K candidates", "vote across M models", "ensemble", "parallel agents", "multi-query retrieval", "scatter-gathe

What's inside
Steps it walks through
  1. 1. 何时激活 (Activation Rules)
  2. 2. 核心心智模型 (Core Mental Model)
  3. 3. SOP 工作流 (Standard Operating Protocol)
  4. Step 1 · Confirm items are independent
  5. Step 2 · Estimate cost honestly
  6. Step 3 · Pick Nconcurrent (the most important number in the file)
  7. Step 4 · Decide the failure policy before writing the fan-out
  8. Step 5 · Pick the reducer
  9. Step 6 · Set per-call timeout and total wall-clock budget
  10. Step 7 · Reduce, then verify the reduction is sane
  11. 4. 操作模型 (Operation Models)
  12. OP-1 · asyncio.gather with bounded concurrency (Python baseline)
  13. OP-2 · asyncio.ascompleted for quorum / first-K
  14. OP-3 · LangGraph Send for dynamic fan-out
More from SkillAlchemy
All skills →
About this skill
What does the agentsop-map-reduce-fanout skill do?

Decision protocol for the map-reduce / dynamic fan-out pattern in LM pipelines — "given list L, run f(item) for each item in parallel, then combine". Activates when the coder agent is about to process N items with N LM calls (per-doc summarize, per-query retrieve, per-candidate rank, parallel tool fan-out). Encodes the *when*, *how many at once*, *what to do when one fails*, and *how to reduce* — not the API of any single framework. Cross-framework: LangGraph `Send`, CrewAI parallel tasks / Flow, `asyncio.gather`, `ThreadPoolExecutor`, LlamaIndex batch retrieval.

How do I install it?

Run `npx skills add agentsope/SkillAlchemy --skill agentsop-map-reduce-fanout --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.

Where does this skill come from?

From agentsope/SkillAlchemy, a repository with 255 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.

Is a popular skill a good skill?

Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.

Keep going