关于 Swarm Orchestration
Swarm Orchestration 是用于协调多 Agent swarm 的 agentic-flow 技能,支持网状、层级和自适应拓扑,并提供并行或依赖式任务执行、共享记忆、负载均衡与故障处理。
主要功能
- 01网状、层级和自适应拓扑
- 02并行与流水线任务执行
- 03自动分配任务和负载均衡
- 04swarm 共享记忆
- 05重试与任务重新分配
- 06swarm 性能指标
适用场景
- 01将 API 实现拆分给多个 Agent
- 02按顺序执行设计、实现、测试和审查
- 03在 Agent 间共享架构与状态
- 04Agent 发生故障后重新分配工作
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ proffesor-for-testing/ agentic-qe --skill swarm-orchestration安装后在 Claude Code 中输入/swarm-orchestration确认已加载。
详细介绍
Swarm 编排
此技能的作用
使用 agentic-flow 的高级协调系统编排多 Agent 集群。支持网状、分层和自适应拓扑,并具备自动任务分配、负载均衡和容错能力。
前置条件
- agentic-flow v1.5.11+
- Node.js 18+
- 了解分布式系统(有帮助)
快速开始
# Initialize swarm
npx agentic-flow hooks swarm-init --topology mesh --max-agents 5
# Spawn agents
npx agentic-flow hooks agent-spawn --type coder
npx agentic-flow hooks agent-spawn --type tester
npx agentic-flow hooks agent-spawn --type reviewer
# Orchestrate task
npx agentic-flow hooks task-orchestrate \
--task "Build REST API with tests" \
--mode parallel
拓扑模式
1. 网状(点对点)
// Equal peers, distributed decision-making
await swarm.init({
topology: 'mesh',
agents: ['coder', 'tester', 'reviewer'],
communication: 'broadcast'
});
2. 分层(主节点-工作节点)
// Centralized coordination, specialized workers
await swarm.init({
topology: 'hierarchical',
queen: 'architect',
workers: ['backend-dev', 'frontend-dev', 'db-designer']
});
3. 自适应(动态)
// Automatically switches topology based on task
await swarm.init({
topology: 'adaptive',
optimization: 'task-complexity'
});
任务编排
并行执行
// Execute tasks concurrently
const results = await swarm.execute({
tasks: [
{ agent: 'coder', task: 'Implement API endpoints' },
{ agent: 'frontend', task: 'Build UI components' },
{ agent: 'tester', task: 'Write test suite' }
],
mode: 'parallel',
timeout: 300000 // 5 minutes
});
流水线执行
// Sequential pipeline with dependencies
await swarm.pipeline([
{ stage: 'design', agent: 'architect' },
{ stage: 'implement', agent: 'coder', after: 'design' },
{ stage: 'test', agent: 'tester', after: 'implement' },
{ stage: 'review', agent: 'reviewer', after: 'test' }
]);
自适应执行
// Let swarm decide execution strategy
await swarm.autoOrchestrate({
goal: 'Build production-ready API',
constraints: {
maxTime: 3600,
maxAgents: 8,
quality: 'high'
}
});
内存协调
// Share state across swarm
await swarm.memory.store('api-schema', {
endpoints: [...],
models: [...]
});
// Agents read shared memory
const schema = await swarm.memory.retrieve('api-schema');
高级功能
负载均衡
// Automatic work distribution
await swarm.enableLoadBalancing({
strategy: 'dynamic',
metrics: ['cpu', 'memory', 'task-queue']
});
容错
// Handle agent failures
await swarm.setResiliency({
retry: { maxAttempts: 3, backoff: 'exponential' },
fallback: 'reassign-task'
});
性能监控
// Track swarm metrics
const metrics = await swarm.getMetrics();
// { throughput, latency, success_rate, agent_utilization }
与钩子集成
# Pre-task coordination
npx agentic-flow hooks pre-task --description "Build API"
# Post-task synchronization
npx agentic-flow hooks post-task --task-id "task-123"
# Session restore
npx agentic-flow hooks session-restore --session-id "swarm-001"
最佳实践
- 从小规模开始:先从 2-3 个 Agent 开始,再逐步扩展
- 使用内存:通过集群内存共享上下文
- 监控指标:跟踪性能和瓶颈
- 启用钩子:实现自动协调和同步
- 设置超时:防止任务挂起
故障排除
问题:Agent 之间无法协调
解决方案:验证内存访问权限并启用钩子
问题:性能不佳
解决方案:检查拓扑(使用自适应拓扑)并启用负载均衡
了解更多
- 集群指南:docs/swarm/orchestration.md
- 拓扑模式:docs/swarm/topologies.md
- 钩子集成:docs/hooks/coordination.md
评论
支持 Markdown