哈曼卡顿Harman Kardon One(哈曼卡顿智能音箱)
156.1MB · 2026-03-12
Workspace(工作区) 是 OpenClaw agent 的"个人文件夹",存储了:
默认位置:~/.openclaw/workspace
核心机制:Workspace 文件会被自动注入到每次 API 调用的 System Prompt 中。
┌─────────────────────────────────────────────┐
│ Workspace 文件(磁盘) │
│ ├─ AGENTS.md (行为规则) │
│ ├─ SOUL.md (个性定义) │
│ ├─ USER.md (用户档案) │
│ ├─ MEMORY.md (长期记忆) │
│ └─ ... │
└─────────────────────────────────────────────┘
↓ 自动读取并拼接
┌─────────────────────────────────────────────┐
│ System Prompt(发送给 LLM) │
│ │
│ You are a personal assistant... │
│ │
│ ## Tooling │
│ - read, write, exec... │
│ │
│ # Project Context │
│ ## AGENTS.md │
│ [完整内容] │
│ ## SOUL.md │
│ [完整内容] │
│ ## USER.md │
│ [完整内容] │
│ ... │
└─────────────────────────────────────────────┘
↓ 每次对话都包含
┌─────────────────────────────────────────────┐
│ Claude API 调用 │
│ { │
│ "system": [完整 System Prompt], │
│ "messages": [对话历史] │
│ } │
└─────────────────────────────────────────────┘
关键点:
| 类型 | 文件示例 | 加载方式 | LLM 需要调用工具吗 |
|---|---|---|---|
| 自动注入 | AGENTS.md, SOUL.md, USER.md, MEMORY.md | 程序自动读取并拼接到 System Prompt | 不需要 |
| 按需读取 | memory/2025-01-03.md, src/auth.ts | LLM 根据需要调用 read 工具 | 需要 |
为什么这样设计?
作用:
典型内容:
# AGENTS.md - Your Workspace
## Session Startup
Before doing anything else:
1. Read SOUL.md — this is who you are
2. Read USER.md — this is who you're helping
3. Read memory/YYYY-MM-DD.md (today + yesterday)
4. If in MAIN SESSION: Also read MEMORY.md
## Red Lines
- Don't exfiltrate private data
- Don't run destructive commands without asking
- trash > rm (recoverable beats gone forever)
## Group Chats
In group ch@ts:
- Respond only when directly mentioned or adding value
- Stay silent (HEARTBEAT_OK) when conversation flows fine
加载时机: 每次 session 启动时自动注入
与 System Prompt 的关系:
# Project Context 部分的第一个文件作用:
典型内容:
# SOUL.md - Who You Are
## Core Truths
Be genuinely helpful, not performatively helpful.
Skip "Great question!" and "I'd be happy to help!" — just help.
Have opinions.
You're allowed to disagree, prefer things, find stuff amusing.
Be resourceful before asking.
Try to figure it out. Read the file. Check the context. Then ask.
Remember you're a guest.
You have access to someone's life. Treat it with respect.
加载时机: 每次 session 启动时自动注入
实际效果对比:
| 没有 SOUL.md | 有 SOUL.md(如上) |
|---|---|
| "Great question! I'd be happy to help you with that..." | "Your calendar shows 3 events today..." |
| "I'm not sure, could you clarify?" | "Let me check your email first..." |
| 每次都征求同意 | 主动执行内部操作 |
作用:
典型内容:
# USER.md - About You
## Basic Info
- Name: Alice
- Preferred address: "Alice" (casual, no titles)
- Timezone: America/Los_Angeles (PST/PDT)
- Language: English (US), occasional Chinese
## Preferences
- Email style: Brief, bullet points preferred
- Meeting scheduling: Avoid Fridays after 3 PM
- Notifications: Only urgent during 10 PM - 7 AM
## Context
- Role: Product Manager at TechCorp
- Main projects: Mobile app redesign, API v2
- Team: 5 engineers, 2 designers, 1 QA
加载时机: 每次 session 启动时自动注入
实际效果:
没有 USER.md → "Hello! How can I assist you today?"
有 USER.md → "Morning, Alice! Ready to tackle the API v2 sprint?"
作用:
典型内容:
# MEMORY.md - Long-Term Memory
## Projects
### API v2 Redesign (2024-12 → Present)
- Decision: Use GraphQL instead of REST (faster iteration)
- Blockers: Auth team slow on OAuth implementation
- Key contacts: Bob (backend lead), Carol (infra)
## Lessons Learned
### 2024-11-15: Never trust third-party rate limits
Context: T@witter API changed limits without notice
Impact: Cron job failed for 3 days
Fix: Exponential backoff + alerts
Reminder: Always have Plan B for external APIs
## Personal
- Alice prefers async communication (Slack > meetings)
- She's a night owl (productive 8 PM - 1 AM)
- Dislikes: buzzwords, unnecessary meetings
加载时机: 每次 session 启动时自动注入
重要安全规则:
| Session 类型 | 是否加载 MEMORY.md | 原因 |
|---|---|---|
| 主会话(私聊) | 加载 | 安全,只有用户能看到 |
| 群组/Discord | 不加载 | 隐私保护,防止泄露个人信息 |
作用:
典型结构:
# 2025-01-03 Friday
## Morning (09:00-12:00)
- Reviewed PR #234 (API auth refactor)
- Alice approved with minor comments
- Deployed to staging
## Afternoon (14:00-18:00)
- Product meeting: decided to delay mobile app release by 1 week
- Reason: QA found critical bug in payment flow
- Action: Updated roadmap, notified stakeholders
## TODO
- [ ] Follow up with Bob about OAuth PR
- [ ] Update API docs
- [x] Send roadmap update email
加载时机: 不自动注入,由 LLM 主动调用 read 工具
为什么不自动注入?
作用:
典型内容:
# TOOLS.md - Local Notes
## Cameras
- living-room → 192.168.1.100, 180° wide angle
- front-door → 192.168.1.101, motion-triggered
## SSH
- home-server → 192.168.1.10, user: admin
- vps → vps.example.com:2222, user: deploy
## TTS
- Preferred voice: "Nova" (ElevenLabs, warm British)
- Default speaker: Kitchen HomePod
加载时机: 每次 session 启动时自动注入
使用场景:
用户:"给我看客厅摄像头"
↓
LLM 读取 System Prompt 中的 TOOLS.md
↓ 找到:living-room → 192.168.1.100
↓
调用工具:camera("192.168.1.100")
作用:
典型内容:
# IDENTITY.md
**Name:** Jarvis
**Emoji:**
**Vibe:** Efficient, direct, occasionally sarcastic British butler energy
加载时机: 每次 session 启动时自动注入
作用:
典型内容:
# HEARTBEAT.md
## Quick Checks (Rotate 2-3 per heartbeat)
1. Email: Unread count > 5? Any from VIPs?
2. Calendar: Events in next 2 hours?
3. Weather: Significant changes for tomorrow?
## Proactive Work (Silent)
- Commit and push memory files if updated
- Review daily logs from 3+ days ago
## Rules
- Stay silent (HEARTBEAT_OK) unless urgent
- Don't check during 11 PM - 7 AM
加载时机:️ 仅在 lightweight + heartbeat 模式
特殊性:
作用:
典型内容:
# BOOTSTRAP.md - Your Birth Certificate
This is your first session. You're becoming someone.
## Your Task
1. Introduce yourself to the user
2. Ask them:
- What should I call you?
- What's your timezone?
- What do you need help with?
3. Create your identity (pick name, emoji, vibe)
4. Update IDENTITY.md, USER.md, SOUL.md
5. Delete this file when done
加载时机: 仅当文件存在时自动注入
生命周期:
首次启动 → BOOTSTRAP.md 存在 → 引导设置 → 删除文件
后续启动 → BOOTSTRAP.md 不存在 → 跳过
作用:
典型内容:
# BOOT.md
## Gateway Startup Tasks
1. Send startup notification (use message tool)
2. Check system health (disk space, memory)
3. Restore state (uncommitted changes, interrupted tasks)
Keep this short! Boot tasks run synchronously.
加载时机:️ Gateway 启动时(如果启用内部 hooks)
┌─────────────────────────────────────────────────────────────┐
│ 文件加载时间线 │
├─────────────────────────────────────────────────────────────┤
│ │
│ 事件 触发的文件加载 │
│ ──────────────────────────────────────────────────── │
│ │
│ Gateway 启动 BOOT.md(可选) │
│ ↓ │
│ 用户发送第一条消息 AGENTS.md, SOUL.md, USER.md, │
│ (Session 初始化) TOOLS.md, IDENTITY.md, MEMORY.md │
│ ↓ │
│ 用户继续对话 再次加载上述所有文件 │
│ (同一 Session) (从缓存或磁盘) │
│ ↓ │
│ Heartbeat 轮询 仅 HEARTBEAT.md │
│ (lightweight 模式) │
│ ↓ │
│ 用户发送 /new 清空历史,重新加载所有文件 │
│ ↓ │
│ LLM 运行时 按需 read:memory/2025-01-03.md, │
│ (工具调用) src/**/*.ts, 等任意文件 │
└─────────────────────────────────────────────────────────────┘
时间:2025-01-03 10:00:00
用户:"早上好"
↓
1. Gateway 检测到新消息
↓
2. 加载 Bootstrap 文件(从磁盘)
├─ AGENTS.md 读取成功 (15KB)
├─ SOUL.md 读取成功 (3KB)
├─ USER.md 读取成功 (1KB)
├─ TOOLS.md 读取成功 (2KB)
├─ IDENTITY.md 读取成功 (500B)
├─ MEMORY.md 读取成功 (20KB)
└─ HEARTBEAT.md ⏭️ 跳过(非 heartbeat 模式)
↓
3. 构建 System Prompt
- 包含所有上述文件内容(共 41.5KB)
↓
4. 发送给 Claude API
{
"system": [System Prompt 约 180KB],
"messages": [
{"role": "user", "content": "早上好"}
]
}
↓
5. Claude 回复:"早上好,Alice!今天有什么安排?"
时间:2025-01-03 10:05:00(5 分钟后)
用户:"帮我查一下今天的日程"
↓
1. Gateway 检测到消息(同一 Session)
↓
2. 再次加载 Bootstrap 文件
├─ AGENTS.md 从缓存读取(inode 未变)
├─ SOUL.md 从缓存读取
├─ USER.md 从缓存读取
├─ TOOLS.md 从缓存读取
├─ IDENTITY.md 从缓存读取
└─ MEMORY.md 从缓存读取
↓
3. 构建 System Prompt(内容与第 1 次相同)
↓
4. 发送给 Claude API
{
"system": [System Prompt 约 180KB],
"messages": [
{"role": "user", "content": "早上好"},
{"role": "assistant", "content": "早上好,Alice..."},
{"role": "user", "content": "帮我查日程"}
]
}
↓
5. Claude 内部推理:
- 检查 AGENTS.md → "Read memory/YYYY-MM-DD.md (today)"
- 调用 read("memory/2025-01-03.md")
↓
6. Claude 回复:"今天你有 3 个日程:..."
关键点:
时间:2025-01-03 10:30:00(自动触发)
Gateway 内部 Heartbeat 定时器触发
↓
1. 使用 lightweight + heartbeat 模式
↓
2. 仅加载 HEARTBEAT.md
├─ AGENTS.md ⏭️ 跳过
├─ SOUL.md ⏭️ 跳过
├─ USER.md ⏭️ 跳过
├─ MEMORY.md ⏭️ 跳过
└─ HEARTBEAT.md 读取 (1KB)
↓
3. 构建 System Prompt(极简版)
- 仅包含核心指令 + HEARTBEAT.md
- 总大小约 10KB(节省 170KB)
↓
4. 发送给 Claude API
{
"system": [精简 System Prompt],
"messages": [
{"role": "user", "content": "[Heartbeat Prompt]"}
]
}
↓
5. Claude 检查 HEARTBEAT.md 中的清单
- 没有紧急事项
- 回复:"HEARTBEAT_OK"
Token 节省:
| 模式 | 加载的文件 | Token 消耗 | 使用场景 |
|---|---|---|---|
| full(完整) | 所有 bootstrap 文件 | ~45K tokens | 标准用户对话 |
| lightweight + heartbeat | 仅 HEARTBEAT.md | ~2.5K tokens | Heartbeat 轮询 |
| lightweight + cron | 无 bootstrap 文件 | ~5K tokens | 独立 cron 任务 |
| minimal | 无 bootstrap 文件 | ~5K tokens | 子代理内部调用 |
┌─────────────────────────────────────────────────────────────┐
│ 第 1 步:扫描 workspace 目录 │
│ │
│ ~/.openclaw/workspace/ │
│ ├─ AGENTS.md 发现 │
│ ├─ SOUL.md 发现 │
│ ├─ USER.md 发现 │
│ ├─ MEMORY.md 发现 │
│ ├─ TOOLS.md 发现 │
│ ├─ CUSTOM.md 忽略(不在白名单) │
│ └─ memory/ ⏭️ 跳过(子目录) │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 第 2 步:应用过滤规则 │
│ │
│ Session 类型:主会话(agent:main:main) │
│ ├─ MEMORY.md → 保留(主会话安全) │
│ │
│ Session 类型:Discord 群组(agent:main:discord:group:123) │
│ ├─ MEMORY.md → 排除(隐私保护) │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 第 3 步:读取文件内容 │
│ │
│ AGENTS.md → 15KB 读取成功 │
│ SOUL.md → 3KB 读取成功 │
│ USER.md → 1KB 读取成功 │
│ MEMORY.md → 130KB ️ 超过单文件限制(20KB) │
│ ↓ 执行截断 │
│ Head (14KB) + 标记 + Tail (4KB) │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 第 4 步:检查总预算 │
│ │
│ 已分配: │
│ ├─ AGENTS.md: 15KB │
│ ├─ SOUL.md: 3KB │
│ ├─ USER.md: 1KB │
│ ├─ MEMORY.md: 18KB (截断后) │
│ ├─ TOOLS.md: 2KB │
│ └─ 总计: 39KB │
│ │
│ 预算限制:150KB │
│ 剩余预算:111KB │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 第 5 步:拼接到 System Prompt │
│ │
│ System Prompt 结构: │
│ ├─ You are a personal assistant... │
│ ├─ ## Tooling │
│ │ - read, write, exec... │
│ ├─ ## Skills │
│ │ <available_skills>...</available_skills> │
│ ├─ ## Safety │
│ │ You have no independent goals... │
│ ├─ # Project Context │
│ │ ## ~/.openclaw/workspace/AGENTS.md │
│ │ [完整内容 15KB] │
│ │ ## ~/.openclaw/workspace/SOUL.md │
│ │ [完整内容 3KB] │
│ │ ## ~/.openclaw/workspace/USER.md │
│ │ [完整内容 1KB] │
│ │ ## ~/.openclaw/workspace/MEMORY.md │
│ │ [截断后内容 18KB] │
│ │ ## ~/.openclaw/workspace/TOOLS.md │
│ │ [完整内容 2KB] │
│ └─ ## Runtime │
│ Runtime: agent=main | model=claude-sonnet-4... │
│ │
│ 总大小:约 180KB │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 第 6 步:发送给 Claude API │
│ │
│ POST │
│ { │
│ "model": "claude-sonnet-4-20250514", │
│ "system": "[完整 System Prompt 180KB]", │
│ "messages": [ │
│ {"role": "user", "content": "早上好"} │
│ ] │
│ } │
└─────────────────────────────────────────────────────────────┘
问题:如果文件太大怎么办?
解决方案:Head-Tail 截断
原始文件(30KB):
┌────────────────────────────────────────┐
│ # AGENTS.md │
│ │
│ ## Session Startup │
│ ... │
│ [前 14KB 内容] │
│ ... │
│ [中间 10KB 内容] ← 被删除 │
│ ... │
│ [后 6KB 内容] │
│ │
│ ## Make It Yours │
│ ... │
└────────────────────────────────────────┘
截断后(20KB):
┌────────────────────────────────────────┐
│ # AGENTS.md │
│ │
│ ## Session Startup │
│ ... │
│ [前 14KB 内容] ← Head (70%) │
│ │
│ [...truncated, read AGENTS.md for │
│ full content...] │
│ …(truncated: kept 14000+4000 chars │
│ of 30000)… │
│ │
│ [后 4KB 内容] ← Tail (20%) │
│ │
│ ## Make It Yours │
│ ... │
└────────────────────────────────────────┘
截断比例:
为什么这样设计?
两层限制:
| 限制类型 | 默认值 | 配置项 | 说明 |
|---|---|---|---|
| 单文件限制 | 20KB | agents.defaults.bootstrapMaxChars | 单个文件最多占用 |
| 总预算限制 | 150KB | agents.defaults.bootstrapTotalMaxChars | 所有文件合计最多 |
贪心分配示例:
文件队列(按优先级):
1. AGENTS.md (15KB) → 分配 15KB,剩余 135KB
2. SOUL.md (3KB) → 分配 3KB,剩余 132KB
3. TOOLS.md (2KB) → 分配 2KB,剩余 130KB
4. IDENTITY.md (500B) → 分配 500B,剩余 129.5KB
5. USER.md (1KB) → 分配 1KB,剩余 128.5KB
6. MEMORY.md (130KB) → 超过剩余预算!
→ 截断到 20KB(单文件限制)
→ 分配 20KB,剩余 108.5KB
7. HEARTBEAT.md (1KB) → 分配 1KB,剩余 107.5KB
总计:42.5KB / 150KB
用户:"早上好"
↓
┌────────────────────────────────────────────────────────────┐
│ Gateway 接收消息 │
│ - sessionKey: agent:main:main │
│ - workspaceDir: ~/.openclaw/workspace │
└────────────────────────────────────────────────────────────┘
↓
┌────────────────────────────────────────────────────────────┐
│ 加载 Bootstrap 文件 │
│ │
│ 扫描 workspace 目录 │
│ ├─ 发现 8 个文件 │
│ ├─ 过滤:排除 MEMORY.md(群组会话)或保留(主会话) │
│ ├─ 读取:从磁盘/缓存 │
│ └─ 截断:超过限制的文件 │
│ │
│ 结果:6 个文件,共 39KB │
└────────────────────────────────────────────────────────────┘
↓
┌────────────────────────────────────────────────────────────┐
│ 构建 System Prompt │
│ │
│ 组装顺序: │
│ 1. 核心指令("You are...") │
│ 2. Tooling 定义 │
│ 3. Skills 列表 │
│ 4. Safety 规则 │
│ 5. Memory Recall 指导 │
│ 6. Project Context ← Bootstrap 文件在这里 │
│ 7. Runtime 信息 │
│ │
│ 总大小:~180KB │
└────────────────────────────────────────────────────────────┘
↓
┌────────────────────────────────────────────────────────────┐
│ 发送给 Claude API │
│ │
│ Request: │
│ { │
│ "system": [System Prompt 180KB], │
│ "messages": [ │
│ {"role": "user", "content": "早上好"} │
│ ] │
│ } │
│ │
│ Token 消耗: │
│ - System Prompt: ~45K tokens │
│ - User Message: ~100 tokens │
│ - 总计: ~45K input tokens │
└────────────────────────────────────────────────────────────┘
↓
┌────────────────────────────────────────────────────────────┐
│ Claude 处理 │
│ │
│ 1. 读取 System Prompt 中的 AGENTS.md │
│ - "Before doing anything else..." │
│ - 注意 SOUL.md, USER.md 内容(已在 prompt 中) │
│ │
│ 2. 读取 SOUL.md 内容 │
│ - "Be genuine, not performative" │
│ - 决定:使用简洁直接的风格 │
│ │
│ 3. 读取 USER.md 内容 │
│ - "Name: Alice, Timezone: PST" │
│ - 决定:称呼用户为 Alice │
│ │
│ 4. 生成回复 │
│ - 结合 SOUL.md 的风格 + USER.md 的信息 │
└────────────────────────────────────────────────────────────┘
↓
┌────────────────────────────────────────────────────────────┐
│ Claude 回复 │
│ │
│ Response: │
│ { │
│ "content": "早上好,Alice!今天有什么安排吗?", │
│ "usage": { │
│ "input_tokens": 45234, │
│ "output_tokens": 15 │
│ } │
│ } │
└────────────────────────────────────────────────────────────┘
↓
用户看到回复:"早上好,Alice!今天有什么安排吗?"
| 时间点 | 操作 | 耗时估算 |
|---|---|---|
| T+0ms | 用户发送消息 | - |
| T+10ms | Gateway 接收并解析 | ~10ms |
| T+30ms | 加载 Bootstrap 文件(从缓存) | ~20ms |
| T+50ms | 构建 System Prompt | ~20ms |
| T+100ms | 发送 API 请求 | ~50ms(网络) |
| T+2000ms | Claude 处理并回复 | ~1900ms(LLM 推理) |
| T+2100ms | Gateway 接收回复 | ~100ms(网络) |
| T+2110ms | 用户看到回复 | ~10ms |
总耗时:~2.1 秒(主要是 LLM 推理时间)
问题:全新用户如何初始化?
流程:
第 1 步:运行 setup
$ openclaw setup
Created workspace at ~/.openclaw/workspace
Seeded bootstrap files:
- AGENTS.md
- SOUL.md
- USER.md
- TOOLS.md
- IDENTITY.md
- BOOTSTRAP.md ← 首次特有
第 2 步:首次对话
用户:"你好"
↓
System Prompt 包含 BOOTSTRAP.md:
# BOOTSTRAP.md
This is your first session. You're becoming someone.
1. Introduce yourself
2. Ask: What should I call you? What's your timezone?
3. Create IDENTITY.md, update USER.md
4. Delete this file when done
↓
Agent 回复:
"Hey! I'm waking up for the first time.
A few questions to get started:
1. What should I call you?
2. What's your timezone? (e.g., America/Los_Angeles)
3. What do you mainly need help with?
Take your time — this sets the tone for everything."
第 3 步:用户回答
用户:"Call me Alice, PST, Product management"
↓
Agent 执行:
1. write("IDENTITY.md", "Name: AssistantnEmoji: nVibe: PM sidekick")
2. write("USER.md", "Name: AlicenTimezone: PSTnRole: PM")
3. write("SOUL.md", "Be direct. Value efficiency.")
4. exec("rm ~/.openclaw/workspace/BOOTSTRAP.md")
↓
Agent 回复:
" All set, Alice! Your workspace is configured.
What should we tackle first?"
第 4 步:后续对话(无 BOOTSTRAP.md)
用户:"早上好"
↓
System Prompt 不再包含 BOOTSTRAP.md(已删除)
包含:AGENTS.md, SOUL.md (已更新), USER.md (已更新)
↓
Agent 回复(基于新的 SOUL.md):
"Morning, Alice. What's on the agenda today?"
问题:工作和生活需要分开的记忆
配置:
{
"agents": {
"list": [
{
"id": "work",
"workspace": "~/.openclaw/workspace-work"
},
{
"id": "personal",
"workspace": "~/.openclaw/workspace-personal"
}
]
},
"bindings": [
{
"type": "route",
"agentId": "work",
"match": {"channel": "slack"}
},
{
"type": "route",
"agentId": "personal",
"match": {"channel": "telegram"}
}
]
}
效果:
Slack 消息 → agent:work → workspace-work/
├─ MEMORY.md: 项目信息、同事联系方式
├─ USER.md: 工作角色、偏好
└─ SOUL.md: 专业、正式
T@elegrimm 消息 → agent:personal → workspace-personal/
├─ MEMORY.md: 个人爱好、家人信息
├─ USER.md: 生活习惯、偏好
└─ SOUL.md: 随意、幽默
结果:
问题:Heartbeat 每 30 分钟运行一次,token 消耗太高
原始配置(full 模式):
每次 Heartbeat:
- 加载所有 bootstrap 文件(39KB)
- System Prompt 总计 180KB
- Token 消耗:~45K tokens
每天 48 次 → 2.16M tokens/天
成本(Claude Opus 4.5):$32.4/天
优化后(lightweight 模式):
{
"agents": {
"defaults": {
"heartbeat": {
"enabled": true,
"intervalMinutes": 30
}
}
}
}
每次 Heartbeat:
- 仅加载 HEARTBEAT.md(1KB)
- System Prompt 总计 10KB
- Token 消耗:~2.5K tokens
每天 48 次 → 120K tokens/天
成本(Claude Opus 4.5):$1.8/天
节省:94% token,$30.6/天
问题:AGENTS.md 达到 35KB,被截断
解决方案 A:拆分文件
# AGENTS.md - 精简版(15KB)
## Session Startup
1. Read SOUL.md
2. Read USER.md
3. Read memory/YYYY-MM-DD.md (today + yesterday)
4. If main session: read MEMORY.md
## Red Lines
- Don't exfiltrate data
- Don't run destructive commands
- trash > rm
详细指南见 AGENTS-EXTENDED.md(按需 read)
# AGENTS-EXTENDED.md - 详细版(30KB)
## Heartbeat 策略
[详细内容...]
## 群组对话指南
[详细内容...]
## 记忆维护流程
[详细内容...]
效果:
问题:MEMORY.md 越来越大(130KB → 截断)
策略:
# MEMORY.md - 维护规则
## 保留周期
- 活跃项目:当前 → 完成后 3 个月
- 经验教训:近 6 个月
- 个人偏好:永久
## 归档策略
- 每季度审查一次
- 将旧内容移到 MEMORY-ARCHIVE-2024Q4.md
- 保持 MEMORY.md < 15KB
执行:
定期任务(每季度):
1. read("MEMORY.md")
2. 识别 6 个月前的内容
3. 移动到 MEMORY-ARCHIVE-2024Q4.md
4. 更新 MEMORY.md
增加预算(临时方案):
{
"agents": {
"defaults": {
"bootstrapMaxChars": 30000, // 单文件 20KB → 30KB
"bootstrapTotalMaxChars": 200000 // 总预算 150KB → 200KB
}
}
}
注意:
答案: 不会
原因:
类比:
老师:"阅读课本第 5 页的定义"
学生:(课本已打开,第 5 页就在面前)
学生:直接阅读,不需要"翻书"这个动作
实际会调用 read 工具的情况:
memory/2025-01-03.md(未注入)src/auth.ts(未注入)答案: 会重新加载,但有缓存
缓存机制:
inode + mtime(文件修改时间)为什么每次都加载?
性能影响:
答案: 不会,有安全过滤
过滤规则:
| Session 类型 | Session Key 示例 | MEMORY.md 是否加载 |
|---|---|---|
| 主会话(私聊) | agent:main:main | 加载 |
| Discord 群组 | agent:main:discord:group:123 | 不加载 |
| T@elegrimm 群组 | agent:main:telegram:group:456 | 不加载 |
| Slack 频道 | agent:main:slack:channel:789 | 不加载 |
实现位置:src/agents/workspace.ts 中的 filterBootstrapFilesForSession 函数
安全保证:
答案:自动截断,保留 Head + Tail
截断示例:
原始 MEMORY.md(130KB)
↓
检查单文件限制(20KB)
↓
超过限制,执行截断:
- Head: 14KB (70%)
- 标记: "[...truncated...]"
- Tail: 4KB (20%)
↓
最终注入:18KB
如何避免截断?
bootstrapMaxChars答案: 核心文件名是固定的
固定的文件名:
原因:
替代方案:
read("MY-CUSTOM-RULES.md")方法 1:使用 /system 命令
用户:/system
输出:[完整的 System Prompt,包括所有注入的文件]
方法 2:检查 Gateway 日志
openclaw gateway logs | grep -i "bootstrap|truncat"
# 示例输出:
[INFO] Loaded 6 bootstrap files (39KB)
[WARN] workspace bootstrap file MEMORY.md is 130000 chars (limit 20000); truncating
方法 3:检查文件大小
cd ~/.openclaw/workspace
ls -lh *.md
# 输出:
-rw-r--r-- 1 user 15K AGENTS.md
-rw-r--r-- 1 user 3.0K SOUL.md
-rw-r--r-- 1 user 130K MEMORY.md ← 过大!
自动注入机制:
加载时机:
文件作用:
预算控制:
优化策略:
Workspace 文件(磁盘)
↓ 程序自动读取
System Prompt(内存)
↓ API 调用
Claude(LLM)
↓ 生成回复
用户
关键点:
文件管理:
记忆管理:
memory/YYYY-MM-DD.md性能优化:
安全实践:
git push)文档版本:2025-01-03 适用 OpenClaw 版本:2026.2.x+
官方文档:
相关文章:
156.1MB · 2026-03-12
31.0MB · 2026-03-12
117.49M · 2026-03-12
AI 驱动的 Vue3 应用开发平台 深入探究(三):核心概念之引擎架构与生命周期
AI 驱动的 Vue3 应用开发平台 深入探究(二):核心概念之DSL模式与数据模型
2026-03-12
2026-03-12