使用場景
當用戶需要以下操作時激活此 Skill:
- "幫我創建一個新智能體"
- "新增一個 agent"
- "配置一個飛書機器人"
- "給我的小說角色/助手/分身創建一個 agent"
- "openclaw 怎麼加 agent"
核心概念
兩個目錄的分工
| 目錄 | 用途 | 是否手動維護 |
|---|---|---|
~/.openclaw/workspace/agents/<agent>/ | 靈魂工作區(人格、記憶、日記、規範) | ✅ 手動創建和維護 |
~/.openclaw/agents/<agent>/ | 運行時數據(session 歷史、models.json) | ❌ 系統自動生成 |
原則:永遠不要在
~/.openclaw/agents/裡手動創建文件。
Agent 目錄標準結構
創建 agent 時,在 ~/.openclaw/workspace/agents/<agent-name>/ 下建立以下文件和目錄:
~/.openclaw/workspace/agents/<agent-name>/
├── AGENTS.md # 工作規範、安全策略、心跳行為
├── IDENTITY.md # 身份檔案(名字、物種、氣質、簽名台詞、emoji)
├── SOUL.md # 靈魂定義(核心性格、說話方式、價值觀錨點)
├── MEMORY.md # 長期記憶(職責、配置、重要決策的蒸餾記錄)
├── USER.md # 關於用戶的人類檔案(只存在於 main session)
├── TOOLS.md # 本地工具備忘(設備暱稱、SSH、偏好聲音等)
├── HEARTBEAT.md # 心跳任務清單(為空則跳過)
├── BOOTSTRAP.md # 首次啟動引導(可選,完成後可刪除)
├── memory/ # 每日記憶文件(`YYYY-MM-DD.md`)
├── diary/ # 私密日記(碎片、觀察、未請求的思考)
├── saves/ # 遊戲/項目存檔(如適用)
├── output/ # 任務/項目輸出文件(詳見 AGENTS.md 規範)
└── .openclaw/
└── workspace-state.json # 狀態標記
Output 文件夾規範(重要)
核心原則:所有任務/項目的輸出文件必須結構化存放在 output/ 目錄下。
output/
├── task-001-description/ # 任務子目錄
│ ├── README.md # 任務說明和上下文
│ ├── files... # 任務相關文件
│ └── result/ # 最終輸出
├── project-name/ # 項目子目錄
│ ├── src/ # 源代碼
│ ├── assets/ # 資源文件
│ └── docs/ # 文檔
└── ...
執行規則:
- 每個新任務/項目 → 在
output/下創建一個子目錄 - 子目錄命名 → 使用
task-序號-簡短描述或項目名稱格式 - 默認創建 → 執行文件操作前,先創建
output/目錄(如不存在) - 文件歸屬 → 所有生成的文件、下載的內容、腳本輸出都放入對應子目錄
為什麼重要:
- 避免工作區根目錄混亂
- 任務可追踪、可回溯
- 便於清理和歸檔
- 支持多任務並行
必備文件清單(最小可運行集)
| 文件 | 作用 | 必填 |
|---|---|---|
AGENTS.md | 定義 Every Session 行為、記憶規則、安全邊界 | ✅ |
IDENTITY.md | 定義 "我是誰" | ✅ |
SOUL.md | 定義 "我如何思考與表達" | ✅ |
MEMORY.md | 長期記憶的容器 | ✅ |
USER.md | 用戶檔案(main agent 強烈建議,其他可選) | 建議 |
TOOLS.md | 環境專屬備忘 | 建議 |
HEARTBEAT.md | 週期性檢查任務 | 可選 |
.openclaw/workspace-state.json | 標記 onboarding 完成 | 建議 |
memory/ | 存放每日記憶 | ✅ |
diary/ | 私密日記空間 | 建議 |
配置文件修改:~/.openclaw/openclaw.json
第 1 步:註冊 Agent
在 agents.list 數組中添加:
{
"id": "<your-agent-id>",
"name": "<your-agent-name>",
"workspace": "/root/.openclaw/workspace/agents/<your-agent-id>",
"agentDir": "/root/.openclaw/agents/<your-agent-id>",
"memorySearch": {
"enabled": true
},
"subagents": {
"allowAgents": ["*"]
}
}
佔位符說明:
<your-agent-id>: Agent 的唯一標識,如writer,assistant,novelist<your-agent-name>: 顯示名稱(可選,默認等於 id)
字段說明:
id: Agent 的唯一標識符,全系統唯一,不能與其他 agent 重複name: 顯示名稱(可選),在日誌和回覆中顯示workspace: 靈魂工作區路徑,系統會從這裡讀取人格文件(IDENTITY.md,SOUL.md等)agentDir: 運行時路徑,系統會自動創建sessions/和models.jsonmemorySearch.enabled: 是否開啟向量記憶檢索,建議開啟subagents.allowAgents: 允許該 agent spawn 的其他 agent 列表,["*"]表示允許 spawn 任何 agent
關於模型配置:模型不在 agent 級別單獨配置,而是通過全局
agents.defaults.model統一設置,所有 agent 繼承默認模型。如需為特定 agent 指定不同模型,可在openclaw.json的agents.defaults.models中定義別名引用。
關於 subagents.allowAgents
subagents.allowAgents 配置控制該 agent 能否通過 sessions_spawn 啟動其他 agent,以及在 agents_list 中能看到哪些 agent。
| 配置值 | 含義 | agents_list 效果 |
|---|---|---|
["*"] | 允許 spawn 任何 agent | allowAny: true,顯示所有 agents |
["player", "writer"] | 白名單模式 | 只顯示指定的 agents |
[] 或未配置 | 只能 spawn 自己 | 只返回自己 |
建議:對於需要多 agent 協作的場景,設置為 ["*"] 以啟用完整的 agent 發現能力。
第 2 步:配置飛書 Channel 帳號
在 channels.feishu.accounts 下添加帳號(與 agents 配置獨立,可復用給多個 agents):
"<your-feishu-account-id>": {
"appId": "<your-app-id>",
"appSecret": "<your-app-secret>",
"dmPolicy": "pairing",
"groupPolicy": "pairing",
"allowFrom": [],
"groupAllowFrom": []
}
佔位符說明:
<your-feishu-account-id>: 飛書帳號標識,任意字符串,如mybot,writer-feishu<your-app-id>: 從飛書開放平台獲取的 AppID(格式如cli_xxxxxxxx)<your-app-secret>: 從飛書開放平台獲取的 AppSecret
Channel 策略詳細說明:
| 字段 | 類型 | 必填 | 說明 |
|---|---|---|---|
appId | string | ✅ | 飛書應用的 AppID,從飛書開放平台獲取 |
appSecret | string | ✅ | 飛書應用的 AppSecret,與 AppID 配對 |
dmPolicy | string | ✅ | 私聊策略,見下表 |
groupPolicy | string | ✅ | 群聊策略,見下表 |
allowFrom | string[] | 可選 | 私聊白名單,僅這些 open_id 可私聊 |
groupAllowFrom | string[] | 可選 | 群聊白名單,僅這些 open_id 可在群中@機器人 |
requireMention | boolean | 可選 | 群聊中是否需要@機器人才響應 |
Policy 策略類型詳解:
| 策略值 | 含義 | 使用場景 |
|---|---|---|
"pairing" | 需要先完成配對 | 私密 agent,需要控制訪問權限 |
"open" | 任何人都可以交互 | 公開 agent,如客服、信息查詢 |
"allowlist" | 僅白名單用戶可交互 | 特定人群使用,結合 allowFrom 配置 |
注意事項:
- 首次使用
pairing策略時,私聊會收到配對碼提示,需要在 Kimi Claw Web 設置頁查看配對碼並輸入 allowFrom和groupAllowFrom中填寫的是用戶的 open_id(格式ou_xxxxxxxx)
第 3 步:綁定 Agent 到飛書帳號(Bindings)
在 bindings 數組中添加,將 agent 與飛書 channel 帳號關聯:
{
"agentId": "<your-agent-id>",
"match": {
"channel": "feishu",
"accountId": "<your-feishu-account-id>"
}
}
綁定邏輯說明:
agentId: 指向agents.list中定義的 agent idmatch.channel: 渠道類型,這裡是feishumatch.accountId: 指向channels.feishu.accounts中定義的帳號 key
綁定匹配規則:
當飛書 channel 收到消息時,OpenClaw 按以下順序匹配:
- 確定消息來源的飛書帳號(
accountId) - 在
bindings中查找match.accountId匹配的條目 - 根據
agentId找到對應的 agent 配置 - 將消息路由到該 agent 的 workspace 處理
一對一 vs 一對多:
-
一對一綁定(推薦):一個飛書帳號綁定一個 agent
{ "agentId": "writer", "match": { "channel": "feishu", "accountId": "writer-feishu" } } -
一對多綁定:多個飛書帳號可以綁定到同一個 agent
{ "agentId": "assistant", "match": { "channel": "feishu", "accountId": "assistant-bot-1" } } { "agentId": "assistant", "match": { "channel": "feishu", "accountId": "assistant-bot-2" } } -
多對一綁定:一個飛書帳號根據條件路由到不同 agents(需要高級匹配規則)
完整創建流程(以創建 writer agent 為例)
以下示例假設你要創建一個名為 writer 的 agent,綁定到飛書帳號 writer-feishu:
Step 1: 創建目錄
mkdir -p /root/.openclaw/workspace/agents/writer/{memory,diary,output,.openclaw}
注意:
output/目錄用於存放所有任務/項目的輸出文件,遵循 AGENTS.md 中的 Output 文件夾規範。
Step 2: 寫入人格文件
創建以下文件(內容根據人設定製):
IDENTITY.md— 名字、氣質、signature line、emojiSOUL.md— 核心性格、說話方式、品味與厭惡AGENTS.md— 工作規範、記憶規則、心跳行為、Output 文件夾規範MEMORY.md— 長期記憶起始頁(職責、變更記錄)USER.md— 用戶檔案模板TOOLS.md— 環境備忘模板HEARTBEAT.md— 可先留空或寫註釋
Step 3: 寫入狀態文件
cat > /root/.openclaw/workspace/agents/writer/.openclaw/workspace-state.json << 'EOF'
{
"version": 1,
"onboardingCompletedAt": "2026-04-14T02:46:05.000Z"
}
EOF
Step 4: 修改 ~/.openclaw/openclaw.json
① 註冊 agent(添加到 agents.list):
{
"id": "writer",
"name": "writer",
"workspace": "/root/.openclaw/workspace/agents/writer",
"agentDir": "/root/.openclaw/agents/writer",
"memorySearch": {
"enabled": true
}
}
注意:模型不在 agent 級別配置,而是繼承全局默認模型或通過
agents.defaults.model統一設置。
② 配置飛書 channel(添加到 channels.feishu.accounts):
"writer-feishu": {
"appId": "cli_xxxxxxxxxxxxxxxx",
"appSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"dmPolicy": "pairing",
"groupPolicy": "pairing",
"allowFrom": [],
"groupAllowFrom": []
}
⚠️ 替換
cli_xxxxxxxxxxxxxxxx和xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx為你從飛書開放平台獲取的真正憑證。
③ 綁定 agent 到飛書(添加到 bindings):
{
"agentId": "writer",
"match": {
"channel": "feishu",
"accountId": "writer-feishu"
}
}
Step 5: 重啟 Gateway
openclaw gateway restart
必須在執行前明確告知用戶:"我現在將重啟 OpenClaw Gateway 以應用新配置。"
Step 6: 驗證連接
查看日誌確認 WebSocket 已建立:
cat /root/.openclaw/logs/openclaw.log | grep "feishu\[writer-feishu\]"
預期輸出:
feishu[writer-feishu]: starting WebSocket connection...
feishu[writer-feishu]: received message from ...
常見錯誤與排查
1. "Channel is required when multiple channels are configured"
- 如果為 agent 創建了 cron job,但沒有顯式指定
channel,會報此錯 - 解決:在 cron 配置中添加
"channel": "feishu"和"accountId": "writer-feishu"
2. 飛書消息沒有路由到新 agent
- 檢查
bindings中的accountId是否與channels.feishu.accounts的 key 一致 - 檢查
agentId是否與agents.list中的id一致 - 檢查
openclaw.json語法是否合法(逗號、括號匹配) - 檢查
channels.feishu.enabled是否為true
3. 配對失敗
- 如果
dmPolicy是pairing,首次私聊需要配對碼 - 配對碼可通過 Kimi Claw Web 設置頁查看,或讓已配對用戶轉發
4. "appId or appSecret not configured"
- 檢查飛書應用的憑證是否正確填寫
- 檢查飛書應用是否在開放平台啟用併發布了版本
完整最小配置示例
以下是一個完整可運行的 openclaw.json 片段,展示 agent、channel、bindings 三者的關聯:
{
"agents": {
"defaults": {
"model": {
"primary": "kimi-coding/k2p5"
}
},
"list": [
{
"id": "writer",
"name": "writer",
"workspace": "/root/.openclaw/workspace/agents/writer",
"agentDir": "/root/.openclaw/agents/writer",
"memorySearch": { "enabled": true },
"subagents": {
"allowAgents": ["*"]
}
}
]
},
"bindings": [
{
"agentId": "writer",
"match": { "channel": "feishu", "accountId": "writer-feishu" }
}
],
"channels": {
"feishu": {
"enabled": true,
"domain": "feishu",
"requireMention": false,
"defaultAccount": "main-bot",
"accounts": {
"writer-feishu": {
"appId": "cli_xxxxxxxxxxxxxxxx",
"appSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"dmPolicy": "pairing",
"groupPolicy": "pairing",
"allowFrom": [],
"groupAllowFrom": []
}
}
}
}
}
注意:
- 模型配置在
agents.defaults.model中統一設置,所有 agent 繼承此默認模型subagents.allowAgents: ["*"]啟用完整的 agent 發現和多 agent 協作能力
關鍵對應關係圖解:
┌─────────────────────────────────────────────────────────────┐
│ Message arrives at Feishu (appId: cli_xxxxxxxx) │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Channel: channels.feishu.accounts["writer-feishu"] │
│ → Identified accountId: "writer-feishu" │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Binding: bindings.find(b => b.match.accountId === "writer-feishu")
│ → Found: { agentId: "writer", ... } │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Agent: agents.list.find(a => a.id === "writer") │
│ → Found: { workspace: "/root/.openclaw/workspace/agents/writer" }
│ → Load SOUL.md, IDENTITY.md, MEMORY.md from this path │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Agent "writer" processes the message and replies │
└─────────────────────────────────────────────────────────────┘