Reflect:AI 智能体自我进化与持续学习 - Openclaw Skills

作者:互联网

2026-04-13

AI教程

什么是 Reflect?

Reflect 践行“一次纠正,终身受益”的理念,将您的 AI 助手从静态工具转变为持续进化的伙伴。通过分析用户反馈、纠正信号和成功模式,这一 Openclaw Skills 插件确保您的智能体能从每次交互中学习,有效减少重复性错误,并根据您的特定项目需求量身定制行为。

该技能弥补了短期会话上下文与长期行为演变之间的鸿沟。它充当桥梁,将修正意见合成为持久指令,并延续到未来的所有会话中。对于希望通过 Openclaw Skills 获得真正个性化 AI 编程体验的开发者来说,它是必不可少的组件。

下载入口:https://github.com/openclaw/skills/tree/main/skills/stevengonsalvez/self-reflect

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install self-reflect

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 self-reflect。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Reflect 应用场景

  • 在完成复杂的开发任务后,保存成功的模式和逻辑。
  • 当用户使用“永远不要做 X”或“务必做 Y”等指令明确纠正智能体行为时。
  • 在会话结束或上下文压缩之前,确保关键见解不会丢失。
  • 当发现非显而易见的调试方案时,将其保存为新的 Openclaw Skills 以供将来使用。
Reflect 工作原理
  1. 扫描对话历史,寻找诸如“从不”、“总是”或“精确”等高置信度信号,以识别学习机会。
  2. 将检测到的信号分类为代码风格、架构、流程或工具等类别。
  3. 将学习成果与特定的智能体文件匹配,或确定该模式是否值得创建一个全新的技能。
  4. 生成结构化提案和差异对比(diff),精确显示将对智能体定义进行的更改。
  5. 通过人工干预的审查流程将批准的更改应用到相关文件中,以确保安全性和准确性。

Reflect 配置指南

要将 Reflect 集成到您的环境中,请按照以下步骤确保您的 Openclaw Skills 配置正确:

# 创建所需的各种状态目录
mkdir -p ~/.reflect

# (可选)设置自定义状态目录路径
export REFLECT_STATE_DIR="~/.reflect"

目录准备就绪后,您可以在任何会话期间使用 reflect 命令触发该技能。它将自动开始扫描当前上下文中的改进信号。

Reflect 数据架构与分类体系

Reflect 在全局和项目特定位置管理数据,以确保您的学习成果在 Openclaw Skills 生态系统中持久且可移植。

位置 文件类型 描述
~/.reflect/learnings.yaml YAML 所有捕获的学习成果和纠正的全局日志。
~/.reflect/reflect-metrics.yaml YAML 聚合指标,包括采纳率和更新次数。
.claude/reflections/ Markdown 记录每次反思会话的项目级日志。
.claude/skills/ Markdown 从复杂的、可重用的模式中生成的新技能定义。
name: reflect
description: Self-improvement through conversation analysis. Extracts learnings from corrections and success patterns, permanently encoding them into agent definitions. Philosophy - Correct once, never again.
version: "2.0.0"
user-invocable: true
triggers:
  - reflect
  - self-reflect
  - review session
  - what did I learn
  - extract learnings
  - analyze corrections
allowed-tools:
  - Read
  - Write
  - Edit
  - Grep
  - Glob
  - Bash
metadata:
  clawdbot:
    emoji: "??"
    config:
      stateDirs: ["~/.reflect"]

Reflect - Agent Self-Improvement Skill

Transform your AI assistant into a continuously improving partner. Every correction becomes a permanent improvement that persists across all future sessions.

Quick Reference

Command Action
reflect Analyze conversation for learnings
reflect on Enable auto-reflection
reflect off Disable auto-reflection
reflect status Show state and metrics
reflect review Review pending learnings

When to Use

  • After completing complex tasks
  • When user explicitly corrects behavior ("never do X", "always Y")
  • At session boundaries or before context compaction
  • When successful patterns are worth preserving

Workflow

Step 1: Scan Conversation for Signals

Analyze the conversation for correction signals and learning opportunities.

Signal Confidence Levels:

Confidence Triggers Examples
HIGH Explicit corrections "never", "always", "wrong", "stop", "the rule is"
MEDIUM Approved approaches "perfect", "exactly", "that's right", accepted output
LOW Observations Patterns that worked but not explicitly validated

See signal_patterns.md for full detection rules.

Step 2: Classify & Match to Target Files

Map each signal to the appropriate target:

