npm package: @openclaw-harness/orchestrator
Description: OpenClaw Harness Orchestrator - Multi-Agent coordination and task dispatching
Author: OpenClaw Harness Team
Latest version: 0.1.0

# @openclaw-harness/orchestrator

[![npm version](https://badge.fury.io/js/@openclaw-harness%2Forchestrator.svg)](https://www.npmjs.com/package/@openclaw-harness/orchestrator)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

[English](./README.md) | 中文

> 多 Agent 协调和任务分发

## 特性

- 🤖 **Agent 管理** - 注册、管理和监控多个 Agent
- 🎯 **智能路由** - 能力匹配、负载均衡、成本优化
- 🔄 **Agent 交接** - Agent 之间的无缝上下文转移
- 📢 **广播** - 向多个 Agent 广播消息

## 安装

```bash
npm install @openclaw-harness/orchestrator
```

## 快速开始

```typescript
import { HarnessOrchestratorPlugin } from '@openclaw-harness/orchestrator';

const plugin = new HarnessOrchestratorPlugin();

// 初始化
await plugin.init(openClawContext);

// 获取编排器服务
const orchestratorService = openClawContext.api.getService('harness:orchestrator');

// 注册 Agent
await orchestratorService.registerAgent({
  id: 'my-agent',
  name: '我的 Agent',
  capabilities: [{ name: 'text-generation', description: '生成文本' }]
});

// 分发任务
const result = await orchestratorService.dispatchTask({
  id: 'task-1',
  type: 'text-generation',
  description: '写一首诗',
  input: {},
  priority: 'medium'
});
```

## 路由策略

- **能力匹配** - 根据任务类型选择具有相应能力的 Agent
- **轮询** - 平均分配任务到所有可用 Agent
- **负载均衡** - 选择负载最轻的 Agent
- **成本优化** - 优先选择成本较低的 Agent
- **性能优化** - 选择响应时间最短的 Agent

## CLI 命令

```bash
# 列出所有 Agent
openclaw harness:agent:list

# 从 JSON 文件注册 Agent
openclaw harness:agent:register ./agent-config.json

# 注销 Agent
openclaw harness:agent:unregister <agent-id>

# 查看 Agent 状态
openclaw harness:agent:status <agent-id>

# 分发任务
openclaw harness:task:dispatch '{"id":"task-1","type":"text-generation","description":"写一首诗"}'

# Agent 交接
openclaw harness:agent:handoff <from-agent-id> <to-agent-id>

# 查看指标
openclaw harness:orchestrator:metrics
```

## HTTP API

```bash
# 列出所有 Agent
curl http://localhost:3000/harness/agents

# 注册 Agent
curl -X POST http://localhost:3000/harness/agents \
  -H "Content-Type: application/json" \
  -d @agent-config.json

# 分发任务
curl -X POST http://localhost:3000/harness/tasks \
  -H "Content-Type: application/json" \
  -d '{"id":"task-1","type":"text-generation","description":"写一首诗","input":{},"priority":"medium"}'

# Agent 交接
curl -X POST http://localhost:3000/harness/handoff \
  -H "Content-Type: application/json" \
  -d '{"fromAgentId": "agent-1", "toAgentId": "agent-2"}'
```

## Agent 配置示例

```json
{
  "id": "tech-agent",
  "name": "技术支持 Agent",
  "description": "处理技术问题",
  "capabilities": [
    { "name": "technical-support", "description": "处理技术问题" },
    { "name": "debugging", "description": "调试代码问题" }
  ],
  "tools": ["search", "code-executor", "file-reader"],
  "model": "gpt-4"
}
```

## 协调模式

### Supervisor 模式
一个主管 Agent 管理多个工作 Agent：

```typescript
const coordination = orchestratorService.createCoordination({
  type: 'supervisor',
  config: {
    supervisorAgentId: 'supervisor',
    workerAgentIds: ['worker1', 'worker2'],
    delegationStrategy: 'auto'
  }
});
```

### Pipeline 模式
多个 Agent 按顺序处理任务：

```typescript
const coordination = orchestratorService.createCoordination({
  type: 'pipeline',
  config: {
    stages: [
      { id: 'stage1', agentId: 'agent1' },
      { id: 'stage2', agentId: 'agent2' }
    ],
    errorHandling: 'stop'
  }
});
```

## 文档

查看 [完整文档](https://github.com/your-username/harness-orchestrator#readme) 获取更多详情。

## 许可证

MIT © [OpenClaw Harness Team](https://github.com/your-username)