building-multiagent-systems
複数のAIエージェントが連携し、複雑なタスクを効率的に達成するシステムを設計・実装するSkill。
📜 元の英語説明(参考)
This skill should be used when designing or implementing systems with multiple AI agents that coordinate to accomplish tasks. Triggers on "multi-agent", "orchestrator", "sub-agent", "coordination", "delegation", "parallel agents", "sequential pipeline", "fan-out", "map-reduce", "spawn agents", "agent hierarchy".
🇯🇵 日本人クリエイター向け解説
複数のAIエージェントが連携し、複雑なタスクを効率的に達成するシステムを設計・実装するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
[Skill 名] building-multiagent-systems
マルチエージェント、ツール使用型エージェントシステムの構築
概要
AIエージェントが連携してツールを使用し、複雑なタスクを達成するマルチエージェントシステムのための包括的なアーキテクチャパターンです。言語に依存せず、TypeScript、Python、Go、Rust、その他の環境に適用可能です。
発見的質問(必須)
システムを設計する前に、以下の6つの必須質問を問いかけてください。
- 出発点 - グリーンフィールド、既存システムへの追加、または現在の実装の修正ですか?
- 主要なユースケース - 並行作業、シーケンシャルパイプライン、再帰的委任、ピアコラボレーション、ワークキュー、その他ですか?
- スケールの期待 - 小規模(2-5エージェント)、中規模(10-50)、または大規模(100以上)ですか?
- 状態要件 - ステートレスな実行、セッションベース、またはクラッシュをまたいだ永続性が必要ですか?
- ツール連携 - 独立したエージェント、共有読み取り専用リソース、書き込み連携、またはレート制限されたAPIですか?
- 既存の制約 - 言語、フレームワーク、パフォーマンス要件、コンプライアンス要件は何ですか?
基本アーキテクチャ
4層スタック
すべてのエージェントは、テスト容易性、安全性、モジュール性を確保するために4層アーキテクチャに従います。
| レイヤー | 名前 | 責任 |
|---|---|---|
| 1 | 推論 (LLM) | 計画、批評、呼び出すツールの決定 |
| 2 | オーケストレーション | 検証、ルーティング、ポリシー適用、サブエージェントの生成 |
| 3 | ツールバス | スキーマ検証、ツール実行の調整 |
| 4 | 決定論的アダプター | ファイルI/O、API、シェルコマンド、データベースアクセス |
重要なルール: レイヤー1より下はすべて決定論的でなければなりません。ツール内でLLMを呼び出してはいけません。
コード例を含む詳細な実装については、references/four-layer-architecture.mdをご覧ください。
基本パターン
| パターン | 目的 |
|---|---|
| イベントソーシング | 監査証跡とリプレイのためのイベントとしてのすべての状態変更 |
| 階層ID | コスト集計のための委任階層のエンコード (例: session.1.2) |
| エージェント状態マシン | 無効な遷移エラーを伴う明示的な状態 (idle → thinking → tool_execution → stopped) |
| コミュニケーション | 状態変更のためのEventEmitter、結果収集のためのPromise |
7つの連携パターン
発見的質問の回答に基づいて選択してください。
| パターン | ユースケース | トレードオフ |
|---|---|---|
| ファンアウト/ファンイン | 並列の独立した作業 | 高速だが高コスト。孤立に注意 |
| シーケンシャルパイプライン | 多段階変換 | 最も遅い段階でボトルネック |
| 再帰的委任 | 階層的なタスク分解 | 深さ制限を追加する必要あり |
| ワークスティーリングキュー | ロードバランシングを伴う1000以上のタスク | 組み込みの優先順位なし |
| Map-Reduce | コスト最適化 | 安価なマップ ($0.01)、スマートなリデュース ($0.15) |
| ピアコラボレーション | バイアス削減のためのLLM評議会 | 高コスト (3N+1回の呼び出し)、低速 |
| MAKER | ゼロエラータスク (10万ステップ以上) | 5倍のコストだがエラー率約0% |
詳細な実装については、references/coordination-patterns.mdをご覧ください。
パターン選択ガイド
| 要件 | 推奨パターン |
|---|---|
| 並列の独立したタスク | ファンアウト/ファンイン |
| 各段階が前段階に依存 | シーケンシャルパイプライン |
| 複雑なタスク分解 | 再帰的委任 |
| 大規模バッチ処理 | ワークスティーリングキュー |
| コスト重視の分析 | Map-Reduce |
| 多様な視点が必要 | ピアコラボレーション |
| ゼロエラー許容度 | MAKER |
MAKERパターン(ゼロエラー)
ゼロエラー許容度で10万ステップ以上のタスク(医療、金融、法律分野)が必要な場合:
- 極端な分解 - 各サブタスクが100ステップ未満になるまで再帰的に分解
- マイクロエージェント - 単一ツール、専門的な専門知識、安価なモデル
- マルチエージェント投票 - サブタスクごとにN個の並列試行、多数決による合意
- エラー訂正 - 決定論的検証 + 失敗コンテキストでの再試行
コスト比較: 従来のアプローチと同じコストで、10以上のエラーに対してゼロエラーです。
医療診断の例を含む完全な実装については、references/maker-pattern.mdをご覧ください。
ツール連携
| メカニズム | 目的 |
|---|---|
| 権限継承 | 子は親の権限のサブセットを継承します(昇格はできません) |
| リソースロック | 共有リソースの取得/解放パターン |
| レート制限 | すべてのエージェントにわたるトークンバケットアルゴリズム |
| 結果キャッシュ | 読み取り専用、冪等、高コストな操作をキャッシュします |
サブエージェントをツールとして扱うパターン: 特殊なエージェントを親が呼び出せるツールとしてラップすることで、構成可能な抽象化と自然なライフサイクル管理を提供します。
実装については、references/tool-coordination.mdをご覧ください。
重要なライフサイクル: カスケードストップ
「常に自分を停止する前に子を停止する。」これにより、孤立したエージェントを防ぎます。
1. すべての子エージェントを取得します
2. すべての子を並行して停止します
3. 自分自身を停止します
4. 進行中の作業をキャンセルします
5. イベントをフラッシュします
一時停止/再開が利用できない場合は、手動でチェックポイントを実装してください。エージェントの状態(メッセージ、コンテキスト、ツール結果)を保存し、後で復元します。
本番環境での強化
| 懸念事項 | 解決策 |
|---|---|
| 孤立検出 | 30秒ごとのハートビート監視 |
| コスト追跡 | エージェントツリー全体の階層的集計 |
| セッション永続性 | セッションをまたいだ作業のためのプロジェクトレベルのタスクストア |
| チェックポイント | 10以上のツール、1.00ドルのコスト、または5分経過後に保存 |
| 自己修正の安全性 | 影響範囲評価、ブランチ分離、テストファースト |
詳細な実装については、references/production-hardening.mdをご覧ください。
実世界の例: コードレビューシステム
ファンアウト/ファンインを使用するプルリクエストオーケストレーター:
- 4人の専門レビューア(セキュリティ、パフォーマンス、スタイル、テスト)を並行して生成します
- セキュリティとテストはスマートモデル(Sonnet)を使用し、スタイルとパフォーマンスは高速モデル(Haiku)を使用します
- 各レビューアには2分のタイムアウトがあります
- 部分的な失敗に関わらず結果を集約します
- コストはレビューアごとに追跡されます
- すべてのエージェントは完了後、カスケードストップによりきれいに停止します
実行チェックリスト
impをガイドする際
(原文がここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Building Multi-Agent, Tool-Using Agentic Systems
Overview
Comprehensive architecture patterns for multi-agent systems where AI agents coordinate to accomplish complex tasks using tools. Language-agnostic and applicable across TypeScript, Python, Go, Rust, and other environments.
Discovery Questions (Required)
Before architecting any system, ask these six mandatory questions:
- Starting Point - Greenfield, adding to existing system, or fixing current implementation?
- Primary Use Case - Parallel work, sequential pipeline, recursive delegation, peer collaboration, work queues, or other?
- Scale Expectations - Small (2-5 agents), medium (10-50), or large (100+)?
- State Requirements - Stateless runs, session-based, or persistent across crashes?
- Tool Coordination - Independent agents, shared read-only resources, write coordination, or rate-limited APIs?
- Existing Constraints - Language, framework, performance needs, compliance requirements?
Foundational Architecture
Four-Layer Stack
Every agent follows the four-layer architecture for testability, safety, and modularity:
| Layer | Name | Responsibility |
|---|---|---|
| 1 | Reasoning (LLM) | Plans, critiques, decides which tools to call |
| 2 | Orchestration | Validates, routes, enforces policy, spawns sub-agents |
| 3 | Tool Bus | Schema validation, tool execution coordination |
| 4 | Deterministic Adapters | File I/O, APIs, shell commands, database access |
Critical Rule: Everything below Layer 1 must be deterministic. No LLM calls in tools.
See references/four-layer-architecture.md for detailed implementation with code examples.
Foundational Patterns
| Pattern | Purpose |
|---|---|
| Event-Sourcing | All state changes as events for audit trails and replay |
| Hierarchical IDs | Encode delegation hierarchy (e.g., session.1.2) for cost aggregation |
| Agent State Machines | Explicit states (idle → thinking → tool_execution → stopped) with invalid transition errors |
| Communication | EventEmitter for state changes, promises for result collection |
Seven Coordination Patterns
Choose based on discovery question answers:
| Pattern | Use Case | Trade-offs |
|---|---|---|
| Fan-Out/Fan-In | Parallel independent work | Fast but costly; watch for orphans |
| Sequential Pipeline | Multi-stage transformations | Bottleneck at slowest stage |
| Recursive Delegation | Hierarchical task breakdown | Must add depth limits |
| Work-Stealing Queue | 1000+ tasks with load balancing | No built-in priority |
| Map-Reduce | Cost optimization | Cheap map ($0.01), smart reduce ($0.15) |
| Peer Collaboration | LLM council for bias reduction | Expensive (3N+1 calls), slow |
| MAKER | Zero-error tasks (100K+ steps) | 5× cost but ~0% error rate |
See references/coordination-patterns.md for detailed implementations.
Pattern Selection Guide
| Requirement | Recommended Pattern |
|---|---|
| Parallel independent tasks | Fan-Out/Fan-In |
| Each stage depends on previous | Sequential Pipeline |
| Complex task decomposition | Recursive Delegation |
| Large batch processing | Work-Stealing Queue |
| Cost-sensitive analysis | Map-Reduce |
| Need diverse perspectives | Peer Collaboration |
| Zero error tolerance | MAKER |
MAKER Pattern (Zero Errors)
For tasks requiring 100K+ steps with zero error tolerance (medical, financial, legal domains):
- Extreme Decomposition - Recursive breakdown until each subtask <100 steps
- Microagents - Single tool, focused expertise, cheap models
- Multi-Agent Voting - N parallel attempts per subtask, majority consensus
- Error Correction - Deterministic validation + retry with failure context
Cost comparison: Same cost as traditional approach, zero errors vs. 10+ errors.
See references/maker-pattern.md for full implementation with medical diagnosis example.
Tool Coordination
| Mechanism | Purpose |
|---|---|
| Permission Inheritance | Children inherit subset of parent permissions (cannot escalate) |
| Resource Locking | Acquire/release patterns for shared resources |
| Rate Limiting | Token bucket algorithm across all agents |
| Result Caching | Cache read-only, idempotent, expensive operations |
Sub-Agent as Tool Pattern: Wrap specialized agents as tools the parent can call, providing composable abstractions and natural lifecycle management.
See references/tool-coordination.md for implementations.
Critical Lifecycle: Cascading Stop
"Always stop children before stopping self." This prevents orphaned agents.
1. Get all child agents
2. Stop all children in parallel
3. Stop self
4. Cancel ongoing work
5. Flush events
If pause/resume unavailable, implement manual checkpointing: save agent state (messages, context, tool results), then restore later.
Production Hardening
| Concern | Solution |
|---|---|
| Orphan Detection | Heartbeat monitoring every 30 seconds |
| Cost Tracking | Hierarchical aggregation across agent tree |
| Session Persistence | Project-level task store for cross-session work |
| Checkpointing | Save after 10+ tools, $1.00 cost, or 5 minutes elapsed |
| Self-Modification Safety | Blast radius assessment, branch isolation, test-first |
See references/production-hardening.md for detailed implementations.
Real-World Example: Code Review System
A pull request orchestrator using Fan-Out/Fan-In:
- Spawns four specialist reviewers in parallel (security, performance, style, tests)
- Security and tests use smart models (Sonnet); style and performance use fast models (Haiku)
- Each reviewer has 2-minute timeout
- Results aggregate regardless of partial failures
- Costs track per reviewer
- All agents stop cleanly via cascading stop after completion
Execution Checklist
When guiding implementation of multi-agent systems:
- Ask discovery questions - Understand requirements before architecting
- Assess error tolerance - Zero errors → MAKER; some acceptable → simpler patterns
- Establish four-layer architecture - Reasoning, orchestration, tool bus, adapters
- Design schema-first tools - Typed contracts before implementation
- Define deterministic boundary - No LLM in Layers 3-4
- Choose orchestration model - YOLO, Safety-First, or Hybrid
- Select coordination pattern - Fan-out, pipeline, delegation, queue, map-reduce, peer, or MAKER
- Design tool coordination - Permission inheritance, locking, rate limiting
- Implement cascading cleanup - Always stop children before parent
- Add monitoring and cost tracking - Hierarchical aggregation across agent tree
- Consider self-modification safety - If agents can modify code, add safety protocol
Common Pitfalls
| Pitfall | Impact |
|---|---|
| Missing four-layer architecture | Untestable, unsafe, hard to debug |
| LLM calls in tools (Layer 3-4) | Non-deterministic, can't unit test |
| No schema-first tool design | Sub-agents can't discover tools |
| Missing cascading stop | Orphaned agents consuming resources |
| No permission inheritance | Sub-agents can escalate privileges |
| No timeouts | Indefinite hangs waiting for sub-agents |
| Unbounded concurrency | Resource exhaustion from too many agents |
| Ignoring cost tracking | Budget surprises |
| No partial-failure handling | One failure cascades to all agents |
| Unpersisted state | Unrecoverable workflows on crash |
| Uncoordinated tool access | Race conditions on shared resources |
| Wrong model selection | Cost inefficiency (Sonnet for simple tasks) |
| Self-modification without safety | Sub-agents break themselves |
| No heartbeat monitoring | Can't detect orphans after parent crash |
Reference Files
Detailed implementations with code examples:
| File | Contents |
|---|---|
references/four-layer-architecture.md |
Four-layer stack, deterministic boundary, schema-first tools |
references/coordination-patterns.md |
Seven coordination patterns with code |
references/maker-pattern.md |
MAKER implementation, voting, medical diagnosis example |
references/tool-coordination.md |
Permission inheritance, locking, rate limiting, caching |
references/production-hardening.md |
Cascading stop, orphan detection, cost tracking, checkpointing |