Category Target Files
Code Style code-reviewer, backend-developer, frontend-developer
Architecture solution-architect, api-architect, architecture-reviewer
Process CLAUDE.md, orchestrator agents
Domain Domain-specific agents, CLAUDE.md
Tools CLAUDE.md, relevant specialists
New Skill Create new skill file

See agent_mappings.md for mapping rules.

Step 3: Check for Skill-Worthy Signals

Some learnings should become new skills rather than agent updates:

Skill-Worthy Criteria:

  • Non-obvious debugging (>10 min investigation)
  • Misleading error (root cause different from message)
  • Workaround discovered through experimentation
  • Configuration insight (differs from documented)
  • Reusable pattern (helps in similar situations)

Quality Gates (must pass all):

  • Reusable: Will help with future tasks
  • Non-trivial: Requires discovery, not just docs
  • Specific: Can describe exact trigger conditions
  • Verified: Solution actually worked
  • No duplication: Doesn't exist already

Step 4: Generate Proposals

Present findings in structured format:

# Reflection Analysis

## Session Context
- **Date**: [timestamp]
- **Messages Analyzed**: [count]

## Signals Detected

| # | Signal | Confidence | Source Quote | Category |
|---|--------|------------|--------------|----------|
| 1 | [learning] | HIGH | "[exact words]" | Code Style |

## Proposed Changes

### Change 1: Update [agent-name]
**Target**: `[file path]`
**Section**: [section name]
**Confidence**: HIGH

```diff
+ New rule from learning

Review Prompt

Apply these changes? (Y/N/modify/1,2,3)


### Step 5: Apply with User Approval

**On `Y` (approve):**
1. Apply each change using Edit tool
2. Commit with descriptive message
3. Update metrics

**On `N` (reject):**
1. Discard proposed changes
2. Log rejection for analysis

**On `modify`:**
1. Present each change individually
2. Allow editing before applying

**On selective (e.g., `1,3`):**
1. Apply only specified changes
2. Commit partial updates

## State Management

State is stored in `~/.reflect/` (configurable via `REFLECT_STATE_DIR`):

```yaml
# reflect-state.yaml
auto_reflect: false
last_reflection: "2026-01-26T10:30:00Z"
pending_reviews: []

Metrics Tracking

# reflect-metrics.yaml
total_sessions_analyzed: 42
total_signals_detected: 156
total_changes_accepted: 89
acceptance_rate: 78%
confidence_breakdown:
  high: 45
  medium: 32
  low: 12
most_updated_agents:
  code-reviewer: 23
  backend-developer: 18
skills_created: 5

Safety Guardrails

Human-in-the-Loop

  • NEVER apply changes without explicit user approval
  • Always show full diff before applying
  • Allow selective application

Incremental Updates

  • ONLY add to existing sections
  • NEVER delete or rewrite existing rules
  • Preserve original structure

Conflict Detection

  • Check if proposed rule contradicts existing
  • Warn user if conflict detected
  • Suggest resolution strategy

Output Locations

Project-level (versioned with repo):

  • .claude/reflections/YYYY-MM-DD_HH-MM-SS.md - Full reflection
  • .claude/skills/{name}/SKILL.md - New skills

Global (user-level):

  • ~/.reflect/learnings.yaml - Learning log
  • ~/.reflect/reflect-metrics.yaml - Aggregate metrics

Examples

Example 1: Code Style Correction

User says: "Never use var in TypeScript, always use const or let"

Signal detected:

  • Confidence: HIGH (explicit "never" + "always")
  • Category: Code Style
  • Target: frontend-developer.md

Proposed change:

## Style Guidelines
+ * Use `const` or `let` instead of `var` in TypeScript

Example 2: Process Preference

User says: "Always run tests before committing"

Signal detected:

  • Confidence: HIGH (explicit "always")
  • Category: Process
  • Target: CLAUDE.md

Proposed change:

## Commit Hygiene
+ * Run test suite before creating commits

Example 3: New Skill from Debugging

Context: Spent 30 minutes debugging a React hydration mismatch

Signal detected:

  • Confidence: HIGH (non-trivial debugging)
  • Category: New Skill
  • Quality gates: All passed

Proposed skill: react-hydration-fix/SKILL.md

Troubleshooting

No signals detected:

  • Session may not have had corrections
  • Check if using natural language corrections

Conflict warning:

  • Review the existing rule cited
  • Decide if new rule should override
  • Can modify before applying

Agent file not found:

  • Check agent name spelling
  • May need to create agent file first

相关推荐