完整实现 Swarm 多智能体协作系统
- 新增 CLIPluginAdapter 统一接口 (backend/app/core/agent_adapter.py) - 新增 LLM 服务层,支持 Anthropic/OpenAI/DeepSeek/Ollama (backend/app/services/llm_service.py) - 新增 Agent 执行引擎,支持文件锁自动管理 (backend/app/services/agent_executor.py) - 新增 NativeLLMAgent 原生 LLM 适配器 (backend/app/adapters/native_llm_agent.py) - 新增进程管理器 (backend/app/services/process_manager.py) - 新增 Agent 控制 API (backend/app/routers/agents_control.py) - 新增 WebSocket 实时通信 (backend/app/routers/websocket.py) - 更新前端 AgentsPage,支持启动/停止 Agent - 测试通过:Agent 启动、批量操作、栅栏同步 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
305
docs/reference-projects.md
Normal file
305
docs/reference-projects.md
Normal file
@@ -0,0 +1,305 @@
|
||||
# 多 Agent 协作系统 - 参考项目分析
|
||||
|
||||
> 本文档分析相关开源项目的优点,用于设计整合
|
||||
|
||||
---
|
||||
|
||||
## 一、插件化架构参考
|
||||
|
||||
### 1. OpenClaw ⭐⭐⭐⭐⭐
|
||||
**GitHub**: [MindDock/OpenClaw](https://github.com/MindDock/OpenClaw)
|
||||
|
||||
**核心优点**:
|
||||
- **Channel Plugin 接口**:统一的插件架构,支持消息通道、Agent 工具、CLI 扩展
|
||||
- **Plugin SDK**:完整的插件开发框架,包含扩展点、配置系统、发布流程
|
||||
- **Gateway 控制平面**:WebSocket/HTTP 控制平面,支持 RPC 方法、事件系统
|
||||
- **适配器模式**:每个插件实现标准接口,易于扩展
|
||||
|
||||
```typescript
|
||||
// OpenClaw Channel Plugin 接口
|
||||
interface ChannelPlugin {
|
||||
id: string;
|
||||
meta: ChannelMeta;
|
||||
capabilities: ChannelCapabilities;
|
||||
config: ChannelConfigAdapter;
|
||||
outbound: ChannelOutboundAdapter;
|
||||
inbound?: ChannelInboundAdapter;
|
||||
messaging?: ChannelMessagingAdapter;
|
||||
}
|
||||
```
|
||||
|
||||
**适用场景**:CLI 工具插件化、多通道适配
|
||||
|
||||
---
|
||||
|
||||
### 2. everything-claude-code ⭐⭐⭐⭐⭐
|
||||
**GitHub**: [affaan-m/everything-claude-code](https://github.com/affaan-m/everything-claude-code)
|
||||
|
||||
**核心优点**:
|
||||
- **跨工具兼容**:设计为可在 Claude Code、Codex、Cursor、OpenCode 等多种工具运行
|
||||
- **DRY Adapter**:适配器模式实现跨工具通用描述
|
||||
- **插件系统**:完整的 Claude Code 插件,支持 agents、commands、skills、hooks
|
||||
- **多语言规则架构**:按语言分组的规则系统(common + typescript + python + golang)
|
||||
|
||||
```json
|
||||
{
|
||||
"extraKnownMarketplaces": {
|
||||
"everything-claude-code": {
|
||||
"source": {
|
||||
"source": "github",
|
||||
"repo": "affaan-m/everything-claude-code"
|
||||
}
|
||||
}
|
||||
},
|
||||
"enabledPlugins": {
|
||||
"everything-claude-code@everything-claude-code": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**适用场景**:跨 CLI 工具的 Agent 适配
|
||||
|
||||
---
|
||||
|
||||
### 3. Kimi CLI ⭐⭐⭐⭐
|
||||
**GitHub**: [MoonshotAI/kimi-cli](https://github.com/MoonshotAI/kimi-cli)
|
||||
|
||||
**核心优点**:
|
||||
- **Agent Client Protocol (ACP)**:标准的 Agent 客户端协议
|
||||
- **MCP 支持**:完整的 Model Context Protocol 支持
|
||||
- **Zsh 集成**:Shell 集成,支持模式切换(Agent/Shell)
|
||||
|
||||
```bash
|
||||
# MCP 配置示例
|
||||
kimi --mcp-config-file /path/to/mcp.json
|
||||
```
|
||||
|
||||
**适用场景**:CLI 工具的 MCP 集成参考
|
||||
|
||||
---
|
||||
|
||||
## 二、共识机制参考
|
||||
|
||||
### 1. W-5 Multi-Agent Consensus Framework ⭐⭐⭐⭐⭐
|
||||
**GitHub**: [Winner12-AI/w5-football-prediction](https://github.com/Winner12-AI/w5-football-prediction)
|
||||
|
||||
**核心优点**:
|
||||
- **概率再平衡器**:使用 Gemini 3 作为"概率再平衡器"
|
||||
- **动态提示注入**:根据任务动态调整提示词
|
||||
- **多 Agent 辩论**:Agent 之间通过辩论达成共识
|
||||
- **准确率提升**:86.3% 准确率,通过共识机制实现
|
||||
|
||||
```
|
||||
共识流程:
|
||||
1. 各 Agent 独立分析
|
||||
2. 提出初步结论
|
||||
3. Agent 之间辩论
|
||||
4. 概率再平衡
|
||||
5. 达成共识
|
||||
```
|
||||
|
||||
**适用场景**:多 Agent 决策共识
|
||||
|
||||
---
|
||||
|
||||
### 2. Claude-Flow ⭐⭐⭐⭐⭐
|
||||
**项目**: Enterprise multi-agent orchestration for Claude Code
|
||||
|
||||
**核心优点**:
|
||||
- **容错共识**:支持 Byzantine、Weighted、Majority 三种共识机制
|
||||
- **Queen-led Swarms**:层级化协调,防止 Agent 漂移
|
||||
- **SONA 学习**:自优化神经架构,<0.05ms 适应速度
|
||||
- **HNSW Memory**:150x-12,500x 更快的模式检索
|
||||
|
||||
| 共识类型 | 特点 | 适用场景 |
|
||||
|---------|------|---------|
|
||||
| Byzantine | 2/3 多数,抗恶意节点 | 高安全要求 |
|
||||
| Weighted | 按权重投票 | 专家系统 |
|
||||
| Majority | 简单多数 | 快速决策 |
|
||||
| Raft | 领导者选举 | 分布式协调 |
|
||||
| Gossip | 流言传播 | 大规模系统 |
|
||||
|
||||
**适用场景**:企业级 Agent 编排、容错共识
|
||||
|
||||
---
|
||||
|
||||
### 3. Multi-Agent Consensus Seeking via LLMs
|
||||
**论文**: [Multi-Agent Consensus Seeking Via Large Language Models](https://www.aminer.cn/pub/6541a83c939a5f40824d000c/multi-agent-consensus-seeking-via-large-language-models)
|
||||
|
||||
**核心优点**:
|
||||
- **平均策略**:LLM Agent 主要使用平均策略寻求共识
|
||||
- **网络拓扑影响**:分析 Agent 数量、个性、网络拓扑对谈判的影响
|
||||
- **零样本自主规划**:应用于多机器人聚合任务
|
||||
|
||||
**适用场景**:Agent 谈判、共识算法设计
|
||||
|
||||
---
|
||||
|
||||
## 三、协作协议参考
|
||||
|
||||
### 1. Co-TAP: Three-Layer Agent Interaction Protocol ⭐⭐⭐⭐⭐
|
||||
**项目**: Co-TAP 三层 Agent 交互协议
|
||||
|
||||
**核心优点**:
|
||||
- **HAI (Human-Agent Interaction)**:人机交互标准化
|
||||
- **UAP (Unified Agent Protocol)**:异构 Agent 统一通信
|
||||
- **MEK (Memory-Extraction-Knowledge)**:认知链标准化
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────┐
|
||||
│ HAI 层:用户-界面-Agent 信息流标准化 │
|
||||
├─────────────────────────────────────────────────┤
|
||||
│ UAP 层:异构 Agent 无缝互联 │
|
||||
├─────────────────────────────────────────────────┤
|
||||
│ MEK 层:记忆-提取-知识认知链 │
|
||||
└─────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
**适用场景**:跨平台 Agent 通信
|
||||
|
||||
---
|
||||
|
||||
### 2. Internet of Agents (IoA) ⭐⭐⭐⭐
|
||||
**论文**: Internet of Agents: Fundamentals, Applications, and Challenges
|
||||
|
||||
**核心优点**:
|
||||
- **能力通知与发现**:Agent 动态发现机制
|
||||
- **自适应通信协议**:协议转换机制
|
||||
- **动态任务匹配**:任务自动分配
|
||||
- **共识与冲突解决**:内置冲突解决机制
|
||||
- **激励模型**:经济激励机制
|
||||
|
||||
**适用场景**:大规模 Agent 网络
|
||||
|
||||
---
|
||||
|
||||
### 3. Agent Name Service (ANS) ⭐⭐⭐⭐
|
||||
**项目**: Universal Directory for AI Agent Discovery
|
||||
|
||||
**核心优点**:
|
||||
- **PKI 证书**:可验证的 Agent 身份
|
||||
- **DNS 命名**:DNS 风格的命名约定
|
||||
- **协议适配器层**:支持 A2A、MCP、ACP 等多种协议
|
||||
- **安全解析**:正式化的解析算法
|
||||
|
||||
**适用场景**:Agent 发现与互操作
|
||||
|
||||
---
|
||||
|
||||
## 四、MCP 集成参考
|
||||
|
||||
### 1. MCP 协议完整生态
|
||||
**标准**: Model Context Protocol (Anthropic)
|
||||
|
||||
**核心优点**:
|
||||
- **三种传输模式**:stdio、http、sse
|
||||
- **三大核心原语**:Tools、Resources、Prompts
|
||||
- **动态发现**:运行时工具发现
|
||||
- **16000+ Server**:丰富的生态
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"github": {
|
||||
"type": "http",
|
||||
"url": "https://github-mcp.example.com",
|
||||
"headers": {
|
||||
"Authorization": "Bearer ${GITHUB_TOKEN}"
|
||||
}
|
||||
},
|
||||
"filesystem": {
|
||||
"type": "stdio",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "~/Projects"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 五、整合设计建议
|
||||
|
||||
基于以上分析,建议整合以下优点:
|
||||
|
||||
### 1. 插件化架构(来自 OpenClaw + everything-claude-code)
|
||||
```python
|
||||
interface CLIPluginAdapter {
|
||||
id: string
|
||||
name: string
|
||||
version: string
|
||||
|
||||
# 适配能力
|
||||
def execute(task: Task) -> Result
|
||||
def get_status() -> Status
|
||||
def join_meeting(meeting_id: str) -> None
|
||||
def write_state(state: dict) -> None
|
||||
def read_others(agent_id: str) -> dict
|
||||
}
|
||||
|
||||
# 预置适配器
|
||||
class ClaudeCodeAdapter(CLIPluginAdapter): ...
|
||||
class KimiCodeAdapter(CLIPluginAdapter): ...
|
||||
class OpenCodeAdapter(CLIPluginAdapter): ...
|
||||
```
|
||||
|
||||
### 2. 共识机制(来自 Claude-Flow + W-5)
|
||||
```python
|
||||
class ConsensusMechanism:
|
||||
def propose(self, agent_id: str, proposal: Proposal) -> None
|
||||
def vote(self, agent_id: str, vote: Vote) -> None
|
||||
def resolve(self) -> Decision
|
||||
|
||||
# 共识类型
|
||||
class ByzantineConsensus(ConsensusMechanism): ...
|
||||
class WeightedConsensus(ConsensusMechanism): ...
|
||||
class MajorityConsensus(ConsensusMechanism): ...
|
||||
```
|
||||
|
||||
### 3. 会议驱动(栅栏同步)
|
||||
```python
|
||||
class MeetingBarrier:
|
||||
def wait(self, agent_id: str) -> None
|
||||
def trigger_when_all_ready(self) -> None
|
||||
def start_conensus_process(self) -> Decision
|
||||
```
|
||||
|
||||
### 4. .doc 文件夹结构
|
||||
```
|
||||
.doc/
|
||||
├── agents/ # Agent 注册与状态
|
||||
│ ├── claude-code.json
|
||||
│ ├── kimi-cli.json
|
||||
│ └── opencode.json
|
||||
├── dialogues/ # Agent 间对话记录
|
||||
│ └── agent_a_agent_b_20250304.json
|
||||
├── progress/ # 工程进度
|
||||
│ └── project_state.json
|
||||
├── resources/ # 资源分配与锁
|
||||
│ └── resource_pool.json
|
||||
├── meetings/ # 会议记录与共识
|
||||
│ └── meeting_20250304.md
|
||||
├── cache/ # 实时缓存
|
||||
│ └── meeting_queue.json
|
||||
└── workflow/ # 工作流定义
|
||||
└── project_workflow.yaml
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 六、参考项目链接汇总
|
||||
|
||||
| 项目 | GitHub/链接 | 核心价值 |
|
||||
|-----|------------|---------|
|
||||
| OpenClaw | [MindDock/OpenClaw](https://github.com/MindDock/OpenClaw) | 插件化架构 |
|
||||
| everything-claude-code | [affaan-m/everything-claude-code](https://github.com/affaan-m/everything-claude-code) | 跨工具兼容 |
|
||||
| Kimi CLI | [MoonshotAI/kimi-cli](https://github.com/MoonshotAI/kimi-cli) | MCP + ACP |
|
||||
| W-5 Framework | [Winner12-AI/w5-football-prediction](https://github.com/Winner12-AI/w5-football-prediction) | 共识机制 |
|
||||
| Claude-Flow | [ruvnet/claude-flow](https://github.com/ruvnet/claude-flow) | 企业级编排 |
|
||||
| RuVector | [ruvnet/ruvector](https://github.com/ruvnet/ruvector) | 自学习向量库 |
|
||||
| template-repo | [AndrewAltimit/template-repo](https://github.com/AndrewAltimit/template-repo) | 6 Agents + 14 MCP |
|
||||
| MCP Protocol | [modelcontextprotocol](https://modelcontextprotocol.io/) | 统一协议标准 |
|
||||
|
||||
---
|
||||
|
||||
*更新日期:2026-03-04*
|
||||
Reference in New Issue
Block a user