笔记更新
This commit is contained in:
@@ -1,117 +0,0 @@
|
||||
|
||||
#n8n #openclaw #agents
|
||||
## OpenClaw API Server 配置
|
||||
|
||||
OpenClaw 的 Gateway 可以提供 OpenAI 兼容的 [Fossies](https://fossies.org/linux/openclaw/docs/gateway/openai-http-api.md) Chat Completions 端点,**默认是关闭的**,需要在配置中手动开启。
|
||||
|
||||
### 第一步:开启端点
|
||||
|
||||
编辑 `~/.openclaw/openclaw.json`,添加:
|
||||
|
||||
json
|
||||
|
||||
```json
|
||||
{
|
||||
"gateway": {
|
||||
"port": 18789,
|
||||
"mode": "local",
|
||||
"bind": "lan",
|
||||
"auth": {
|
||||
"mode": "token",
|
||||
"token": "fb97035a1b62a4f29e5cb2f9ac131bd37f021a10823f66b0"
|
||||
},
|
||||
"tailscale": {
|
||||
"mode": "off",
|
||||
"resetOnExit": false
|
||||
},
|
||||
"remote": {
|
||||
"url": "ws://192.168.3.189:18789"
|
||||
},
|
||||
"nodes": {
|
||||
"denyCommands": [
|
||||
"camera.snap",
|
||||
"camera.clip",
|
||||
"screen.record",
|
||||
"contacts.add",
|
||||
"calendar.add",
|
||||
"reminders.add",
|
||||
"sms.send"
|
||||
]
|
||||
},
|
||||
"controlUi": {
|
||||
"allowInsecureAuth": true
|
||||
},
|
||||
"http": {
|
||||
"endpoints": {
|
||||
"chatCompletions": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> `host: "0.0.0.0"` 是为了让 Docker 容器能访问,和 Hermes 同理。
|
||||
|
||||
然后重启 Gateway:
|
||||
|
||||
bash
|
||||
|
||||
```bash
|
||||
openclaw gateway restart
|
||||
```
|
||||
|
||||
验证:
|
||||
|
||||
bash
|
||||
|
||||
```bash
|
||||
curl http://localhost:18789/v1/health
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 与 Hermes 的关键区别
|
||||
|
||||
|项目|Hermes|OpenClaw|
|
||||
|---|---|---|
|
||||
|默认端口|`8642`|**`18789`**|
|
||||
|Agent 指定方式|`"model": "hermes-agent"`|**`"model": "openclaw:main"`**|
|
||||
|默认是否开启|✅ 开启|❌ 需手动开启|
|
||||
|
||||
OpenClaw 通过 `model` 字段来指定 Agent ID,格式为 `"openclaw:<agentId>"`,例如 `"openclaw:main"` 或 `"openclaw:beta"`。 [OpenClaw AI](https://openclaw-ai.com/en/docs/gateway/openai-http-api/)
|
||||
|
||||
---
|
||||
|
||||
## 在 n8n 中调用 OpenClaw
|
||||
|
||||
json
|
||||
|
||||
```json
|
||||
{
|
||||
"model": "openclaw:main",
|
||||
"messages": [
|
||||
{"role": "user", "content": "{{ $json.input }}"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
| 字段 | 值 |
|
||||
| ------------- | ------------------------------------------------ |
|
||||
| URL | `http://192.168.3.189:18789/v1/chat/completions` |
|
||||
| Authorization | `Bearer your-secret-key` |
|
||||
|
||||
---
|
||||
|
||||
## 最终架构总结
|
||||
|
||||
```
|
||||
n8n (Docker)
|
||||
│
|
||||
├─ POST 192.168.3.189:8642 → Hermes Agent (port 8642)
|
||||
│
|
||||
└─ POST 192.168.3.189:18789 → OpenClaw Agent (port 18789)
|
||||
```
|
||||
|
||||
两个都用同一个局域网 IP,只是端口不同,在 n8n 里分别建两个 HTTP Request 节点就可以了。你的 OpenClaw 现在是什么状态,已经安装好了吗?
|
||||
@@ -1,152 +0,0 @@
|
||||
---
|
||||
title: "n8n调用openclaw/hermes agents的工作流架构"
|
||||
source: "https://claude.ai/chat/a18d1fa2-7e98-4f86-bac0-1167281eb151"
|
||||
author:
|
||||
published:
|
||||
created: 2026-04-20
|
||||
description: "Claude conversation with 8 messages"
|
||||
tags:
|
||||
- "clippings"
|
||||
---
|
||||
好消息!**Hermes Agent 内置了 OpenAI 兼容的 API Server**,完全不需要额外写任何代码,直接配置开启就行。
|
||||
|
||||
---
|
||||
|
||||
## 第一步:开启 Hermes API Server
|
||||
|
||||
Hermes 的 API Server 会将 hermes-agent 暴露为一个 OpenAI 兼容的 HTTP 端点,默认端口是 **8642**。 [GitHub](https://github.com/NousResearch/hermes-agent/blob/main/website/docs/user-guide/features/api-server.md)
|
||||
|
||||
bash
|
||||
|
||||
```bash
|
||||
# 开启 API Server
|
||||
hermes config set API_SERVER_ENABLED true
|
||||
|
||||
# 设置一个访问密钥(必须)
|
||||
hermes config set API_SERVER_KEY your-secret-key
|
||||
|
||||
# 启动 Gateway(API Server 随之运行)
|
||||
hermes gateway install # 安装为系统服务
|
||||
hermes gateway start # 启动
|
||||
```
|
||||
|
||||
验证是否正常运行:
|
||||
|
||||
bash
|
||||
|
||||
```bash
|
||||
curl http://localhost:8642/v1/health
|
||||
# 返回 {"status": "ok"} 即成功
|
||||
```
|
||||
|
||||
```bash
|
||||
weishen@WeideMac-mini ~ % hermes config set API_SERVER_ENABLED true
|
||||
✓ Set API_SERVER_ENABLED = True in /Users/weishen/.hermes/config.yaml
|
||||
weishen@WeideMac-mini ~ % nano /Users/weishen/.hermes/config.yaml
|
||||
weishen@WeideMac-mini ~ % hermes config set API_SERVER_KEY 01KPN2YYSEV56BZQSQX9XGW6VH
|
||||
✓ Set API_SERVER_KEY = 01KPN2YYSEV56BZQSQX9XGW6VH in /Users/weishen/.hermes/config.yaml
|
||||
weishen@WeideMac-mini ~ % nano /Users/weishen/.hermes/config.yaml
|
||||
weishen@WeideMac-mini ~ % hermes gateway restart
|
||||
✓ Service restarted
|
||||
weishen@WeideMac-mini ~ % curl http://localhost:8642/v1/health
|
||||
{"status": "ok", "platform": "hermes-agent"}% weishen@WeideMac-mini ~ % curl http://localhost:8642/v1/chat/completions \
|
||||
-H "Authorization: Bearer 01KPN2YYSEV56BZQSQX9XGW6VH" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model": "hermes-agent", "messages": [{"role": "user", "content": "Hello!"}]}'
|
||||
{"id": "chatcmpl-e1569aadb12b4e36aedd9198b29e1", "object": "chat.completion", "created": 1776677020, "model": "hermes-agent", "choices": [{"index": 0, "message": {"role": "assistant", "content": "Hello! How can I help today?"}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 11458, "completion_tokens": 63, "total_tokens": 11521}}%
|
||||
```
|
||||
---
|
||||
|
||||
## 第二步:为每个 Agent 创建独立 Profile
|
||||
|
||||
你可以用 Profile 的方式为每个用户/角色创建独立的 Hermes 实例,每个 profile 跑在不同端口,配置独立的 API key。 [GitHub](https://github.com/NousResearch/hermes-agent/blob/main/website/docs/user-guide/features/api-server.md)
|
||||
|
||||
bash
|
||||
|
||||
```bash
|
||||
# 创建三个专用 Agent(以任务分工为例)
|
||||
hermes profile create agent-researcher
|
||||
hermes profile create agent-writer
|
||||
hermes profile create agent-coder
|
||||
|
||||
# 分别配置端口和 key
|
||||
hermes -p agent-researcher config set API_SERVER_ENABLED true
|
||||
hermes -p agent-researcher config set API_SERVER_PORT 8643
|
||||
hermes -p agent-researcher config set API_SERVER_KEY key-researcher
|
||||
|
||||
hermes -p agent-writer config set API_SERVER_ENABLED true
|
||||
hermes -p agent-writer config set API_SERVER_PORT 8644
|
||||
hermes -p agent-writer config set API_SERVER_KEY key-writer
|
||||
|
||||
hermes -p agent-coder config set API_SERVER_ENABLED true
|
||||
hermes -p agent-coder config set API_SERVER_PORT 8645
|
||||
hermes -p agent-coder config set API_SERVER_KEY key-coder
|
||||
|
||||
# 分别启动三个 gateway
|
||||
hermes -p agent-researcher gateway &
|
||||
hermes -p agent-writer gateway &
|
||||
hermes -p agent-coder gateway &
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 第三步:在 n8n 中调用
|
||||
|
||||
每个 Agent 都是标准的 OpenAI 格式接口,在 n8n 中用 **HTTP Request 节点**:
|
||||
|
||||
|字段|填写内容|
|
||||
|---|---|
|
||||
|Method|POST|
|
||||
|URL|`http://localhost:8643/v1/chat/completions`|
|
||||
|Header: Authorization|`Bearer key-researcher`|
|
||||
|Header: Content-Type|`application/json`|
|
||||
|
||||
Body(JSON):
|
||||
|
||||
json
|
||||
|
||||
```json
|
||||
{
|
||||
"model": "agent-researcher",
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "你是一个专门负责网络调研的Agent,请搜索并总结信息"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "{{ $json.task }}"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 多轮对话保持上下文(重要)
|
||||
|
||||
v0.7.0 起 API Server 支持通过 `X-Hermes-Session-Id` header 来保持会话连续性,让 chat-completions 客户端也能跨请求共享同一个 session。 [GitHub](https://github.com/mudrii/hermes-agent-docs)
|
||||
|
||||
在 n8n 的 HTTP Request 节点 Header 中加一行:
|
||||
|
||||
```
|
||||
X-Hermes-Session-Id: my-workflow-session-001
|
||||
```
|
||||
|
||||
这样同一个工作流里的多次调用会共享上下文,非常适合需要多步推理的任务链。
|
||||
|
||||
---
|
||||
|
||||
## 完整架构示意
|
||||
|
||||
```
|
||||
n8n Workflow
|
||||
│
|
||||
├─ [HTTP Request] → localhost:8643 (agent-researcher) → 搜索/调研
|
||||
│
|
||||
├─ [HTTP Request] → localhost:8644 (agent-writer) → 内容生成
|
||||
│
|
||||
└─ [HTTP Request] → localhost:8645 (agent-coder) → 代码任务
|
||||
```
|
||||
|
||||
这套方案完全原生支持,不需要任何额外中间件。你现在的 Hermes 是哪个版本?可以用 `hermes version` 确认一下,部分特性需要 v0.4.0+。
|
||||
Reference in New Issue
Block a user