Install
openclaw skills install yuyonghao-agent-orchestrator生产级 Agent 编排器,实现Agent生命周期管理、任务调度、资源限制、服务发现及多节点集群管理功能。
openclaw skills install yuyonghao-agent-orchestrator生产级 Agent 编排器,类似 Kubernetes 的 Agent 调度系统。
npm install
const { AgentOrchestrator } = require('./src');
// 创建编排器实例
const orchestrator = new AgentOrchestrator({
cluster: { enabled: true, nodeId: 'node-1' },
scheduler: { strategy: 'round-robin' },
resources: { maxAgents: 100, maxTasksPerAgent: 10 }
});
// 注册 Agent
orchestrator.registerAgent({
id: 'agent-1',
capabilities: ['text-generation', 'code-execution'],
resources: { maxConcurrent: 5 }
});
// 提交任务
const task = await orchestrator.submitTask({
type: 'code-generation',
priority: 'high',
payload: { prompt: 'Generate a function...' }
});
// 获取集群状态
const status = orchestrator.getClusterStatus();
console.log(status);
// Round Robin
const orchestrator = new AgentOrchestrator({
scheduler: { strategy: 'round-robin' }
});
// Least Connections
const orchestrator = new AgentOrchestrator({
scheduler: { strategy: 'least-connections' }
});
// Weighted Round Robin
const orchestrator = new AgentOrchestrator({
scheduler: { strategy: 'weighted-round-robin', weights: { 'agent-1': 2, 'agent-2': 1 } }
});
// 配置健康检查
const orchestrator = new AgentOrchestrator({
healthCheck: {
enabled: true,
interval: 30000, // 30 seconds
timeout: 5000, // 5 seconds
retries: 3
}
});
// 手动检查 Agent 健康
const isHealthy = await orchestrator.healthChecker.check('agent-1');
// 配置资源限制
const orchestrator = new AgentOrchestrator({
resources: {
maxAgents: 100,
maxTasksPerAgent: 10,
maxMemoryPerAgent: '512MB',
maxCpuPerAgent: '1.0'
}
});
// 获取资源使用
const usage = orchestrator.resourceManager.getUsage();
new AgentOrchestrator(options)
Options:
cluster: 集群配置scheduler: 调度器配置resources: 资源限制healthCheck: 健康检查配置registerAgent(agent): 注册 AgentunregisterAgent(agentId): 注销 AgentsubmitTask(task): 提交任务cancelTask(taskId): 取消任务getClusterStatus(): 获取集群状态getAgentStatus(agentId): 获取 Agent 状态npm test
{
cluster: {
enabled: true,
nodeId: 'node-1',
leaderElection: true
},
scheduler: {
strategy: 'round-robin', // or 'least-connections', 'weighted-round-robin'
priorityLevels: ['low', 'normal', 'high', 'critical']
},
resources: {
maxAgents: 100,
maxTasksPerAgent: 10,
maxMemoryPerAgent: '512MB',
maxCpuPerAgent: '1.0'
},
healthCheck: {
enabled: true,
interval: 30000,
timeout: 5000,
retries: 3
}
}
MIT