mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-21 09:28:14 +00:00
按用户指出的关键点(a.memory 多数使用点属"主 agent 整理记忆"与"记忆整理流水线", 子不该有那些路径)实现,方案见设计 §16.0。 ## 窄接口:只有 Recall + Commit 新增 `GraphMemory` 接口(memoryface.go)—— 按调用方实测分类后,真正"根与子都要"的只有这两个: - `Recall`:上下文检索 / memory_recall - `Commit`:自动写入路径的图部分 / memory_commit 新增 `Agent.graph`(共同面)与 `Agent.graphMem()` 访问器: - `graph` 显式为 nil 时**回落**到 `memory` ⇒ 既有"只用 Agent 字面量设 memory"的测试无需改动 (原本会出现"必须同时设两个字段"的脚坑,实测踩到后去掉了) - 轻量内核:`graph = *memory.LightMemory`,`memory = nil` ## nil 即禁用:整理面自动消失,不需要受限包装 子的 `a.memory == nil` ⇒ 既有的 22 处 `if a.memory != nil` 关卡自动禁掉全部整理面: - 记忆整理流水线(distill.go 的 archive/review/merge 循环) - 记忆块 + 媒体桥(graphmedia.go / medialoop.go) - 记忆整理工具(memory_merge / memory_delete_entity / memory_block_merge / memory_purge / memory_edit / memory_introspect)—— 它们本就在 `if a.memory != nil` 块内 唯一拆开的一处是自动写入 `commitTriplesWithMedia`: 图部分走 `graphMem().Commit`(父落 main、子落 temp),块/媒体部分仍由 `a.memory != nil` 守卫。 `executeMemoryTool` 的读路径改走 `graphMem().Recall`;整理类 case 加 `requireFull()` 闸门, 被直调时明确报"本 agent 是轻量内核:记忆整理不可用",不静默降级。 ## 验收(3 项新测试) - `TestLightProfile_MemoryFaceWiring`:整理面为 nil、写入只落 temp(主库无子痕迹)、 读是并集(主库实体 + temp 实体都看得到) - `TestLightProfile_OrganizeToolsAbsentAndRefused`:整理类工具**不进工具表**; 即便被直调也明确报"轻量内核不支持" - `TestFullProfile_KeepsOrganizeFace`:对照,根 agent 仍保留整理面与整理工具 全仓 go test ./... 37 包 ok / 0 FAIL;-race(agent/memory)干净;gofmt 干净。
34 lines
1.6 KiB
Go
34 lines
1.6 KiB
Go
package core
|
||
|
||
// 图记忆的**共同面**(设计 docs/zh/resident-subagent-design.md §16.0)。
|
||
//
|
||
// 只有两个方法 —— 因为按调用方实测分类后,`Agent.memory` 的 42 处使用里,
|
||
// 真正"根与子都要"的只有:
|
||
//
|
||
// Recall 读(上下文检索 / memory_recall)
|
||
// Commit 写(自动写入路径的图部分 / memory_commit)
|
||
//
|
||
// 其余 40 处全是**主 agent 整理记忆**与**记忆整理流水线**:
|
||
// - 记忆整理流水线:distill.go 的 archive/review/merge 循环
|
||
// - 记忆块 + 媒体桥:graphmedia.go / medialoop.go
|
||
// - 记忆整理工具:memory_merge / memory_delete_entity / memory_block_merge /
|
||
// memory_purge / memory_edit / memory_introspect
|
||
//
|
||
// 所以驻留子的轻量内核**不该有那些代码路径**:它用 `*memory.LightMemory` 接上 `graph`,
|
||
// 而 `a.memory`(整理面)保持 nil —— 既有的 22 处 `if a.memory != nil` 关卡
|
||
// 会自动把整理面全部禁掉,不需要写"每个方法都返回错误"的受限包装。
|
||
|
||
import "gitcode.com/JianFeeeee/HomeAgent/internal/memory"
|
||
|
||
// GraphMemory 是任意 agent 都能用的图记忆面。
|
||
//
|
||
// 实现者:
|
||
// - 根 agent:直接就是 *memory.GraphDB
|
||
// - 驻留子:*memory.LightMemory(读 temp∪main,只写 temp)
|
||
type GraphMemory interface {
|
||
// Recall 按关键词/种子实体召回(子的实现是两空间并集)。
|
||
Recall(keywords []string, seedEntities []string, depth int, sessionFilter string) (*memory.RecallResult, error)
|
||
// Commit 写入三元组(子的实现只落自己的 temp 空间)。
|
||
Commit(triples []memory.Triple, sessionID string, turnID int) (int, int, error)
|
||
}
|