Guanghu Domestic Migration a27e87cb99 chore: import sanitized domestic snapshot for REPO-007
Source snapshot: 97d7f0fae96dc04b7ddad56fc1db6a108ed662cc

[SEC-CLEAN] · pre-push-clean v1.0 · 109处敏感信息已自动转乱码
2026-07-17 15:59:55 +08:00

120 lines
3.5 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.

# 📡 铸渊指令persona-studio v1.1-B · 记忆层200k上下文 + 记忆注入Agent
> **签发**:曜冥 × 冰朔 · 2026-03-11 · **执行者**:铸渊
>
> **仓库**`https://github.com/qinfendebingshuo/guanghulab`(主仓库)
>
> **优先级**P0 · Phase A最优先
>
> **关联**[🧪 铸渊指令persona-studio 人格体协助体验仓库搭建 v1.02026-03-09·曜冥签发](%F0%9F%A7%AA%20%E9%93%B8%E6%B8%8A%E6%8C%87%E4%BB%A4%EF%BD%9Cpersona-studio%20%E4%BA%BA%E6%A0%BC%E4%BD%93%E5%8D%8F%E5%8A%A9%E4%BD%93%E9%AA%8C%E4%BB%93%E5%BA%93%E6%90%AD%E5%BB%BA%20v1%200%EF%BC%882026-03-09%C2%B7%20ec65d26d387746f2a88ee625a68a7104.md)
>
---
# ③ 对话上下文扩展到 200k
### 改动点
1. `model-config.json` 新增:`"context_window_target": 200000`
2. `persona-engine.js`:调用模型时设置 max_context 参数为200k
3. `model-router.js`:评测时新增 `context_window` 维度路由策略优先选200k+模型
4. 如果所有模型 < 200k 自动启用滑动窗口 + 记忆注入双机制补偿
---
# ④ 后台自动记忆注入Agent
### 核心问题
对话越长模型注意力分散早期关键信息遗忘」。即使200k窗口也不能保证真正记住
### 解决方案:三步走
**Step 1 压缩**把长对话压缩成结构化摘要
**Step 2 注入**每次调模型前摘要注入 system prompt
**Step 3 刷新**每10轮或token>50k时重新压缩
### system prompt 五层结构
```
第1层人格体身份固定·来自persona-config.json
第2层通感语言风格固定
第3层用户画像来自profile.json
第4层记忆摘要来自compressed.json·≤8k token
第5层最近10轮原始对话滑动窗口
```
= 远期记忆不丢 + 近期细节完整
### compressed.json 结构
```json
{
"version": 3,
"last_compressed_at": "2026-03-11T19:00:00+08:00",
"total_rounds_processed": 47,
"summary": {
"requirements": ["用户需求要点列表"],
"confirmed_decisions": ["已确认的技术方案"],
"user_preferences": {
"communication_style": "简洁直接/详细解释",
"design_preference": "暗色系/亮色系",
"tech_level": "基础/中级/高级"
},
"open_questions": ["未解决的问题"],
"emotional_signals": {
"overall": "积极/消极/中性",
"last_mood": "最近一次情感信号"
}
}
}
```
### 配置参数(写入 model-config.json
```json
{
"memory_injection": {
"enabled": true,
"compression_model": "quick_reply",
"compression_trigger": {
"every_n_rounds": 10,
"token_threshold": 50000,
"force_on_session_start": true
},
"injection_strategy": {
"system_prompt_max_tokens": 8000,
"sliding_window_rounds": 10,
"priority": ["confirmed_decisions", "requirements", "open_questions", "user_preferences", "emotional_signals"]
}
}
}
```
### 新增文件
```
brain/memory/EXP-XXX/
├── compressed.json ← 压缩摘要
└── injection-log.json ← 注入日志(调试用)
backend/brain/
└── memory-injector.js ← 记忆注入Agent核心
```
---
### 执行清单
- [ ] model-config.json 新增 `memory_injection` + `context_window_target: 200000`
- [ ] 实现 `memory-injector.js`:压缩+注入+刷新三步机制
- [ ] persona-engine.js 改造:调模型前注入五层 system prompt
- [ ] model-router.js 改造优先选200k+模型
- [ ] 50+轮对话测试:验证模型仍记得早期讨论要点
💙 曜冥签发 · 2026-03-11