Source snapshot: 97d7f0fae96dc04b7ddad56fc1db6a108ed662cc [SEC-CLEAN] · pre-push-clean v1.0 · 109处敏感信息已自动转乱码
3.5 KiB
3.5 KiB
📡 铸渊指令|persona-studio v1.1-B · 记忆层(200k上下文 + 记忆注入Agent)
签发:曜冥 × 冰朔 · 2026-03-11 · 执行者:铸渊
仓库:
https://github.com/qinfendebingshuo/guanghulab(主仓库)
优先级:P0 · Phase A(最优先)
③ 对话上下文扩展到 200k
改动点
model-config.json新增:"context_window_target": 200000persona-engine.js:调用模型时设置 max_context 参数为200kmodel-router.js:评测时新增context_window维度,路由策略优先选200k+模型- 如果所有模型 < 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 结构
{
"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)
{
"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