マルチエージェントの例
エージェントとは
Section titled “エージェントとは”エージェントは、特定のタスクに特化した独立したサブプロセスです。専門的なシステムプロンプトと制限されたツールセットを持ちます。
エージェントの利点
Section titled “エージェントの利点”- 専門化: 各エージェントは特定の役割に特化
- 並列実行: 複数のエージェントを同時に実行可能
- ツール制限: 各エージェントは必要最小限のツールのみ使用
- 再利用: 同じエージェントを異なるコンテキストで再利用
例1: code-explorer エージェント(シンプル)
Section titled “例1: code-explorer エージェント(シンプル)”ファイル: plugins/feature-dev/agents/code-explorer.md
Section titled “ファイル: plugins/feature-dev/agents/code-explorer.md”---name: code-explorerdescription: Deeply analyzes existing codebase featurestools: Glob, Grep, Read, TodoWrite, WebFetch, WebSearchmodel: sonnetcolor: yellow---
You are an expert code analyst specializing in tracing and understanding feature implementations.
## Core MissionProvide a complete understanding of how a specific feature works by tracing its implementation from entry points to data storage.
## Analysis Approach
**1. Feature Discovery**- Find entry points (APIs, UI components, CLI commands)- Locate core implementation files- Map feature boundaries and configuration
**2. Code Flow Tracing**- Follow call chains from entry to output- Trace data transformations at each step- Identify all dependencies and integrations
**3. Architecture Analysis**- Map abstraction layers (presentation → business logic → data)- Identify design patterns and architectural decisions- Document interfaces between components
**4. Implementation Details**- Key algorithms and data structures- Error handling and edge cases- Performance considerations
## Output Guidance
Provide a comprehensive analysis that includes:- Entry points with file:line references- Step-by-step execution flow- Key components and their responsibilities- Architecture insights- List of files essential for understandingYAMLフロントマター
Section titled “YAMLフロントマター”name: code-explorerdescription: Deeply analyzes existing codebase featurestools: Glob, Grep, Read, TodoWrite, WebFetch, WebSearchmodel: sonnetcolor: yellowフィールド:
name: エージェントの一意な名前description: エージェントの説明tools: 使用可能なツール(読み取り専用ツールのみ)model:sonnet(バランス型)color: ターミナル表示色
システムプロンプト
Section titled “システムプロンプト”You are an expert code analyst...エージェントの役割と振る舞いを定義します。
コマンドから起動:
Launch a code-explorer agent to analyze the authentication feature.実行フロー:
1. メインプロセスが code-explorer エージェントを起動 ↓2. エージェントが専門プロンプトで実行開始 ↓3. Glob, Grep, Read ツールでコードベースを探索 ↓4. 分析結果を返却 ↓5. メインプロセスが結果を受け取る例2: 並列マルチエージェント(feature-dev)
Section titled “例2: 並列マルチエージェント(feature-dev)”コマンド: plugins/feature-dev/commands/feature-dev.md
Section titled “コマンド: plugins/feature-dev/commands/feature-dev.md”---description: Guided feature development---
## Phase 2: Codebase Exploration
**Goal**: Understand relevant existing code and patterns
**Actions**:1. Launch 2-3 code-explorer agents in parallel. Each agent should: - Trace through the code comprehensively - Target a different aspect of the codebase - Include a list of 5-10 key files to read
**Example agent prompts**: - "Find features similar to [feature] and trace implementation" - "Map architecture and abstractions for [feature area]" - "Analyze current implementation of [existing feature]"
2. Once agents return, read all files identified by agents3. Present comprehensive summary of findings並列実行の仕組み
Section titled “並列実行の仕組み”メインプロセス ↓ ├─→ code-explorer #1: "Find similar features" ├─→ code-explorer #2: "Map architecture" └─→ code-explorer #3: "Analyze UI patterns" ↓ [並列実行] ↓ ├─← 結果1: 類似機能のリスト + ファイルリスト ├─← 結果2: アーキテクチャマップ + ファイルリスト └─← 結果3: UIパターン分析 + ファイルリスト ↓メインプロセスが全結果を統合例: 3つの並列エージェント
Section titled “例: 3つの並列エージェント”ユーザーリクエスト:
/feature-dev Add dark mode to settingsPhase 2 で起動される3つのエージェント:
Agent 1: 類似機能の探索
Section titled “Agent 1: 類似機能の探索”Prompt: Find features similar to theme switching and trace their implementation comprehensively.
Tasks:- Search for existing theme/style switching code- Trace how settings are persisted- Identify UI components involved
Expected output:- List of similar features- Implementation patterns- 5-10 key files to readAgent 2: アーキテクチャ分析
Section titled “Agent 2: アーキテクチャ分析”Prompt: Map the architecture and abstractions for the settings system, tracing through the code comprehensively.
Tasks:- Identify settings storage mechanism- Map state management approach- Trace configuration flow
Expected output:- Architecture diagram (text)- Key abstractions- 5-10 key files to readAgent 3: UI パターン分析
Section titled “Agent 3: UI パターン分析”Prompt: Analyze UI patterns for settings pages and theme customization.
Tasks:- Identify UI component patterns- Find styling approaches- Locate theme configuration
Expected output:- UI patterns used- Styling conventions- 5-10 key files to readAll agents complete ↓メインプロセス receives: - 15-30 key files to read - Multiple perspectives on the codebase - Comprehensive understanding ↓メインプロセス: - Reads all identified files - Synthesizes findings - Proceeds to next phase例3: 逐次マルチエージェント(設計 → 実装 → レビュー)
Section titled “例3: 逐次マルチエージェント(設計 → 実装 → レビュー)”Phase 4: Architecture Design
Section titled “Phase 4: Architecture Design”**Actions**:1. Launch 2-3 code-architect agents in parallel with different focuses: - Minimal changes (smallest change, maximum reuse) - Clean architecture (maintainability, elegant abstractions) - Pragmatic balance (speed + quality)
2. Review all approaches3. Present to user with recommendationPhase 7: Review
Section titled “Phase 7: Review”**Actions**:1. Launch code-reviewer agent to review implementation2. Address any issues found3. Re-run tests if needed逐次実行フロー
Section titled “逐次実行フロー”Phase 4: Architecture Design ↓ ├─→ code-architect #1: "Minimal changes approach" ├─→ code-architect #2: "Clean architecture approach" └─→ code-architect #3: "Pragmatic approach" ↓ [並列実行] ↓ 結果を受け取り、ユーザーに提示 ↓Phase 5: Implementation ↓ 選択されたアプローチで実装 ↓Phase 6: Testing ↓ テストを実行 ↓Phase 7: Review ↓ code-reviewer エージェントを起動 ↓ レビュー結果を受け取る ↓ 問題があれば修正例4: code-architect エージェント
Section titled “例4: code-architect エージェント”ファイル: plugins/feature-dev/agents/code-architect.md
Section titled “ファイル: plugins/feature-dev/agents/code-architect.md”---name: code-architectdescription: Designs feature architectures and implementation blueprintstools: Read, TodoWritemodel: sonnetcolor: blue---
You are an expert software architect specializing in designing elegant, maintainable solutions.
## Core MissionDesign a clear implementation blueprint for a feature, considering the existing codebase patterns, constraints, and best practices.
## Design Approach
**1. Requirements Analysis**- Understand the feature requirements- Identify constraints and edge cases- Consider performance and scalability
**2. Architecture Options**- Propose 2-3 different architectural approaches- Analyze trade-offs for each approach- Recommend the best approach with reasoning
**3. Implementation Blueprint**- File structure and new files needed- Key interfaces and contracts- Data flow and state management- Integration points with existing code
**4. Risk Assessment**- Potential pitfalls and how to avoid them- Testing strategy- Migration path if needed
## Output Guidance
Provide:- Clear architectural decision with reasoning- Step-by-step implementation plan- Pseudo-code or interface definitions- Files to create/modifyツール制限:
tools: Read, TodoWrite設計エージェントは:
- ✅ ファイルを読める(
Read) - ✅ TODOを管理できる(
TodoWrite) - ❌ ファイルを編集できない(
Edit,Writeなし)
理由: 設計フェーズでは実装すべきではないため。
例5: code-reviewer エージェント
Section titled “例5: code-reviewer エージェント”ファイル: plugins/feature-dev/agents/code-reviewer.md
Section titled “ファイル: plugins/feature-dev/agents/code-reviewer.md”---name: code-reviewerdescription: Reviews code for bugs, quality issues, and project conventionstools: Glob, Grep, Read, Bash(npm test:*), Bash(git diff:*)model: sonnetcolor: red---
You are an expert code reviewer focused on quality, correctness, and maintainability.
## Core MissionThoroughly review code for bugs, style issues, missing tests, and architectural concerns.
## Review Approach
**1. Correctness**- Logic errors and bugs- Edge cases and error handling- Type safety
**2. Code Quality**- Readability and maintainability- Code duplication- Naming conventions
**3. Testing**- Test coverage- Missing test cases- Test quality
**4. Architecture**- Consistency with existing patterns- Separation of concerns- Potential tech debt
## Output Guidance
Provide:- Categorized list of issues (critical, important, nice-to-have)- Specific file:line references- Suggested fixes- Overall assessmentツール制限:
tools: Glob, Grep, Read, Bash(npm test:*), Bash(git diff:*)レビューエージェントは:
- ✅ コードを読める
- ✅ テストを実行できる
- ✅ diffを確認できる
- ❌ ファイルを編集できない(レビューのみ)
エージェント設計パターン
Section titled “エージェント設計パターン”パターン1: Read-Only Explorer
Section titled “パターン1: Read-Only Explorer”用途: コードベース探索、分析
tools: Glob, Grep, Read, TodoWrite例: code-explorer
パターン2: Design-Focused
Section titled “パターン2: Design-Focused”用途: アーキテクチャ設計、計画
tools: Read, TodoWrite例: code-architect
パターン3: Review-Focused
Section titled “パターン3: Review-Focused”用途: コードレビュー、品質チェック
tools: Glob, Grep, Read, Bash(test:*), Bash(git diff:*)例: code-reviewer
パターン4: Implementation-Focused
Section titled “パターン4: Implementation-Focused”用途: 実装、ファイル編集
tools: Glob, Grep, Read, Edit, Write, Bash, TodoWrite例: メインプロセス(通常のClaude Code)
マルチエージェントのベストプラクティス
Section titled “マルチエージェントのベストプラクティス”1. 明確な役割分担
Section titled “1. 明確な役割分担”❌ 悪い例: すべてのエージェントが同じツールセット
# すべてのエージェントが編集可能agent1: tools: Glob, Grep, Read, Edit, Writeagent2: tools: Glob, Grep, Read, Edit, Writeagent3: tools: Glob, Grep, Read, Edit, Write✅ 良い例: 役割に応じたツールセット
explorer: tools: Glob, Grep, Read # 探索のみarchitect: tools: Read, TodoWrite # 設計のみreviewer: tools: Read, Bash(test:*) # レビュー + テスト2. 並列実行の活用
Section titled “2. 並列実行の活用”❌ 悪い例: 逐次実行(遅い)
1. Launch explorer agent2. Wait for result3. Launch another explorer agent4. Wait for result✅ 良い例: 並列実行(速い)
Launch 3 explorer agents in parallel:- Agent 1: Find similar features- Agent 2: Map architecture- Agent 3: Analyze UI patterns3. 適切なモデル選択
Section titled “3. 適切なモデル選択”| タスク | 推奨モデル | 理由 |
|---|---|---|
| シンプルな探索 | haiku | 高速、低コスト |
| 複雑な分析 | sonnet | バランス型 |
| 重要な設計判断 | opus | 最高品質 |
4. 明確な出力期待
Section titled “4. 明確な出力期待”❌ 悪い例: 曖昧な指示
Launch an agent to analyze the code.✅ 良い例: 具体的な出力要求
Launch code-explorer agent to:1. Find authentication-related code2. Trace login flow from API to database3. Return a list of 5-10 key files to read実装例: カスタムマルチエージェントワークフロー
Section titled “実装例: カスタムマルチエージェントワークフロー”目標: /api-review コマンド
Section titled “目標: /api-review コマンド”APIエンドポイントを複数の観点でレビューする。
ファイル構成
Section titled “ファイル構成”plugins/api-review/├── .claude-plugin/│ └── plugin.json├── commands/│ └── api-review.md├── agents/│ ├── security-reviewer.md│ ├── performance-reviewer.md│ └── api-design-reviewer.md└── README.mdcommands/api-review.md
Section titled “commands/api-review.md”---description: Comprehensive API endpoint reviewargument-hint: API endpoint path or file---
# API Review Workflow
## Phase 1: Gather Context
- Target API: $ARGUMENTS- Recent changes: !`git diff HEAD`
## Phase 2: Multi-Perspective Review
Launch 3 specialized reviewer agents in parallel:
1. **security-reviewer**: Check for security vulnerabilities2. **performance-reviewer**: Analyze performance implications3. **api-design-reviewer**: Review API design and consistency
Each agent should provide:- Specific issues with file:line references- Severity level (critical/important/nice-to-have)- Recommended fixes
## Phase 3: Consolidate Findings
After all agents complete:1. Consolidate all findings2. Prioritize issues by severity3. Present actionable recommendationsagents/security-reviewer.md
Section titled “agents/security-reviewer.md”---name: security-reviewerdescription: Reviews APIs for security vulnerabilitiestools: Glob, Grep, Readmodel: sonnetcolor: red---
You are a security expert specializing in API security.
## Review Checklist
**Authentication & Authorization**- Proper authentication checks- Authorization for all endpoints- Token validation
**Input Validation**- SQL injection prevention- XSS prevention- Input sanitization
**Data Protection**- Sensitive data encryption- Proper error messages (no data leaks)- HTTPS enforcement
## Output Format
Provide findings in this format:
### Critical Issues- [file:line] Description and recommended fix
### Important Issues- [file:line] Description and recommended fix
### Nice-to-have Improvements- [file:line] Description and recommended fixagents/performance-reviewer.md
Section titled “agents/performance-reviewer.md”---name: performance-reviewerdescription: Reviews APIs for performance issuestools: Glob, Grep, Readmodel: sonnetcolor: yellow---
You are a performance expert specializing in API optimization.
## Review Checklist
**Database Queries**- N+1 query problems- Missing indexes- Inefficient queries
**Caching**- Appropriate use of caching- Cache invalidation strategy
**Response Size**- Pagination for large datasets- Unnecessary data in responses
## Output Format
[Same as security-reviewer]agents/api-design-reviewer.md
Section titled “agents/api-design-reviewer.md”---name: api-design-reviewerdescription: Reviews API design and consistencytools: Glob, Grep, Readmodel: sonnetcolor: blue---
You are an API design expert.
## Review Checklist
**RESTful Design**- Proper HTTP methods- Consistent URL patterns- Appropriate status codes
**Consistency**- Naming conventions- Error response format- Data structure consistency
**Documentation**- API documentation completeness- Example requests/responses
## Output Format
[Same as security-reviewer]claude
# プロンプトで/api-review /api/users1. ユーザーが /api-review /api/users を実行 ↓2. コマンドが Context を収集 - git diff で最近の変更を確認 ↓3. 3つのレビューエージェントを並列起動 ├─→ security-reviewer ├─→ performance-reviewer └─→ api-design-reviewer ↓ [並列レビュー実行] ↓ ├─← セキュリティ: 2 critical, 3 important ├─← パフォーマンス: 0 critical, 2 important └─← API設計: 0 critical, 1 important, 3 nice-to-have ↓4. メインプロセスが結果を統合 ↓5. 優先度順に整理して表示 ↓6. アクションプランを提示トラブルシューティング
Section titled “トラブルシューティング”問題1: エージェントが起動しない
Section titled “問題1: エージェントが起動しない”症状: エージェントの結果が返ってこない
原因: エージェントファイルが見つからない
解決:
# ファイルの配置を確認ls -la plugins/my-plugin/agents/
# 名前が正しいか確認cat plugins/my-plugin/agents/my-agent.md | head -5問題2: ツールが使えない
Section titled “問題2: ツールが使えない”症状: “Tool not allowed” エラー
原因: toolsフィールドに含まれていない
解決:
# エージェント定義を確認tools: Glob, Grep, Read # これらのツールのみ使用可能
# 必要なツールを追加tools: Glob, Grep, Read, Edit, Write問題3: 並列実行が遅い
Section titled “問題3: 並列実行が遅い”症状: エージェントが逐次実行されている
原因: プロンプトの書き方
解決:
❌ 悪い例:1. Launch agent 12. Launch agent 23. Launch agent 3
✅ 良い例:Launch 3 agents in parallel:- Agent 1: ...- Agent 2: ...- Agent 3: ...次のステップ
Section titled “次のステップ”- 学習パスガイド - 実践的な学習方法
- プラグインシステム詳解 - システムの詳細仕様