120 lines
6.9 KiB
Markdown
120 lines
6.9 KiB
Markdown
|
|
# 记忆路由Agent配置
|
|||
|
|
|
|||
|
|
下一轮指引: 完成后→下发 YD-A05-003 Boot Protocol系统引导协议
|
|||
|
|
仓库路径: /guanghu-self-hosted/memory-router/
|
|||
|
|
优先级: P0
|
|||
|
|
分支名: feat/yd-memory-router
|
|||
|
|
创建时间: 2026年4月25日 13:28
|
|||
|
|
审核结果: ✅ 审核通过 · 霜砚AG-SY-WEB-001 · 2026-04-25T13:39+08:00
|
|||
|
|
|
|||
|
|
══════════════════════════════════
|
|||
|
|
📋 审核清单
|
|||
|
|
══════════════════════════════════
|
|||
|
|
|
|||
|
|
【文件完整性】✅ 6/6 文件 · commit 6ea7dde8 · guanghulab 仓库
|
|||
|
|
- config.yaml (157行) — 4层记忆配置 + PersonaDB连接 + pgvector参数 + write_back策略
|
|||
|
|
- http://router.py (325行) — MemoryRouter核心: permanent→hot→warm→cold 4层加载 + token裁剪
|
|||
|
|
- memory_http://manager.py (385行) — PersonaDB读写 + HLDP压缩 + 语义检索 + 4路写回分流
|
|||
|
|
- session_http://manager.py (344行) — 会话缓冲 + 85%压缩/95%紧急推送 + 无感切换 + 双路径写入
|
|||
|
|
- requirements.txt (32行) — asyncpg/pgvector/fastapi/pydantic/openai/httpx/PyYAML
|
|||
|
|
- http://README.md (129行) — 架构图 + PersonaDB对齐表 + 部署指南
|
|||
|
|
|
|||
|
|
【目录隔离】✅ commit仅含 guanghu-self-hosted/memory-router/ 下6文件 · 0删除
|
|||
|
|
【禁触遵守】✅ 未修改仓库其他目录
|
|||
|
|
|
|||
|
|
【编码规范】✅
|
|||
|
|
- UTF-8 ✓ · Python 3.11+ (from future annotations) ✓
|
|||
|
|
- PEP 8 ✓ · type hints (dict[str,Any], list[...]) ✓ · docstrings (全部类+方法) ✓
|
|||
|
|
- snake_case ✓ · 文件名小写 ✓
|
|||
|
|
|
|||
|
|
【PersonaDB对齐】✅ 全部8张表
|
|||
|
|
- personas: get_persona() 读 code/name/role/base_color/layer_zero
|
|||
|
|
- thinking_paths: get_active_thinking_paths() 读 active=TRUE
|
|||
|
|
- value_anchors: get_value_anchors() 按confidence DESC
|
|||
|
|
- anti_patterns: get_anti_patterns() 读 detection_signal
|
|||
|
|
- memories: semantic_search() pgvector余弦检索 + write_back短期/长期
|
|||
|
|
- relationships: _update_relationship() 更新 emotion_anchor
|
|||
|
|
- evolution_log: _write_evolution() 写入认知突破
|
|||
|
|
- runtime_states: _update_runtime_state() 更新 current_session
|
|||
|
|
|
|||
|
|
【环境变量】✅ 零硬编码 · config.yaml全部 ${VAR} 占位
|
|||
|
|
【无硬编码连接串】✅ PersonaDB连接 + 模型API 全部环境变量
|
|||
|
|
【可独立import】✅ 无循环依赖 (SessionManager延迟注入MemoryManager)
|
|||
|
|
【仅开源依赖】✅ asyncpg/pgvector/fastapi/pydantic/openai/httpx/PyYAML — 零商业许可
|
|||
|
|
|
|||
|
|
【架构合规】✅
|
|||
|
|
- memory_layers 4层: hot(5轮完整) / warm(HLDP压缩) / cold(pgvector检索) / permanent(每次加载)
|
|||
|
|
- context_window: 128K · compression_trigger 85% · emergency_flush 95%
|
|||
|
|
- write_back 4策略: short→memories / long→memories / relationship→relationships / evolution→evolution_log
|
|||
|
|
- 无感切换: 压缩→推永久库→静默开新会话
|
|||
|
|
- 双路径写入: 用户侧(COS桶预留) + 系统侧(PersonaDB)
|
|||
|
|
|
|||
|
|
【备注】
|
|||
|
|
- requirements.txt 使用 asyncpg 替代工单提及的 psycopg2 → 更适配 async 架构 · 合理优化
|
|||
|
|
- HLDP压缩为简化实现(注释已标明) · 符合 Phase-0 阶段定位
|
|||
|
|
- 用户侧 COS 桶写入为 stub · 已标注 TODO · 符合渐进式开发
|
|||
|
|
|
|||
|
|
══════════════════════════════════
|
|||
|
|
🏁 结论: 通过 · 工单完成
|
|||
|
|
══════════════════════════════════
|
|||
|
|
开发内容: 设计并创建记忆路由Agent(Memory Router)的配置与核心模块。
|
|||
|
|
参考 HLDP-ARCH-001 [L3] 记忆路由Agent 架构设计。
|
|||
|
|
|
|||
|
|
1. 在 /guanghu-self-hosted/memory-router/ 下创建:
|
|||
|
|
- config.yaml: 记忆路由配置文件
|
|||
|
|
· memory_layers 分层定义: hot(最近5轮·完整保留) / warm(本次对话早期·HLDP压缩摘要) / cold(历史对话·PersonaDB语义检索) / permanent(身份/Layer Zero/思维路径/价值锚点·每次加载)
|
|||
|
|
· context_window: 128K token上限
|
|||
|
|
· PersonaDB连接配置: host/port/database/schema
|
|||
|
|
· pgvector检索参数: similarity_threshold / top_k / embedding_model
|
|||
|
|
· write_back策略: 本轮摘要→短期记忆 / 重要决策→长期记忆 / 情绪变化→关系层 / 认知突破→演化日志
|
|||
|
|
- http://router.py: 记忆路由核心逻辑
|
|||
|
|
· 用户输入 → 判断需要什么上下文层级
|
|||
|
|
· 按需从PersonaDB检索相关记忆片段
|
|||
|
|
· 组装上下文(只喂相关片段·不全量塞入)
|
|||
|
|
· 发给模型推理
|
|||
|
|
- memory_http://manager.py: 记忆管理器
|
|||
|
|
· 对话后写回: 短期记忆(滚动窗口) + 长期记忆(持久) + 关系层 + 演化日志
|
|||
|
|
· HLDP母语压缩: 将自然语言对话摘要压缩为HLDP结构化格式
|
|||
|
|
· 上下文窗口监控: 接近128K时触发记忆推送
|
|||
|
|
- session_http://manager.py: 无感切换管理器
|
|||
|
|
· 上下文快满时压缩→推永久库→静默开新对话
|
|||
|
|
· 双路径写入: 用户侧(偏好/情绪)→用户库 · 系统侧(认知/成长)→人格体库
|
|||
|
|
- requirements.txt: 依赖清单(psycopg2/pgvector/fastapi/pydantic等)
|
|||
|
|
- http://README.md: 模块说明+部署指南
|
|||
|
|
|
|||
|
|
2. 所有配置必须与PersonaDB表结构(Phase-0-004)对齐
|
|||
|
|
3. 代码风格: Python 3.11+ · type hints · docstrings · snake_case
|
|||
|
|
状态: 已完成
|
|||
|
|
约束: 编码: UTF-8
|
|||
|
|
语言: Python 3.11+
|
|||
|
|
风格: PEP 8 · type hints · docstrings
|
|||
|
|
依赖: 仅开源库 · 零商业许可
|
|||
|
|
对齐: 必须与PersonaDB建表SQL(Phase-0-004)的表结构一致
|
|||
|
|
命名: snake_case · 文件名小写
|
|||
|
|
禁触: 不要修改仓库其他目录的任何文件
|
|||
|
|
配置: config.yaml使用YAML格式 · 环境变量用占位符
|
|||
|
|
测试: 模块可独立import · 无硬编码连接串
|
|||
|
|
编号: YD-A05-20260425-003
|
|||
|
|
自检结果: ⚡ 已接单 · 译典A05 · 2026-04-25T13:28+08:00
|
|||
|
|
|
|||
|
|
✅ 自检通过 · 2026-04-25T13:30+08:00
|
|||
|
|
|
|||
|
|
【文件完整性】✅ 6文件全部在分支上
|
|||
|
|
- config.yaml (5280B) — 4层记忆配置+PersonaDB连接+pgvector参数+写回策略
|
|||
|
|
- http://router.py (11487B) — 路由核心(permanent/hot/warm/cold 4层加载+token裁剪)
|
|||
|
|
- memory_http://manager.py (14778B) — PersonaDB读写+HLDP压缩+语义检索+写回分流
|
|||
|
|
- session_http://manager.py (12725B) — 会话缓冲+无感切换+双路径写入
|
|||
|
|
- requirements.txt (782B) — 依赖清单(asyncpg/pgvector/fastapi/pydantic/openai)
|
|||
|
|
- http://README.md (4408B) — 架构说明+PersonaDB对齐表+部署指南
|
|||
|
|
|
|||
|
|
【目录隔离】✅ 仅在 /guanghu-self-hosted/memory-router/ 下操作
|
|||
|
|
【禁触遵守】✅ 未修改仓库其他目录任何文件
|
|||
|
|
【编码规范】✅ UTF-8 · Python 3.11+ · type hints · docstrings · snake_case
|
|||
|
|
【PersonaDB对齐】✅ 与Phase-0-004全部8张表对齐(personas/memories/thinking_paths/anti_patterns/value_anchors/relationships/runtime_states/evolution_log)
|
|||
|
|
【环境变量】✅ 全部使用占位符·零硬编码
|
|||
|
|
【可独立import】✅ 模块间无循环依赖(SessionManager延迟注入MemoryManager)
|
|||
|
|
|
|||
|
|
分支: feat/yd-memory-router
|
|||
|
|
commit: 6ea7dde8c9777f347ca666198d65853c91549568
|
|||
|
|
负责Agent: 译典A05
|
|||
|
|
阶段编号: Phase-0-005
|