first build nexus
This commit is contained in:
574
AI/openclaw/OpenClaw 多 Agent 系统设计.md
Normal file
574
AI/openclaw/OpenClaw 多 Agent 系统设计.md
Normal file
@@ -0,0 +1,574 @@
|
||||
|
||||
#openclaw #agent #telegram
|
||||
```table-of-contents
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# OpenClaw 多 Agent 自动化系统架构笔记 (Advanced)
|
||||
|
||||
Author: Billy
|
||||
Purpose: 构建基于 OpenClaw + Telegram + n8n 的 AI 自动化控制系统
|
||||
|
||||
---
|
||||
|
||||
# 1 系统总体架构
|
||||
|
||||
**目标:**
|
||||
|
||||
构建一个 **AI Automation Control Center**
|
||||
|
||||
**核心组件:**
|
||||
|
||||
- OpenClaw Gateway
|
||||
- 多 Agent
|
||||
- Telegram Interface
|
||||
- n8n Workflow Engine
|
||||
|
||||
**系统架构:**
|
||||
|
||||
```
|
||||
Telegram
|
||||
│
|
||||
▼
|
||||
Telegram Bot
|
||||
│
|
||||
▼
|
||||
n8n
|
||||
(Command Router)
|
||||
│
|
||||
▼
|
||||
OpenClaw Gateway
|
||||
│
|
||||
▼
|
||||
┌────────┬────────┬────────┐
|
||||
▼ ▼ ▼ ▼
|
||||
Router Dev Research Ops
|
||||
Agent Agent Agent Agent
|
||||
```
|
||||
|
||||
**系统功能:**
|
||||
|
||||
| 组件 | 作用 |
|
||||
|------|------|
|
||||
| Telegram | 用户交互 |
|
||||
| n8n | 任务路由 |
|
||||
| OpenClaw | AI Agent Runtime |
|
||||
| Agents | 任务执行 |
|
||||
|
||||
---
|
||||
|
||||
# 2 OpenClaw 基础目录结构
|
||||
|
||||
**默认路径:** `~/.openclaw/`
|
||||
|
||||
**结构:**
|
||||
|
||||
```
|
||||
.openclaw/
|
||||
│
|
||||
├── agents/
|
||||
│ │
|
||||
│ ├── main/
|
||||
│ │ └── agent/
|
||||
│ │ ├── authprofile.json
|
||||
│ │ └── models.json
|
||||
│ │
|
||||
│ └── research/
|
||||
│ └── agent/
|
||||
│ ├── authprofile.json
|
||||
│ └── models.json
|
||||
│
|
||||
└── workspace/
|
||||
│
|
||||
├── skills/
|
||||
├── memory/
|
||||
├── identity/
|
||||
│ └── Identity.md
|
||||
├── logs/
|
||||
├── devices/
|
||||
├── completions/
|
||||
└── canvas/
|
||||
```
|
||||
|
||||
**说明:**
|
||||
|
||||
| 目录 | 作用 |
|
||||
|------|------|
|
||||
| agents | Agent Profile |
|
||||
| workspace | 运行数据 |
|
||||
| skills | 技能插件 |
|
||||
| memory | AI记忆 |
|
||||
| identity | System Prompt |
|
||||
| logs | 日志 |
|
||||
|
||||
---
|
||||
|
||||
# 3 多 Agent 设计
|
||||
|
||||
**创建 Agent:**
|
||||
|
||||
```bash
|
||||
openclaw agent create dev
|
||||
openclaw agent create research
|
||||
openclaw agent create ops
|
||||
openclaw agent create orchestrator
|
||||
```
|
||||
|
||||
**推荐 Agent 列表:**
|
||||
|
||||
| Agent | 职责 |
|
||||
|-------|------|
|
||||
| orchestrator | 任务调度 |
|
||||
| dev | 编程 |
|
||||
| research | 搜索分析 |
|
||||
| ops | 服务器运维 |
|
||||
| data | 数据处理 |
|
||||
|
||||
**推荐结构:**
|
||||
|
||||
```
|
||||
agents/
|
||||
│
|
||||
├── orchestrator/
|
||||
├── dev/
|
||||
├── research/
|
||||
├── ops/
|
||||
└── data/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 4 Agent Identity 设计
|
||||
|
||||
Identity 代表:System Prompt
|
||||
|
||||
**建议放在:** `agents/dev/agent/identity.md`
|
||||
|
||||
**示例:**
|
||||
|
||||
```
|
||||
You are DevAgent.
|
||||
|
||||
Responsibilities:
|
||||
- write code
|
||||
- debug programs
|
||||
- generate scripts
|
||||
- create docker configurations
|
||||
```
|
||||
|
||||
**Research Agent:**
|
||||
|
||||
```
|
||||
You are ResearchAgent.
|
||||
|
||||
Responsibilities:
|
||||
- research information
|
||||
- summarize technical topics
|
||||
- analyze documents
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 5 Skills 机制
|
||||
|
||||
**Skills 目录:** `workspace/skills`
|
||||
|
||||
**示例:**
|
||||
|
||||
```
|
||||
skills/
|
||||
├── browser
|
||||
├── filesystem
|
||||
├── python
|
||||
├── telegram
|
||||
└── self-improving-agent
|
||||
```
|
||||
|
||||
**特点:**
|
||||
|
||||
- 所有 Agent 共享
|
||||
- 类似插件
|
||||
|
||||
---
|
||||
|
||||
# 6 Memory 设计
|
||||
|
||||
**默认 memory:** `workspace/memory`
|
||||
|
||||
默认共享。
|
||||
|
||||
**memory 类型:**
|
||||
|
||||
```
|
||||
memory/
|
||||
├── episodic
|
||||
├── semantic
|
||||
└── vector
|
||||
```
|
||||
|
||||
**推荐 Memory 分层:**
|
||||
|
||||
```
|
||||
memory/
|
||||
├── system
|
||||
├── dev
|
||||
├── research
|
||||
└── ops
|
||||
```
|
||||
|
||||
这样避免:memory pollution
|
||||
|
||||
**Agent 指定 namespace:**
|
||||
|
||||
```json
|
||||
{
|
||||
"memoryNamespace": "dev"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 7 模型配置
|
||||
|
||||
每个 Agent 独立:`agents/<agent>/agent/models.json`
|
||||
|
||||
**示例:**
|
||||
|
||||
```json
|
||||
{
|
||||
"default": "gpt-4o-mini",
|
||||
"models": {
|
||||
"gpt-4o-mini": {
|
||||
"provider": "openai",
|
||||
"model": "gpt-4o-mini"
|
||||
},
|
||||
"deepseek-coder": {
|
||||
"provider": "openai-compatible",
|
||||
"base_url": "https://api.deepseek.com/v1",
|
||||
"model": "deepseek-coder"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**推荐模型分配:**
|
||||
|
||||
| Agent | Model |
|
||||
|-------|-------|
|
||||
| orchestrator | gpt-4o-mini |
|
||||
| dev | deepseek-coder |
|
||||
| research | gpt-4o |
|
||||
| ops | claude-sonnet |
|
||||
|
||||
**优点:**
|
||||
|
||||
- 降低成本
|
||||
- 提升能力
|
||||
|
||||
---
|
||||
|
||||
# 8 Agent 切换
|
||||
|
||||
**切换 active agent:**
|
||||
|
||||
```bash
|
||||
openclaw agent use research
|
||||
```
|
||||
|
||||
**行为:**
|
||||
|
||||
```
|
||||
current_agent = research
|
||||
```
|
||||
|
||||
下一条消息:
|
||||
|
||||
```
|
||||
Telegram → research agent
|
||||
```
|
||||
|
||||
不需要重启 Gateway。
|
||||
|
||||
---
|
||||
|
||||
# 9 Telegram 集成
|
||||
|
||||
OpenClaw 支持:Telegram Bot
|
||||
|
||||
**结构:**
|
||||
|
||||
```
|
||||
Telegram
|
||||
│
|
||||
▼
|
||||
OpenClaw Gateway
|
||||
```
|
||||
|
||||
**默认:** 所有消息 → active agent
|
||||
|
||||
---
|
||||
|
||||
# 10 Telegram 指令体系
|
||||
|
||||
**推荐命令:**
|
||||
|
||||
```
|
||||
/dev
|
||||
/research
|
||||
/ops
|
||||
/data
|
||||
/help
|
||||
```
|
||||
|
||||
**示例:**
|
||||
|
||||
```
|
||||
/dev 写一个python脚本
|
||||
/research 查一下OpenClaw架构
|
||||
/ops restart docker
|
||||
```
|
||||
|
||||
在 BotFather 设置:`/setcommands`
|
||||
|
||||
**示例:**
|
||||
|
||||
```
|
||||
dev - coding tasks
|
||||
research - research tasks
|
||||
ops - server tasks
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 11 n8n Command Router
|
||||
|
||||
推荐使用:n8n 进行任务路由。
|
||||
|
||||
**架构:**
|
||||
|
||||
```
|
||||
Telegram
|
||||
│
|
||||
▼
|
||||
n8n
|
||||
│
|
||||
▼
|
||||
OpenClaw
|
||||
```
|
||||
|
||||
**Workflow:**
|
||||
|
||||
```
|
||||
Telegram Trigger
|
||||
│
|
||||
▼
|
||||
Parse Command
|
||||
│
|
||||
▼
|
||||
Agent Router
|
||||
│
|
||||
▼
|
||||
HTTP → OpenClaw
|
||||
```
|
||||
|
||||
**解析示例:**
|
||||
|
||||
```javascript
|
||||
const msg = $json.message.text
|
||||
|
||||
if(msg.startsWith("/dev")){
|
||||
return {agent:"dev"}
|
||||
}
|
||||
|
||||
if(msg.startsWith("/research")){
|
||||
return {agent:"research"}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 12 Router Agent
|
||||
|
||||
Router Agent 负责:Task Distribution
|
||||
|
||||
**Prompt 示例:**
|
||||
|
||||
```
|
||||
You are a routing agent.
|
||||
|
||||
Rules:
|
||||
/dev → DevAgent
|
||||
/research → ResearchAgent
|
||||
/ops → OpsAgent
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 13 推荐系统架构
|
||||
|
||||
Mac Mini AI Control Center:
|
||||
|
||||
```
|
||||
Mac Mini
|
||||
│
|
||||
├─ OpenClaw Gateway
|
||||
├─ n8n
|
||||
└─ Telegram Bot
|
||||
|
||||
Agents
|
||||
│
|
||||
├─ orchestrator
|
||||
├─ dev
|
||||
├─ research
|
||||
├─ ops
|
||||
└─ data
|
||||
```
|
||||
|
||||
**数据流:**
|
||||
|
||||
```
|
||||
Telegram
|
||||
↓
|
||||
n8n Router
|
||||
↓
|
||||
OpenClaw
|
||||
↓
|
||||
Agents
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 14 高级玩法
|
||||
|
||||
**支持:**
|
||||
|
||||
### 多服务器 Agent
|
||||
|
||||
```
|
||||
Mac Mini
|
||||
orchestrator
|
||||
|
||||
Ubuntu Server
|
||||
dev agent
|
||||
|
||||
NAS
|
||||
data agent
|
||||
```
|
||||
|
||||
**通信:**
|
||||
|
||||
```
|
||||
HTTP
|
||||
Redis
|
||||
MQ
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 15 最佳实践
|
||||
|
||||
### 1 Agent 专业化
|
||||
|
||||
**正确:**
|
||||
|
||||
```
|
||||
dev-agent
|
||||
ops-agent
|
||||
research-agent
|
||||
```
|
||||
|
||||
**错误:**
|
||||
|
||||
```
|
||||
python-agent
|
||||
browser-agent
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2 模型分工
|
||||
|
||||
不要所有 agent 使用同一个模型。
|
||||
|
||||
**否则:**
|
||||
|
||||
```
|
||||
multi-agent ≈ single-agent
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3 Memory 分层
|
||||
|
||||
**推荐:**
|
||||
|
||||
```
|
||||
memory/
|
||||
├── system
|
||||
├── dev
|
||||
├── research
|
||||
└── ops
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4 Router 统一入口
|
||||
|
||||
**不要:**
|
||||
|
||||
```
|
||||
Telegram → 各 agent
|
||||
```
|
||||
|
||||
**应该:**
|
||||
|
||||
```
|
||||
Telegram → Router → Agents
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 16 最终架构总结
|
||||
|
||||
**最终系统:**
|
||||
|
||||
```
|
||||
Telegram
|
||||
│
|
||||
▼
|
||||
n8n Router
|
||||
│
|
||||
▼
|
||||
OpenClaw Gateway
|
||||
│
|
||||
▼
|
||||
┌──────────────┬──────────────┬──────────────┐
|
||||
DevAgent ResearchAgent OpsAgent
|
||||
```
|
||||
|
||||
**系统特点:**
|
||||
|
||||
- 多 Agent
|
||||
- 多模型
|
||||
- 自动任务分发
|
||||
- Telegram 控制
|
||||
- 自动化工作流
|
||||
|
||||
---
|
||||
|
||||
# 17 未来扩展
|
||||
|
||||
**未来可扩展:**
|
||||
|
||||
- AI 自动任务
|
||||
- 自动服务器运维
|
||||
- 自动代码生成
|
||||
- 自动数据分析
|
||||
- 自动监控告警
|
||||
|
||||
**目标:** 构建 Personal AI Operations Center
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user