self-reflection

TotalClaw 作者 totalclaw v1.0.0

定期对最近的会议进行自我反思。分析哪些进展顺利,哪些出了问题,并将简洁、可操作的见解写入适当的工作区文件。设计为作为 cron 作业运行。

安装 / 下载方式

TotalClaw CLI推荐
totalclaw skills install shop:totalclaw:totalclaw~brennerspear-agent-self-reflection
cURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~brennerspear-agent-self-reflection/file -o brennerspear-agent-self-reflection.md
# Self-Reflection Skill

Reflect on recent sessions and extract actionable insights. Runs hourly via cron.

## Step 1: Gather Recent Sessions

```bash
# List sessions active in the last 2 hours
openclaw sessions --active 120 --json
```

Parse the output to get session keys and IDs. Skip subagent sessions (they're task workers, not interesting for reflection). Focus on:
- Telegram group/topic sessions (real user interactions)
- Direct sessions (1:1 with Brenner)
- Cron-triggered sessions (how did automated tasks go?)

## Step 2: Read Session History

For each interesting session from Step 1, read the JSONL transcript:

```bash
# Read the last ~50 lines of each session file (keep it bounded!)
tail -50 ~/.openclaw/agents/main/sessions/<sessionId>.jsonl
```

**⚠️ CRITICAL: Never load full session files. Use `tail -50` or `Read` with offset/limit. Sessions can be 100k+ tokens.**

Parse the JSONL to understand what happened. Look for:
- `type: "user"` or `type: "human"` — what was asked
- `type: "assistant"` — what you responded
- `type: "tool_use"` / `type: "tool_result"` — what tools were called and results
- Error patterns, retries, confusion

## Step 3: Analyze & Extract Insights

For each session, ask yourself:

### What went well?
- Tasks completed smoothly on first try
- Good tool usage patterns worth reinforcing
- Efficient approaches to remember

### What went wrong?
- Errors, retries, wrong approaches
- Misunderstandings of user intent
- Tools that didn't work as expected
- Context that was missing

### Lessons learned?
- "Next time, do X instead of Y"
- "Remember that Z works this way"
- "Tool A needs parameter B or it fails"
- "When user says X, they usually mean Y"

**Quality bar:** Each insight must be:
- **Specific** — not "be more careful" but "check if file exists before editing"
- **Actionable** — something future-you can directly apply
- **Non-obvious** — skip things any competent agent would know
- **New** — don't repeat insights already captured

## Step 4: Route Insights to the Right Files

Each insight belongs somewhere specific. Route them:

### → `AGENTS.md`
- Process improvements (how to handle sessions, memory, etc.)
- New conventions or workflow rules
- Safety lessons

### → `TOOLS.md`
- Tool-specific gotchas ("gog needs --json flag for parsing")
- Environment details (paths, configs, quirks)
- New tool patterns discovered

### → `memory/YYYY-MM-DD.md` (today's date)
- Session-specific context ("Brenner asked about X project")
- Temporary facts that matter today but not forever
- What happened today (events, decisions, requests)

### → `memory/about-user.md`
- New preferences discovered
- Communication style observations
- Project/interest updates

### → `skills/<skill-name>/SKILL.md`
- Improvements to specific skill instructions
- Bug fixes in skill workflows
- New parameters or approaches for a skill

### → `MEMORY.md`
- Updates to the memory index if new memory files are created

## Step 5: Write the Insights

For each insight, append or edit the appropriate file. Use the `Edit` tool for surgical changes to existing content. Use append (write to end) for daily memory files.

**Format for daily memory files:**
```markdown
## Self-Reflection — HH:MM ET

### Insights
- [source: session-key] Lesson learned here
- [source: session-key] Another insight

### Tool Notes
- Discovered: tool X needs Y configuration

### User Context
- Brenner mentioned interest in Z
```

## Step 6: Summary

After writing all insights, produce a brief summary of what you reflected on and what you wrote. This is your output — keep it to 2-4 sentences max.

If there's nothing interesting to reflect on (quiet period, only heartbeats), just say so. Don't manufacture insights.

## Quality Checklist

Before writing any insight:
- [ ] Is this actually new? (Check existing files first)
- [ ] Is this specific and actionable?
- [ ] Am I routing it to the right file?
- [ ] Am I keeping daily memory files concise (not dumping full transcripts)?
- [ ] Did I respect the token budget (no huge file reads)?

## Anti-Patterns (Don't Do These)

- ❌ Don't summarize every session — only extract *lessons*
- ❌ Don't read full JSONL files — tail/limit only
- ❌ Don't write vague insights ("improve response quality")
- ❌ Don't duplicate existing knowledge
- ❌ Don't create new files when appending to existing ones works
- ❌ Don't reflect on your own reflection sessions (skip cron:self-reflection sessions)

---

## 中文说明

# 自我反思技能

对最近的会话进行反思,并提取可操作的见解。通过 cron 每小时运行一次。

## 步骤 1:收集最近的会话

```bash
# List sessions active in the last 2 hours
openclaw sessions --active 120 --json
```

解析输出以获取会话键和 ID。跳过子代理会话(它们是任务工作进程,对反思没有意义)。重点关注:
- Telegram 群组/话题会话(真实的用户交互)
- 直接会话(与 Brenner 一对一)
- Cron 触发的会话(自动化任务进行得如何?)

## 步骤 2:读取会话历史

对步骤 1 中每个值得关注的会话,读取其 JSONL 记录:

```bash
# Read the last ~50 lines of each session file (keep it bounded!)
tail -50 ~/.openclaw/agents/main/sessions/<sessionId>.jsonl
```

**⚠️ 关键:切勿加载完整的会话文件。使用 `tail -50` 或带 offset/limit 的 `Read`。会话可能超过 10 万 token。**

解析 JSONL 以理解发生了什么。查找:
- `type: "user"` 或 `type: "human"` —— 被问了什么
- `type: "assistant"` —— 你如何回应
- `type: "tool_use"` / `type: "tool_result"` —— 调用了哪些工具以及结果
- 错误模式、重试、困惑

## 步骤 3:分析并提取见解

对每个会话,问自己:

### 哪些进展顺利?
- 第一次尝试就顺利完成的任务
- 值得强化的良好工具使用模式
- 值得记住的高效做法

### 哪些出了问题?
- 错误、重试、错误的做法
- 对用户意图的误解
- 未按预期工作的工具
- 缺失的上下文

### 学到了什么教训?
- "下次做 X 而不是 Y"
- "记住 Z 是这样工作的"
- "工具 A 需要参数 B,否则会失败"
- "当用户说 X 时,他们通常指的是 Y"

**质量标准:** 每条见解必须做到:
- **具体** —— 不是"要更小心",而是"编辑前检查文件是否存在"
- **可操作** —— 未来的你可以直接应用的内容
- **非显而易见** —— 跳过任何有能力的代理都已知的内容
- **新颖** —— 不要重复已经记录过的见解

## 步骤 4:将见解路由到正确的文件

每条见解都归属于某个特定位置。将它们路由到:

### → `AGENTS.md`
- 流程改进(如何处理会话、记忆等)
- 新的约定或工作流规则
- 安全教训

### → `TOOLS.md`
- 特定工具的注意事项("gog 需要 --json 标志才能解析")
- 环境细节(路径、配置、怪癖)
- 发现的新工具模式

### → `memory/YYYY-MM-DD.md`(今天的日期)
- 会话特定的上下文("Brenner 询问了 X 项目")
- 今天重要但并非永久重要的临时事实
- 今天发生了什么(事件、决策、请求)

### → `memory/about-user.md`
- 发现的新偏好
- 沟通风格的观察
- 项目/兴趣的更新

### → `skills/<skill-name>/SKILL.md`
- 对特定技能说明的改进
- 技能工作流中的 bug 修复
- 某项技能的新参数或新做法

### → `MEMORY.md`
- 如果创建了新的记忆文件,则更新记忆索引

## 步骤 5:写入见解

对每条见解,追加或编辑相应的文件。使用 `Edit` 工具对现有内容进行精确修改。对每日记忆文件使用追加(写到末尾)。

**每日记忆文件的格式:**
```markdown
## Self-Reflection — HH:MM ET

### Insights
- [source: session-key] Lesson learned here
- [source: session-key] Another insight

### Tool Notes
- Discovered: tool X needs Y configuration

### User Context
- Brenner mentioned interest in Z
```

## 步骤 6:总结

写完所有见解后,简要总结你反思了什么、写了什么。这就是你的输出 —— 最多保持在 2-4 句话以内。

如果没有值得反思的内容(安静时段,只有心跳),就直接说明。不要硬造见解。

## 质量检查清单

在写入任何见解之前:
- [ ] 这真的是新的吗?(先检查现有文件)
- [ ] 它是否具体且可操作?
- [ ] 我是否把它路由到了正确的文件?
- [ ] 我是否让每日记忆文件保持简洁(而不是倾倒完整记录)?
- [ ] 我是否尊重了 token 预算(没有读取巨大的文件)?

## 反模式(不要做这些)

- ❌ 不要总结每个会话 —— 只提取*教训*
- ❌ 不要读取完整的 JSONL 文件 —— 仅使用 tail/limit
- ❌ 不要写模糊的见解("提升回复质量")
- ❌ 不要重复已有的知识
- ❌ 当追加到现有文件即可时,不要创建新文件
- ❌ 不要反思你自己的反思会话(跳过 cron:self-reflection 会话)