swarm-advanced
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdvanced Swarm Orchestration
高级Swarm编排
Master advanced swarm patterns for distributed research, development, and testing workflows. This skill covers comprehensive orchestration strategies using both MCP tools and CLI commands.
掌握适用于分布式研究、开发和测试工作流的高级Swarm模式。本技能涵盖使用MCP工具和CLI命令的全面编排策略。
Quick Start
快速开始
Prerequisites
前提条件
bash
undefinedbash
undefinedEnsure Claude Flow is installed
确保已安装Claude Flow
npm install -g claude-flow@alpha
npm install -g claude-flow@alpha
Add MCP server (if using MCP tools)
添加MCP服务器(如果使用MCP工具)
claude mcp add claude-flow npx claude-flow@alpha mcp start
undefinedclaude mcp add claude-flow npx claude-flow@alpha mcp start
undefinedBasic Pattern
基础模式
javascript
// 1. Initialize swarm topology
mcp__claude-flow__swarm_init({ topology: "mesh", maxAgents: 6 })
// 2. Spawn specialized agents
mcp__claude-flow__agent_spawn({ type: "researcher", name: "Agent 1" })
// 3. Orchestrate tasks
mcp__claude-flow__task_orchestrate({ task: "...", strategy: "parallel" })javascript
// 1. 初始化Swarm拓扑结构
mcp__claude-flow__swarm_init({ topology: "mesh", maxAgents: 6 })
// 2. 生成专业Agent
mcp__claude-flow__agent_spawn({ type: "researcher", name: "Agent 1" })
// 3. 编排任务
mcp__claude-flow__task_orchestrate({ task: "...", strategy: "parallel" })Core Concepts
核心概念
Swarm Topologies
Swarm拓扑结构
Mesh Topology - Peer-to-peer communication, best for research and analysis
- All agents communicate directly
- High flexibility and resilience
- Use for: Research, analysis, brainstorming
Hierarchical Topology - Coordinator with subordinates, best for development
- Clear command structure
- Sequential workflow support
- Use for: Development, structured workflows
Star Topology - Central coordinator, best for testing
- Centralized control and monitoring
- Parallel execution with coordination
- Use for: Testing, validation, quality assurance
Ring Topology - Sequential processing chain
- Step-by-step processing
- Pipeline workflows
- Use for: Multi-stage processing, data pipelines
Mesh拓扑 - 点对点通信,最适合研究和分析
- 所有Agent直接通信
- 高灵活性和韧性
- 适用场景:研究、分析、头脑风暴
分层拓扑 - 协调者管理下属Agent,最适合开发
- 清晰的命令结构
- 支持顺序工作流
- 适用场景:开发、结构化工作流
星型拓扑 - 中央协调者,最适合测试
- 集中式控制与监控
- 带协调的并行执行
- 适用场景:测试、验证、质量保证
环形拓扑 - 顺序处理链
- 分步处理
- 流水线工作流
- 适用场景:多阶段处理、数据流水线
Agent Strategies
Agent策略
Adaptive - Dynamic adjustment based on task complexity
Balanced - Equal distribution of work across agents
Specialized - Task-specific agent assignment
Parallel - Maximum concurrent execution
自适应 - 根据任务复杂度动态调整
均衡 - 任务在Agent间平均分配
专业化 - 按任务类型分配特定Agent
并行 - 最大并发执行
Pattern 1: Research Swarm
模式1:研究Swarm
Purpose
目标
Deep research through parallel information gathering, analysis, and synthesis.
通过并行信息收集、分析与合成完成深度研究。
Architecture
架构
javascript
// Initialize research swarm
mcp__claude-flow__swarm_init({
"topology": "mesh",
"maxAgents": 6,
"strategy": "adaptive"
})
// Spawn research team
const researchAgents = [
{
type: "researcher",
name: "Web Researcher",
capabilities: ["web-search", "content-extraction", "source-validation"]
},
{
type: "researcher",
name: "Academic Researcher",
capabilities: ["paper-analysis", "citation-tracking", "literature-review"]
},
{
type: "analyst",
name: "Data Analyst",
capabilities: ["data-processing", "statistical-analysis", "visualization"]
},
{
type: "analyst",
name: "Pattern Analyzer",
capabilities: ["trend-detection", "correlation-analysis", "outlier-detection"]
},
{
type: "documenter",
name: "Report Writer",
capabilities: ["synthesis", "technical-writing", "formatting"]
}
]
// Spawn all agents
researchAgents.forEach(agent => {
mcp__claude-flow__agent_spawn({
type: agent.type,
name: agent.name,
capabilities: agent.capabilities
})
})javascript
// 初始化研究Swarm
mcp__claude-flow__swarm_init({
"topology": "mesh",
"maxAgents": 6,
"strategy": "adaptive"
})
// 定义研究团队Agent
const researchAgents = [
{
type: "researcher",
name: "Web研究员",
capabilities: ["web-search", "content-extraction", "source-validation"]
},
{
type: "researcher",
name: "学术研究员",
capabilities: ["paper-analysis", "citation-tracking", "literature-review"]
},
{
type: "analyst",
name: "数据分析师",
capabilities: ["data-processing", "statistical-analysis", "visualization"]
},
{
type: "analyst",
name: "模式分析师",
capabilities: ["trend-detection", "correlation-analysis", "outlier-detection"]
},
{
type: "documenter",
name: "报告撰写者",
capabilities: ["synthesis", "technical-writing", "formatting"]
}
]
// 生成所有Agent
researchAgents.forEach(agent => {
mcp__claude-flow__agent_spawn({
type: agent.type,
name: agent.name,
capabilities: agent.capabilities
})
})Research Workflow
研究工作流
Phase 1: Information Gathering
阶段1:信息收集
javascript
// Parallel information collection
mcp__claude-flow__parallel_execute({
"tasks": [
{
"id": "web-search",
"command": "search recent publications and articles"
},
{
"id": "academic-search",
"command": "search academic databases and papers"
},
{
"id": "data-collection",
"command": "gather relevant datasets and statistics"
},
{
"id": "expert-search",
"command": "identify domain experts and thought leaders"
}
]
})
// Store research findings in memory
mcp__claude-flow__memory_usage({
"action": "store",
"key": "research-findings-" + Date.now(),
"value": JSON.stringify(findings),
"namespace": "research",
"ttl": 604800 // 7 days
})javascript
// 并行信息收集
mcp__claude-flow__parallel_execute({
"tasks": [
{
"id": "web-search",
"command": "搜索近期出版物和文章"
},
{
"id": "academic-search",
"command": "搜索学术数据库和论文"
},
{
"id": "data-collection",
"command": "收集相关数据集和统计数据"
},
{
"id": "expert-search",
"command": "识别领域专家和意见领袖"
}
]
})
// 将研究结果存储到内存
mcp__claude-flow__memory_usage({
"action": "store",
"key": "research-findings-" + Date.now(),
"value": JSON.stringify(findings),
"namespace": "research",
"ttl": 604800 // 7天
})Phase 2: Analysis and Validation
阶段2:分析与验证
javascript
// Pattern recognition in findings
mcp__claude-flow__pattern_recognize({
"data": researchData,
"patterns": ["trend", "correlation", "outlier", "emerging-pattern"]
})
// Cognitive analysis
mcp__claude-flow__cognitive_analyze({
"behavior": "research-synthesis"
})
// Quality assessment
mcp__claude-flow__quality_assess({
"target": "research-sources",
"criteria": ["credibility", "relevance", "recency", "authority"]
})
// Cross-reference validation
mcp__claude-flow__neural_patterns({
"action": "analyze",
"operation": "fact-checking",
"metadata": { "sources": sourcesArray }
})javascript
// 识别研究结果中的模式
mcp__claude-flow__pattern_recognize({
"data": researchData,
"patterns": ["trend", "correlation", "outlier", "emerging-pattern"]
})
// 认知分析
mcp__claude-flow__cognitive_analyze({
"behavior": "research-synthesis"
})
// 质量评估
mcp__claude-flow__quality_assess({
"target": "research-sources",
"criteria": ["credibility", "relevance", "recency", "authority"]
})
// 交叉引用验证
mcp__claude-flow__neural_patterns({
"action": "analyze",
"operation": "fact-checking",
"metadata": { "sources": sourcesArray }
})Phase 3: Knowledge Management
阶段3:知识管理
javascript
// Search existing knowledge base
mcp__claude-flow__memory_search({
"pattern": "topic X",
"namespace": "research",
"limit": 20
})
// Create knowledge graph connections
mcp__claude-flow__neural_patterns({
"action": "learn",
"operation": "knowledge-graph",
"metadata": {
"topic": "X",
"connections": relatedTopics,
"depth": 3
}
})
// Store connections for future use
mcp__claude-flow__memory_usage({
"action": "store",
"key": "knowledge-graph-X",
"value": JSON.stringify(knowledgeGraph),
"namespace": "research$graphs",
"ttl": 2592000 // 30 days
})javascript
// 搜索现有知识库
mcp__claude-flow__memory_search({
"pattern": "主题X",
"namespace": "research",
"limit": 20
})
// 创建知识图谱关联
mcp__claude-flow__neural_patterns({
"action": "learn",
"operation": "knowledge-graph",
"metadata": {
"topic": "X",
"connections": relatedTopics,
"depth": 3
}
})
// 存储关联供未来使用
mcp__claude-flow__memory_usage({
"action": "store",
"key": "knowledge-graph-X",
"value": JSON.stringify(knowledgeGraph),
"namespace": "research$graphs",
"ttl": 2592000 // 30天
})Phase 4: Report Generation
阶段4:报告生成
javascript
// Orchestrate report generation
mcp__claude-flow__task_orchestrate({
"task": "generate comprehensive research report",
"strategy": "sequential",
"priority": "high",
"dependencies": ["gather", "analyze", "validate", "synthesize"]
})
// Monitor research progress
mcp__claude-flow__swarm_status({
"swarmId": "research-swarm"
})
// Generate final report
mcp__claude-flow__workflow_execute({
"workflowId": "research-report-generation",
"params": {
"findings": findings,
"format": "comprehensive",
"sections": ["executive-summary", "methodology", "findings", "analysis", "conclusions", "references"]
}
})javascript
// 编排报告生成任务
mcp__claude-flow__task_orchestrate({
"task": "生成全面的研究报告",
"strategy": "sequential",
"priority": "high",
"dependencies": ["gather", "analyze", "validate", "synthesize"]
})
// 监控研究进度
mcp__claude-flow__swarm_status({
"swarmId": "research-swarm"
})
// 生成最终报告
mcp__claude-flow__workflow_execute({
"workflowId": "research-report-generation",
"params": {
"findings": findings,
"format": "comprehensive",
"sections": ["executive-summary", "methodology", "findings", "analysis", "conclusions", "references"]
}
})CLI Fallback
CLI备选方案
bash
undefinedbash
undefinedQuick research swarm
快速启动研究Swarm
npx claude-flow swarm "research AI trends in 2025"
--strategy research
--mode distributed
--max-agents 6
--parallel
--output research-report.md
--strategy research
--mode distributed
--max-agents 6
--parallel
--output research-report.md
undefinednpx claude-flow swarm "research AI trends in 2025"
--strategy research
--mode distributed
--max-agents 6
--parallel
--output research-report.md
--strategy research
--mode distributed
--max-agents 6
--parallel
--output research-report.md
undefinedPattern 2: Development Swarm
模式2:开发Swarm
Purpose
目标
Full-stack development through coordinated specialist agents.
通过协同的专业Agent完成全栈开发。
Architecture
架构
javascript
// Initialize development swarm with hierarchy
mcp__claude-flow__swarm_init({
"topology": "hierarchical",
"maxAgents": 8,
"strategy": "balanced"
})
// Spawn development team
const devTeam = [
{ type: "architect", name: "System Architect", role: "coordinator" },
{ type: "coder", name: "Backend Developer", capabilities: ["node", "api", "database"] },
{ type: "coder", name: "Frontend Developer", capabilities: ["react", "ui", "ux"] },
{ type: "coder", name: "Database Engineer", capabilities: ["sql", "nosql", "optimization"] },
{ type: "tester", name: "QA Engineer", capabilities: ["unit", "integration", "e2e"] },
{ type: "reviewer", name: "Code Reviewer", capabilities: ["security", "performance", "best-practices"] },
{ type: "documenter", name: "Technical Writer", capabilities: ["api-docs", "guides", "tutorials"] },
{ type: "monitor", name: "DevOps Engineer", capabilities: ["ci-cd", "deployment", "monitoring"] }
]
// Spawn all team members
devTeam.forEach(member => {
mcp__claude-flow__agent_spawn({
type: member.type,
name: member.name,
capabilities: member.capabilities,
swarmId: "dev-swarm"
})
})javascript
// 初始化分层结构的开发Swarm
mcp__claude-flow__swarm_init({
"topology": "hierarchical",
"maxAgents": 8,
"strategy": "balanced"
})
// 定义开发团队Agent
const devTeam = [
{ type: "architect", name: "系统架构师", role: "coordinator" },
{ type: "coder", name: "后端开发者", capabilities: ["node", "api", "database"] },
{ type: "coder", name: "前端开发者", capabilities: ["react", "ui", "ux"] },
{ type: "coder", name: "数据库工程师", capabilities: ["sql", "nosql", "optimization"] },
{ type: "tester", name: "QA工程师", capabilities: ["unit", "integration", "e2e"] },
{ type: "reviewer", name: "代码审核者", capabilities: ["security", "performance", "best-practices"] },
{ type: "documenter", name: "技术文档撰写者", capabilities: ["api-docs", "guides", "tutorials"] },
{ type: "monitor", name: "DevOps工程师", capabilities: ["ci-cd", "deployment", "monitoring"] }
]
// 生成所有团队成员Agent
devTeam.forEach(member => {
mcp__claude-flow__agent_spawn({
type: member.type,
name: member.name,
capabilities: member.capabilities,
swarmId: "dev-swarm"
})
})Development Workflow
开发工作流
Phase 1: Architecture and Design
阶段1:架构与设计
javascript
// System architecture design
mcp__claude-flow__task_orchestrate({
"task": "design system architecture for REST API",
"strategy": "sequential",
"priority": "critical",
"assignTo": "System Architect"
})
// Store architecture decisions
mcp__claude-flow__memory_usage({
"action": "store",
"key": "architecture-decisions",
"value": JSON.stringify(architectureDoc),
"namespace": "development$design"
})javascript
// 系统架构设计
mcp__claude-flow__task_orchestrate({
"task": "为REST API设计系统架构",
"strategy": "sequential",
"priority": "critical",
"assignTo": "系统架构师"
})
// 存储架构决策
mcp__claude-flow__memory_usage({
"action": "store",
"key": "architecture-decisions",
"value": JSON.stringify(architectureDoc),
"namespace": "development$design"
})Phase 2: Parallel Implementation
阶段2:并行实现
javascript
// Parallel development tasks
mcp__claude-flow__parallel_execute({
"tasks": [
{
"id": "backend-api",
"command": "implement REST API endpoints",
"assignTo": "Backend Developer"
},
{
"id": "frontend-ui",
"command": "build user interface components",
"assignTo": "Frontend Developer"
},
{
"id": "database-schema",
"command": "design and implement database schema",
"assignTo": "Database Engineer"
},
{
"id": "api-documentation",
"command": "create API documentation",
"assignTo": "Technical Writer"
}
]
})
// Monitor development progress
mcp__claude-flow__swarm_monitor({
"swarmId": "dev-swarm",
"interval": 5000
})javascript
// 并行开发任务
mcp__claude-flow__parallel_execute({
"tasks": [
{
"id": "backend-api",
"command": "实现REST API端点",
"assignTo": "后端开发者"
},
{
"id": "frontend-ui",
"command": "构建用户界面组件",
"assignTo": "前端开发者"
},
{
"id": "database-schema",
"command": "设计并实现数据库架构",
"assignTo": "数据库工程师"
},
{
"id": "api-documentation",
"command": "创建API文档",
"assignTo": "技术文档撰写者"
}
]
})
// 监控开发进度
mcp__claude-flow__swarm_monitor({
"swarmId": "dev-swarm",
"interval": 5000
})Phase 3: Testing and Validation
阶段3:测试与验证
javascript
// Comprehensive testing
mcp__claude-flow__batch_process({
"items": [
{ type: "unit", target: "all-modules" },
{ type: "integration", target: "api-endpoints" },
{ type: "e2e", target: "user-flows" },
{ type: "performance", target: "critical-paths" }
],
"operation": "execute-tests"
})
// Quality assessment
mcp__claude-flow__quality_assess({
"target": "codebase",
"criteria": ["coverage", "complexity", "maintainability", "security"]
})javascript
// 全面测试
mcp__claude-flow__batch_process({
"items": [
{ type: "unit", target: "all-modules" },
{ type: "integration", target: "api-endpoints" },
{ type: "e2e", target: "user-flows" },
{ type: "performance", target: "critical-paths" }
],
"operation": "execute-tests"
})
// 质量评估
mcp__claude-flow__quality_assess({
"target": "codebase",
"criteria": ["coverage", "complexity", "maintainability", "security"]
})Phase 4: Review and Deployment
阶段4:审核与部署
javascript
// Code review workflow
mcp__claude-flow__workflow_execute({
"workflowId": "code-review-process",
"params": {
"reviewers": ["Code Reviewer"],
"criteria": ["security", "performance", "best-practices"]
}
})
// CI/CD pipeline
mcp__claude-flow__pipeline_create({
"config": {
"stages": ["build", "test", "security-scan", "deploy"],
"environment": "production"
}
})javascript
// 代码审核工作流
mcp__claude-flow__workflow_execute({
"workflowId": "code-review-process",
"params": {
"reviewers": ["代码审核者"],
"criteria": ["security", "performance", "best-practices"]
}
})
// CI/CD流水线
mcp__claude-flow__pipeline_create({
"config": {
"stages": ["build", "test", "security-scan", "deploy"],
"environment": "production"
}
})CLI Fallback
CLI备选方案
bash
undefinedbash
undefinedQuick development swarm
快速启动开发Swarm
npx claude-flow swarm "build REST API with authentication"
--strategy development
--mode hierarchical
--monitor
--output sqlite
--strategy development
--mode hierarchical
--monitor
--output sqlite
undefinednpx claude-flow swarm "build REST API with authentication"
--strategy development
--mode hierarchical
--monitor
--output sqlite
--strategy development
--mode hierarchical
--monitor
--output sqlite
undefinedPattern 3: Testing Swarm
模式3:测试Swarm
Purpose
目标
Comprehensive quality assurance through distributed testing.
通过分布式测试完成全面质量保证。
Architecture
架构
javascript
// Initialize testing swarm with star topology
mcp__claude-flow__swarm_init({
"topology": "star",
"maxAgents": 7,
"strategy": "parallel"
})
// Spawn testing team
const testingTeam = [
{
type: "tester",
name: "Unit Test Coordinator",
capabilities: ["unit-testing", "mocking", "coverage", "tdd"]
},
{
type: "tester",
name: "Integration Tester",
capabilities: ["integration", "api-testing", "contract-testing"]
},
{
type: "tester",
name: "E2E Tester",
capabilities: ["e2e", "ui-testing", "user-flows", "selenium"]
},
{
type: "tester",
name: "Performance Tester",
capabilities: ["load-testing", "stress-testing", "benchmarking"]
},
{
type: "monitor",
name: "Security Tester",
capabilities: ["security-testing", "penetration-testing", "vulnerability-scanning"]
},
{
type: "analyst",
name: "Test Analyst",
capabilities: ["coverage-analysis", "test-optimization", "reporting"]
},
{
type: "documenter",
name: "Test Documenter",
capabilities: ["test-documentation", "test-plans", "reports"]
}
]
// Spawn all testers
testingTeam.forEach(tester => {
mcp__claude-flow__agent_spawn({
type: tester.type,
name: tester.name,
capabilities: tester.capabilities,
swarmId: "testing-swarm"
})
})javascript
// 初始化星型结构的测试Swarm
mcp__claude-flow__swarm_init({
"topology": "star",
"maxAgents": 7,
"strategy": "parallel"
})
// 定义测试团队Agent
const testingTeam = [
{
type: "tester",
name: "单元测试协调者",
capabilities: ["unit-testing", "mocking", "coverage", "tdd"]
},
{
type: "tester",
name: "集成测试工程师",
capabilities: ["integration", "api-testing", "contract-testing"]
},
{
type: "tester",
name: "E2E测试工程师",
capabilities: ["e2e", "ui-testing", "user-flows", "selenium"]
},
{
type: "tester",
name: "性能测试工程师",
capabilities: ["load-testing", "stress-testing", "benchmarking"]
},
{
type: "monitor",
name: "安全测试工程师",
capabilities: ["security-testing", "penetration-testing", "vulnerability-scanning"]
},
{
type: "analyst",
name: "测试分析师",
capabilities: ["coverage-analysis", "test-optimization", "reporting"]
},
{
type: "documenter",
name: "测试文档撰写者",
capabilities: ["test-documentation", "test-plans", "reports"]
}
]
// 生成所有测试Agent
testingTeam.forEach(tester => {
mcp__claude-flow__agent_spawn({
type: tester.type,
name: tester.name,
capabilities: tester.capabilities,
swarmId: "testing-swarm"
})
})Testing Workflow
测试工作流
Phase 1: Test Planning
阶段1:测试规划
javascript
// Analyze test coverage requirements
mcp__claude-flow__quality_assess({
"target": "test-coverage",
"criteria": [
"line-coverage",
"branch-coverage",
"function-coverage",
"edge-cases"
]
})
// Identify test scenarios
mcp__claude-flow__pattern_recognize({
"data": testScenarios,
"patterns": [
"edge-case",
"boundary-condition",
"error-path",
"happy-path"
]
})
// Store test plan
mcp__claude-flow__memory_usage({
"action": "store",
"key": "test-plan-" + Date.now(),
"value": JSON.stringify(testPlan),
"namespace": "testing$plans"
})javascript
// 分析测试覆盖率要求
mcp__claude-flow__quality_assess({
"target": "test-coverage",
"criteria": [
"line-coverage",
"branch-coverage",
"function-coverage",
"edge-cases"
]
})
// 识别测试场景
mcp__claude-flow__pattern_recognize({
"data": testScenarios,
"patterns": [
"edge-case",
"boundary-condition",
"error-path",
"happy-path"
]
})
// 存储测试计划
mcp__claude-flow__memory_usage({
"action": "store",
"key": "test-plan-" + Date.now(),
"value": JSON.stringify(testPlan),
"namespace": "testing$plans"
})Phase 2: Parallel Test Execution
阶段2:并行测试执行
javascript
// Execute all test suites in parallel
mcp__claude-flow__parallel_execute({
"tasks": [
{
"id": "unit-tests",
"command": "npm run test:unit",
"assignTo": "Unit Test Coordinator"
},
{
"id": "integration-tests",
"command": "npm run test:integration",
"assignTo": "Integration Tester"
},
{
"id": "e2e-tests",
"command": "npm run test:e2e",
"assignTo": "E2E Tester"
},
{
"id": "performance-tests",
"command": "npm run test:performance",
"assignTo": "Performance Tester"
},
{
"id": "security-tests",
"command": "npm run test:security",
"assignTo": "Security Tester"
}
]
})
// Batch process test suites
mcp__claude-flow__batch_process({
"items": testSuites,
"operation": "execute-test-suite"
})javascript
// 并行执行所有测试套件
mcp__claude-flow__parallel_execute({
"tasks": [
{
"id": "unit-tests",
"command": "npm run test:unit",
"assignTo": "单元测试协调者"
},
{
"id": "integration-tests",
"command": "npm run test:integration",
"assignTo": "集成测试工程师"
},
{
"id": "e2e-tests",
"command": "npm run test:e2e",
"assignTo": "E2E测试工程师"
},
{
"id": "performance-tests",
"command": "npm run test:performance",
"assignTo": "性能测试工程师"
},
{
"id": "security-tests",
"command": "npm run test:security",
"assignTo": "安全测试工程师"
}
]
})
// 批量处理测试套件
mcp__claude-flow__batch_process({
"items": testSuites,
"operation": "execute-test-suite"
})Phase 3: Performance and Security
阶段3:性能与安全
javascript
// Run performance benchmarks
mcp__claude-flow__benchmark_run({
"suite": "comprehensive-performance"
})
// Bottleneck analysis
mcp__claude-flow__bottleneck_analyze({
"component": "application",
"metrics": ["response-time", "throughput", "memory", "cpu"]
})
// Security scanning
mcp__claude-flow__security_scan({
"target": "application",
"depth": "comprehensive"
})
// Vulnerability analysis
mcp__claude-flow__error_analysis({
"logs": securityScanLogs
})javascript
// 运行性能基准测试
mcp__claude-flow__benchmark_run({
"suite": "comprehensive-performance"
})
// 瓶颈分析
mcp__claude-flow__bottleneck_analyze({
"component": "application",
"metrics": ["response-time", "throughput", "memory", "cpu"]
})
// 安全扫描
mcp__claude-flow__security_scan({
"target": "application",
"depth": "comprehensive"
})
// 漏洞分析
mcp__claude-flow__error_analysis({
"logs": securityScanLogs
})Phase 4: Monitoring and Reporting
阶段4:监控与报告
javascript
// Real-time test monitoring
mcp__claude-flow__swarm_monitor({
"swarmId": "testing-swarm",
"interval": 2000
})
// Generate comprehensive test report
mcp__claude-flow__performance_report({
"format": "detailed",
"timeframe": "current-run"
})
// Get test results
mcp__claude-flow__task_results({
"taskId": "test-execution-001"
})
// Trend analysis
mcp__claude-flow__trend_analysis({
"metric": "test-coverage",
"period": "30d"
})javascript
// 实时测试监控
mcp__claude-flow__swarm_monitor({
"swarmId": "testing-swarm",
"interval": 2000
})
// 生成全面的测试报告
mcp__claude-flow__performance_report({
"format": "detailed",
"timeframe": "current-run"
})
// 获取测试结果
mcp__claude-flow__task_results({
"taskId": "test-execution-001"
})
// 趋势分析
mcp__claude-flow__trend_analysis({
"metric": "test-coverage",
"period": "30d"
})CLI Fallback
CLI备选方案
bash
undefinedbash
undefinedQuick testing swarm
快速启动测试Swarm
npx claude-flow swarm "test application comprehensively"
--strategy testing
--mode star
--parallel
--timeout 600
--strategy testing
--mode star
--parallel
--timeout 600
undefinednpx claude-flow swarm "test application comprehensively"
--strategy testing
--mode star
--parallel
--timeout 600
--strategy testing
--mode star
--parallel
--timeout 600
undefinedPattern 4: Analysis Swarm
模式4:分析Swarm
Purpose
目标
Deep code and system analysis through specialized analyzers.
通过专业分析Agent完成深度代码与系统分析。
Architecture
架构
javascript
// Initialize analysis swarm
mcp__claude-flow__swarm_init({
"topology": "mesh",
"maxAgents": 5,
"strategy": "adaptive"
})
// Spawn analysis specialists
const analysisTeam = [
{
type: "analyst",
name: "Code Analyzer",
capabilities: ["static-analysis", "complexity-analysis", "dead-code-detection"]
},
{
type: "analyst",
name: "Security Analyzer",
capabilities: ["security-scan", "vulnerability-detection", "dependency-audit"]
},
{
type: "analyst",
name: "Performance Analyzer",
capabilities: ["profiling", "bottleneck-detection", "optimization"]
},
{
type: "analyst",
name: "Architecture Analyzer",
capabilities: ["dependency-analysis", "coupling-detection", "modularity-assessment"]
},
{
type: "documenter",
name: "Analysis Reporter",
capabilities: ["reporting", "visualization", "recommendations"]
}
]
// Spawn all analysts
analysisTeam.forEach(analyst => {
mcp__claude-flow__agent_spawn({
type: analyst.type,
name: analyst.name,
capabilities: analyst.capabilities
})
})javascript
// 初始化分析Swarm
mcp__claude-flow__swarm_init({
"topology": "mesh",
"maxAgents": 5,
"strategy": "adaptive"
})
// 定义分析专业Agent
const analysisTeam = [
{
type: "analyst",
name: "代码分析师",
capabilities: ["static-analysis", "complexity-analysis", "dead-code-detection"]
},
{
type: "analyst",
name: "安全分析师",
capabilities: ["security-scan", "vulnerability-detection", "dependency-audit"]
},
{
type: "analyst",
name: "性能分析师",
capabilities: ["profiling", "bottleneck-detection", "optimization"]
},
{
type: "analyst",
name: "架构分析师",
capabilities: ["dependency-analysis", "coupling-detection", "modularity-assessment"]
},
{
type: "documenter",
name: "分析报告撰写者",
capabilities: ["reporting", "visualization", "recommendations"]
}
]
// 生成所有分析Agent
analysisTeam.forEach(analyst => {
mcp__claude-flow__agent_spawn({
type: analyst.type,
name: analyst.name,
capabilities: analyst.capabilities
})
})Analysis Workflow
分析工作流
javascript
// Parallel analysis execution
mcp__claude-flow__parallel_execute({
"tasks": [
{ "id": "analyze-code", "command": "analyze codebase structure and quality" },
{ "id": "analyze-security", "command": "scan for security vulnerabilities" },
{ "id": "analyze-performance", "command": "identify performance bottlenecks" },
{ "id": "analyze-architecture", "command": "assess architectural patterns" }
]
})
// Generate comprehensive analysis report
mcp__claude-flow__performance_report({
"format": "detailed",
"timeframe": "current"
})
// Cost analysis
mcp__claude-flow__cost_analysis({
"timeframe": "30d"
})javascript
// 并行执行分析任务
mcp__claude-flow__parallel_execute({
"tasks": [
{ "id": "analyze-code", "command": "分析代码库结构与质量" },
{ "id": "analyze-security", "command": "扫描安全漏洞" },
{ "id": "analyze-performance", "command": "识别性能瓶颈" },
{ "id": "analyze-architecture", "command": "评估架构模式" }
]
})
// 生成全面的分析报告
mcp__claude-flow__performance_report({
"format": "detailed",
"timeframe": "current"
})
// 成本分析
mcp__claude-flow__cost_analysis({
"timeframe": "30d"
})Advanced Techniques
高级技术
Error Handling and Fault Tolerance
错误处理与容错
javascript
// Setup fault tolerance for all agents
mcp__claude-flow__daa_fault_tolerance({
"agentId": "all",
"strategy": "auto-recovery"
})
// Error handling pattern
try {
await mcp__claude-flow__task_orchestrate({
"task": "complex operation",
"strategy": "parallel",
"priority": "high"
})
} catch (error) {
// Check swarm health
const status = await mcp__claude-flow__swarm_status({})
// Analyze error patterns
await mcp__claude-flow__error_analysis({
"logs": [error.message]
})
// Auto-recovery attempt
if (status.healthy) {
await mcp__claude-flow__task_orchestrate({
"task": "retry failed operation",
"strategy": "sequential"
})
}
}javascript
// 为所有Agent设置容错机制
mcp__claude-flow__daa_fault_tolerance({
"agentId": "all",
"strategy": "auto-recovery"
})
// 错误处理模式
try {
await mcp__claude-flow__task_orchestrate({
"task": "复杂操作",
"strategy": "parallel",
"priority": "high"
})
} catch (error) {
// 检查Swarm健康状态
const status = await mcp__claude-flow__swarm_status({})
// 分析错误模式
await mcp__claude-flow__error_analysis({
"logs": [error.message]
})
// 尝试自动恢复
if (status.healthy) {
await mcp__claude-flow__task_orchestrate({
"task": "重试失败的操作",
"strategy": "sequential"
})
}
}Memory and State Management
内存与状态管理
javascript
// Cross-session persistence
mcp__claude-flow__memory_persist({
"sessionId": "swarm-session-001"
})
// Namespace management for different swarms
mcp__claude-flow__memory_namespace({
"namespace": "research-swarm",
"action": "create"
})
// Create state snapshot
mcp__claude-flow__state_snapshot({
"name": "development-checkpoint-1"
})
// Restore from snapshot if needed
mcp__claude-flow__context_restore({
"snapshotId": "development-checkpoint-1"
})
// Backup memory stores
mcp__claude-flow__memory_backup({
"path": "$workspaces$claude-code-flow$backups$swarm-memory.json"
})javascript
// 跨会话持久化
mcp__claude-flow__memory_persist({
"sessionId": "swarm-session-001"
})
// 为不同Swarm管理命名空间
mcp__claude-flow__memory_namespace({
"namespace": "research-swarm",
"action": "create"
})
// 创建状态快照
mcp__claude-flow__state_snapshot({
"name": "development-checkpoint-1"
})
// 必要时从快照恢复
mcp__claude-flow__context_restore({
"snapshotId": "development-checkpoint-1"
})
// 备份内存存储
mcp__claude-flow__memory_backup({
"path": "$workspaces$claude-code-flow$backups$swarm-memory.json"
})Neural Pattern Learning
神经模式学习
javascript
// Train neural patterns from successful workflows
mcp__claude-flow__neural_train({
"pattern_type": "coordination",
"training_data": JSON.stringify(successfulWorkflows),
"epochs": 50
})
// Adaptive learning from experience
mcp__claude-flow__learning_adapt({
"experience": {
"workflow": "research-to-report",
"success": true,
"duration": 3600,
"quality": 0.95
}
})
// Pattern recognition for optimization
mcp__claude-flow__pattern_recognize({
"data": workflowMetrics,
"patterns": ["bottleneck", "optimization-opportunity", "efficiency-gain"]
})javascript
// 从成功工作流中训练神经模式
mcp__claude-flow__neural_train({
"pattern_type": "coordination",
"training_data": JSON.stringify(successfulWorkflows),
"epochs": 50
})
// 从经验中自适应学习
mcp__claude-flow__learning_adapt({
"experience": {
"workflow": "research-to-report",
"success": true,
"duration": 3600,
"quality": 0.95
}
})
// 模式识别以优化
mcp__claude-flow__pattern_recognize({
"data": workflowMetrics,
"patterns": ["bottleneck", "optimization-opportunity", "efficiency-gain"]
})Workflow Automation
工作流自动化
javascript
// Create reusable workflow
mcp__claude-flow__workflow_create({
"name": "full-stack-development",
"steps": [
{ "phase": "design", "agents": ["architect"] },
{ "phase": "implement", "agents": ["backend-dev", "frontend-dev"], "parallel": true },
{ "phase": "test", "agents": ["tester", "security-tester"], "parallel": true },
{ "phase": "review", "agents": ["reviewer"] },
{ "phase": "deploy", "agents": ["devops"] }
],
"triggers": ["on-commit", "scheduled-daily"]
})
// Setup automation rules
mcp__claude-flow__automation_setup({
"rules": [
{
"trigger": "file-changed",
"pattern": "*.js",
"action": "run-tests"
},
{
"trigger": "PR-created",
"action": "code-review-swarm"
}
]
})
// Event-driven triggers
mcp__claude-flow__trigger_setup({
"events": ["code-commit", "PR-merge", "deployment"],
"actions": ["test", "analyze", "document"]
})javascript
// 创建可复用工作流
mcp__claude-flow__workflow_create({
"name": "full-stack-development",
"steps": [
{ "phase": "design", "agents": ["architect"] },
{ "phase": "implement", "agents": ["backend-dev", "frontend-dev"], "parallel": true },
{ "phase": "test", "agents": ["tester", "security-tester"], "parallel": true },
{ "phase": "review", "agents": ["reviewer"] },
{ "phase": "deploy", "agents": ["devops"] }
],
"triggers": ["on-commit", "scheduled-daily"]
})
// 设置自动化规则
mcp__claude-flow__automation_setup({
"rules": [
{
"trigger": "file-changed",
"pattern": "*.js",
"action": "run-tests"
},
{
"trigger": "PR-created",
"action": "code-review-swarm"
}
]
})
// 事件驱动触发器
mcp__claude-flow__trigger_setup({
"events": ["code-commit", "PR-merge", "deployment"],
"actions": ["test", "analyze", "document"]
})Performance Optimization
性能优化
javascript
// Topology optimization
mcp__claude-flow__topology_optimize({
"swarmId": "current-swarm"
})
// Load balancing
mcp__claude-flow__load_balance({
"swarmId": "development-swarm",
"tasks": taskQueue
})
// Agent coordination sync
mcp__claude-flow__coordination_sync({
"swarmId": "development-swarm"
})
// Auto-scaling
mcp__claude-flow__swarm_scale({
"swarmId": "development-swarm",
"targetSize": 12
})javascript
// 拓扑优化
mcp__claude-flow__topology_optimize({
"swarmId": "current-swarm"
})
// 负载均衡
mcp__claude-flow__load_balance({
"swarmId": "development-swarm",
"tasks": taskQueue
})
// Agent协同同步
mcp__claude-flow__coordination_sync({
"swarmId": "development-swarm"
})
// 自动扩容
mcp__claude-flow__swarm_scale({
"swarmId": "development-swarm",
"targetSize": 12
})Monitoring and Metrics
监控与指标
javascript
// Real-time swarm monitoring
mcp__claude-flow__swarm_monitor({
"swarmId": "active-swarm",
"interval": 3000
})
// Collect comprehensive metrics
mcp__claude-flow__metrics_collect({
"components": ["agents", "tasks", "memory", "performance"]
})
// Health monitoring
mcp__claude-flow__health_check({
"components": ["swarm", "agents", "neural", "memory"]
})
// Usage statistics
mcp__claude-flow__usage_stats({
"component": "swarm-orchestration"
})
// Trend analysis
mcp__claude-flow__trend_analysis({
"metric": "agent-performance",
"period": "7d"
})javascript
// 实时Swarm监控
mcp__claude-flow__swarm_monitor({
"swarmId": "active-swarm",
"interval": 3000
})
// 收集全面指标
mcp__claude-flow__metrics_collect({
"components": ["agents", "tasks", "memory", "performance"]
})
// 健康监控
mcp__claude-flow__health_check({
"components": ["swarm", "agents", "neural", "memory"]
})
// 使用统计
mcp__claude-flow__usage_stats({
"component": "swarm-orchestration"
})
// 趋势分析
mcp__claude-flow__trend_analysis({
"metric": "agent-performance",
"period": "7d"
})Best Practices
最佳实践
1. Choosing the Right Topology
1. 选择合适的拓扑结构
- Mesh: Research, brainstorming, collaborative analysis
- Hierarchical: Structured development, sequential workflows
- Star: Testing, validation, centralized coordination
- Ring: Pipeline processing, staged workflows
- Mesh:研究、头脑风暴、协作分析
- Hierarchical:结构化开发、顺序工作流
- Star:测试、验证、集中式协调
- Ring:流水线处理、阶段式工作流
2. Agent Specialization
2. Agent专业化
- Assign specific capabilities to each agent
- Avoid overlapping responsibilities
- Use coordination agents for complex workflows
- Leverage memory for agent communication
- 为每个Agent分配特定能力
- 避免职责重叠
- 复杂工作流使用协调Agent
- 利用内存实现Agent间通信
3. Parallel Execution
3. 并行执行
- Identify independent tasks for parallelization
- Use sequential execution for dependent tasks
- Monitor resource usage during parallel execution
- Implement proper error handling
- 识别可并行的独立任务
- 依赖任务使用顺序执行
- 并行执行时监控资源使用
- 实现完善的错误处理
4. Memory Management
4. 内存管理
- Use namespaces to organize memory
- Set appropriate TTL values
- Create regular backups
- Implement state snapshots for checkpoints
- 使用命名空间组织内存
- 设置合适的TTL值
- 定期创建备份
- 实现状态快照作为检查点
5. Monitoring and Optimization
5. 监控与优化
- Monitor swarm health regularly
- Collect and analyze metrics
- Optimize topology based on performance
- Use neural patterns to learn from success
- 定期监控Swarm健康状态
- 收集并分析指标
- 根据性能优化拓扑结构
- 使用神经模式从成功经验中学习
6. Error Recovery
6. 错误恢复
- Implement fault tolerance strategies
- Use auto-recovery mechanisms
- Analyze error patterns
- Create fallback workflows
- 实现容错策略
- 使用自动恢复机制
- 分析错误模式
- 创建备选工作流
Real-World Examples
真实场景示例
Example 1: AI Research Project
示例1:AI研究项目
javascript
// Research AI trends, analyze findings, generate report
mcp__claude-flow__swarm_init({ topology: "mesh", maxAgents: 6 })
// Spawn: 2 researchers, 2 analysts, 1 synthesizer, 1 documenter
// Parallel gather → Analyze patterns → Synthesize → Reportjavascript
// 研究AI趋势、分析结果、生成报告
mcp__claude-flow__swarm_init({ topology: "mesh", maxAgents: 6 })
// 生成:2名研究员、2名分析师、1名合成师、1名文档撰写者
// 并行收集 → 模式分析 → 合成 → 报告Example 2: Full-Stack Application
示例2:全栈应用
javascript
// Build complete web application with testing
mcp__claude-flow__swarm_init({ topology: "hierarchical", maxAgents: 8 })
// Spawn: 1 architect, 2 devs, 1 db engineer, 2 testers, 1 reviewer, 1 devops
// Design → Parallel implement → Test → Review → Deployjavascript
// 构建带测试的完整Web应用
mcp__claude-flow__swarm_init({ topology: "hierarchical", maxAgents: 8 })
// 生成:1名架构师、2名开发者、1名数据库工程师、2名测试员、1名审核者、1名DevOps
// 设计 → 并行实现 → 测试 → 审核 → 部署Example 3: Security Audit
示例3:安全审计
javascript
// Comprehensive security analysis
mcp__claude-flow__swarm_init({ topology: "star", maxAgents: 5 })
// Spawn: 1 coordinator, 1 code analyzer, 1 security scanner, 1 penetration tester, 1 reporter
// Parallel scan → Vulnerability analysis → Penetration test → Reportjavascript
// 全面安全分析
mcp__claude-flow__swarm_init({ topology: "star", maxAgents: 5 })
// 生成:1名协调者、1名代码分析师、1名安全扫描者、1名渗透测试者、1名报告者
// 并行扫描 → 漏洞分析 → 渗透测试 → 报告Example 4: Performance Optimization
示例4:性能优化
javascript
// Identify and fix performance bottlenecks
mcp__claude-flow__swarm_init({ topology: "mesh", maxAgents: 4 })
// Spawn: 1 profiler, 1 bottleneck analyzer, 1 optimizer, 1 tester
// Profile → Identify bottlenecks → Optimize → Validatejavascript
// 识别并修复性能瓶颈
mcp__claude-flow__swarm_init({ topology: "mesh", maxAgents: 4 })
// 生成:1名性能分析者、1名瓶颈分析师、1名优化者、1名测试者
// 性能分析 → 识别瓶颈 → 优化 → 验证Troubleshooting
故障排除
Common Issues
常见问题
Issue: Swarm agents not coordinating properly
Solution: Check topology selection, verify memory usage, enable monitoring
Issue: Parallel execution failing
Solution: Verify task dependencies, check resource limits, implement error handling
Issue: Memory persistence not working
Solution: Verify namespaces, check TTL settings, ensure backup configuration
Issue: Performance degradation
Solution: Optimize topology, reduce agent count, analyze bottlenecks
问题:Swarm Agent协同异常
解决方案:检查拓扑结构选择、验证内存使用、启用监控
问题:并行执行失败
解决方案:验证任务依赖、检查资源限制、实现错误处理
问题:内存持久化失效
解决方案:验证命名空间、检查TTL设置、确保备份配置正确
问题:性能下降
解决方案:优化拓扑结构、减少Agent数量、分析瓶颈
Related Skills
相关技能
- - Systematic development workflow
sparc-methodology - - Repository management and automation
github-integration - - AI-powered coordination optimization
neural-patterns - - Cross-session state persistence
memory-management
- - 系统化开发工作流
sparc-methodology - - 仓库管理与自动化
github-integration - - AI驱动的协同优化
neural-patterns - - 跨会话状态持久化
memory-management
References
参考资料
Version: 2.0.0
Last Updated: 2025-10-19
Skill Level: Advanced
Estimated Learning Time: 2-3 hours