Files
zclaw_openfang/docs/features/02-intelligence-layer/01-identity-evolution.md
iven 6c64d704d7
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
docs: add self-evolution documentation and fix SOUL.md persistence
- Create 01-identity-evolution.md: Identity system architecture (SOUL.md, USER.md, change proposals, version management)
- Create 04-heartbeat-engine.md: Proactive behavior system (heartbeat config, alerts, proactivity levels)
- Create 06-context-compaction.md: Context compression system (token management, summarization, information retention)
- Update ZCLAW_AGENT_INTELLIGENCE_EVOLUTION.md: Add Phase 5 self-evolution UX roadmap
- Fix AgentOnboardingWizard: Persist SOUL.md and USER.md after agent creation
- Fix llm-service: Add Tauri kernel mode detection for memory system LLM calls
- Fix kernel: Kernel config takes priority over agent's persisted model

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 00:38:31 +08:00

221 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 身份演化系统 (Identity Evolution)
> **成熟度**: L4 - 生产
> **最后更新**: 2026-03-24
> **负责人**: Intelligence Layer Team
## 概述
身份演化系统是 ZCLAW 自我进化能力的核心,让 Agent 能够:
1. **定义人格** - 通过 SOUL.md 定义核心特质
2. **演化人格** - 基于对话反思自动改进
3. **版本管理** - 跟踪人格变更历史,支持回滚
---
## 核心概念
### 身份文件 (Identity Files)
每个 Agent 有三个核心身份文件:
| 文件 | 用途 | 示例内容 |
|------|------|----------|
| `soul` (SOUL.md) | Agent 人格定义 | 核心特质、沟通风格、专业领域 |
| `instructions` | 行为指令集 | 执行规则、约束条件 |
| `user_profile` (USER.md) | 用户画像 | 用户偏好、角色、场景 |
### 身份变更提案 (Identity Change Proposal)
```typescript
interface IdentityChangeProposal {
id: string;
agent_id: string;
file: 'soul' | 'instructions' | 'user_profile';
current_content: string;
proposed_content: string;
diff: string; // Unified diff
reason: string; // AI 生成的变更原因
status: 'pending' | 'approved' | 'rejected';
created_at: string;
}
```
---
## 技术实现
### 核心文件
| 文件 | 用途 |
|------|------|
| `desktop/src/lib/intelligence-client.ts` | 前端身份 API 客户端 |
| `desktop/src/lib/intelligence-backend.ts` | 身份管理后端实现 |
| `desktop/src/lib/personality-presets.ts` | 人格预设和 SOUL.md 生成 |
| `desktop/src/components/AgentOnboardingWizard.tsx` | 引导向导,创建时持久化 SOUL.md |
### API 接口
```typescript
// intelligence-client.ts
identity: {
// 获取 Agent 的所有身份文件
get(agentId: string): Promise<IdentityFiles>;
// 读取单个文件内容
readFile(agentId: string, file: string): Promise<string>;
// 更新文件内容(自动创建快照)
updateFile(agentId: string, file: string, content: string): Promise<void>;
// 构建完整的人格 Prompt
buildPrompt(agentId: string, memoryContext?: string): Promise<string>;
// 变更提案
proposeChange(proposal: Omit<IdentityChangeProposal, 'id' | 'status' | 'created_at'>): Promise<IdentityChangeProposal>;
getProposals(): Promise<IdentityChangeProposal[]>;
approveProposal(proposalId: string): Promise<IdentityFiles>;
rejectProposal(proposalId: string): Promise<void>;
// 版本管理
getSnapshots(agentId: string, limit?: number): Promise<IdentitySnapshot[]>;
restoreSnapshot(agentId: string, snapshotId: string): Promise<IdentityFiles>;
}
```
### SOUL.md 生成
```typescript
// personality-presets.ts
export function generateSoulContent(config: {
agentName: string;
emoji?: string;
personality?: string; // professional | friendly | creative | concise
scenarios?: string[]; // coding, writing, product, data, design...
communicationStyle?: string;
}): string;
```
生成的 SOUL.md 包含:
- 核心特质(基于人格预设)
- 沟通风格
- 专业领域
- 边界约束
- 语气设定
---
## 数据流
### 创建时持久化
```
AgentOnboardingWizard
├── createClone() → 创建 Agent
├── generateSoulContent() → 生成 SOUL.md
├── generateUserContent() → 生成 USER.md
└── identity.updateFile() → 持久化到存储
```
### 演化流程
```
对话历史
反思引擎 (Reflection Engine)
├── 分析对话模式
├── 识别人格改进点
identity.proposeChange() → 创建变更提案
用户审批 UI
├── approveProposal() → 应用变更
│ │
│ └── 创建快照
└── rejectProposal() → 丢弃提案
```
---
## 人格预设
| ID | 名称 | 特质 |
|----|------|------|
| `professional` | 专业严谨 | 严谨分析、准确执行、专业术语、结构化输出 |
| `friendly` | 友好亲切 | 热情回应、通俗易懂、主动关怀、耐心解答 |
| `creative` | 创意灵活 | 创新思维、多角度探索、灵活应变、突破常规 |
| `concise` | 简洁高效 | 直击要点、快速响应、高效执行、精炼表达 |
---
## 使用场景
### 场景 1首次创建 Agent
1. 用户通过 AgentOnboardingWizard 创建 Agent
2. 选择人格预设和使用场景
3. 系统自动生成 SOUL.md 和 USER.md
4. 持久化到身份存储
### 场景 2基于反思的人格演化
1. Agent 进行多轮对话
2. 反思引擎分析对话模式
3. 发现用户偏好(如"不要那么啰嗦"
4. 生成人格变更提案
5. 用户审批后更新 SOUL.md
### 场景 3回滚到之前版本
1. 用户觉得新人格不合适
2. 查看演化历史
3. 选择之前的快照
4. 一键恢复
---
## 集成点
| 组件 | 集成方式 |
|------|----------|
| **RightPanel** | 显示身份文件内容、变更提案 |
| **ReflectionEngine** | 触发人格变更提案 |
| **AutonomyManager** | 审批自主级别下的自动变更 |
| **ChatStore** | 使用 `buildPrompt()` 构建系统提示 |
---
## 限制与未来改进
### 当前限制
1. **前端回滚 UI 未实现** - `getSnapshots()``restoreSnapshot()` API 存在但无 UI
2. **变更提案通知缺失** - 提案创建后无主动通知用户
3. **Tauri 模式下文件存储** - 当前使用内存存储,重启后丢失
### 未来改进
1. **文件系统持久化** - 将身份文件写入 `~/.zclaw/agents/{agentId}/`
2. **变更提案通知** - 添加桌面通知或消息提示
3. **人格版本对比** - 可视化 diff 显示变更内容
4. **多人格切换** - 支持同一 Agent 保存多套人格配置
---
## 相关文档
- [00-agent-memory.md](./00-agent-memory.md) - 记忆系统
- [03-reflection-engine.md](./03-reflection-engine.md) - 反思引擎
- [05-autonomy-manager.md](./05-autonomy-manager.md) - 自主授权