mcpField
S
Swarm Orchestration

Swarm Orchestration

github.com/ruvnetAgent 工作流101.6k41 次安装今天更新
代码仓库

关于 Swarm Orchestration

Swarm Orchestration 是用于协调多 Agent 集群的 agentic-flow 技能,支持多种拓扑、任务执行模式、共享记忆和容错控制。

主要功能

  1. 01网状、分层和自适应拓扑
  2. 02并行执行与依赖流水线
  3. 03自动分配任务和负载均衡
  4. 04Agent 间共享记忆
  5. 05重试与任务重新分配
  6. 06集群指标和 hooks

适用场景

  1. 01协同运行编码、测试和审查 Agent
  2. 02按顺序完成设计、实现、测试和审查
  3. 03通过自适应拓扑协调变化的工作负载

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/ruvnet/ruview --skill swarm-orchestration

安装后在 Claude Code 中输入/swarm-orchestration确认已加载。

详细介绍

Swarm 编排

此技能的功能

使用 agentic-flow 的高级协调系统编排多 Agent swarm。支持网状、分层和自适应拓扑,并具备自动任务分配、负载均衡和容错功能。

前提条件

  • agentic-flow v3.0.0-alpha.1+
  • 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 }

与 Hooks 集成

# 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"

最佳实践

  1. 从小规模开始:先从 2-3 个 Agent 开始,再逐步扩展
  2. 使用内存:通过 swarm 内存共享上下文
  3. 监控指标:跟踪性能和瓶颈
  4. 启用 Hooks:实现自动协调与同步
  5. 设置超时:防止任务挂起

故障排除

问题:Agent 未能协调

解决方案:确认内存访问权限,并启用 Hooks

问题:性能不佳

解决方案:检查拓扑(使用自适应拓扑),并启用负载均衡

了解更多

  • Swarm 指南:docs/swarm/orchestration.md
  • 拓扑模式:docs/swarm/topologies.md
  • Hooks 集成:docs/hooks/coordination.md

评论

支持 Markdown