mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-15 12:15:16 +00:00
feat(memory): 新增可声明的召回轴 RecallPolicy(与 prune 正交)
问题:召回(把 L2/L3 相关记忆注入本轮)此前不可声明、也不受任何 SDK 字段 控制——它只在任务开始时对 f.Input 无条件跑一次。于是 qq_get_message 取回 真实正文后只触发 Prune(裁剪),从不触发召回;而中断通知的 meta 文本反而 会去召回(词不对题,命中一堆泛实体)。 改动: - SDK 新增 RecallPolicy(none|auto) 轴,落在 InjectOptions / ChannelDef / ToolDef 三个声明面,与 ContextPolicy 正交(裁剪 vs 召回)。默认值与 prune 刻意相反:输入/注入默认 auto(保持既有「每条输入都召回」), 工具默认 none(工具输出多为噪声,按需声明)。 - 内核:recallDeclared 按 注入点 > 通道 > 默认auto 解析;输入侧用它决定 是否注入记忆索引;工具侧 ContextPolicy/RecallPolicy 共用同一份清洗后 query,一次相关性过程分别 prune / recall;召回以 system 消息挂到消息 末尾(同任务内替换而非累加)。 - 管线:proc RPC(inject/register + 校验)、lua 键、io payload 全量透传。 - QQ 插件:中断与 qq 通道声明 RecallPolicy=none(meta 不是内容); qq_get_message 声明 RecallPolicy=auto(取回正文后据正文召回)。 测试:新增 recallpolicy_test.go(core)与 proc 校验用例; go build ./... 通过,go test ./internal/... 全通过,SDK 模块与 qq 插件测试通过。
This commit is contained in:
@ -2,6 +2,7 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
agentIO "gitcode.com/JianFeeeee/HomeAgent/internal/agent/io"
|
||||
@ -39,6 +40,38 @@ func (a *Agent) buildMemoryContext(input string, maxTokens int) string {
|
||||
return s
|
||||
}
|
||||
|
||||
// buildTaskMemoryContext 按本任务声明的召回策略决定是否注入记忆索引。
|
||||
//
|
||||
// 默认 auto(保持“每条输入都召回”的既有行为);输入/注入声明
|
||||
// recall_policy=none 时返回空串,从而不注入记忆。策略与裁剪(ContextPolicy)正交。
|
||||
func (a *Agent) buildTaskMemoryContext(f *TaskFrame, input string, maxTokens int) string {
|
||||
if f != nil && !a.recallDeclared(f.Evt) {
|
||||
return ""
|
||||
}
|
||||
return a.buildMemoryContext(input, maxTokens)
|
||||
}
|
||||
|
||||
// recallTextFor 以 query 触发一次记忆召回,返回可注入的文本(空串表示无)。
|
||||
//
|
||||
// 这是“召回”侧的单一入口:与 Prune 共用同一份**清洗后**的 query,
|
||||
// 使“取进来”(召回)与“踢出去”(裁剪)落在同一个相关性过程上。
|
||||
// trigger 仅用于日志溯源(如 "tool:qq_get_message")。
|
||||
func (a *Agent) recallTextFor(query, trigger string) string {
|
||||
if query == "" || a.indexer == nil {
|
||||
return ""
|
||||
}
|
||||
memTokens := 0 // 0 = 不截断
|
||||
if a.provider != nil {
|
||||
memTokens = ComputeTokenBudget(a.provider, a.systemPrompt).MemoryTokens
|
||||
}
|
||||
text := a.buildMemoryContext(query, memTokens)
|
||||
if text == "" {
|
||||
return ""
|
||||
}
|
||||
log.Printf("[agent] memory recall (%s): injected %d chars", trigger, len(text))
|
||||
return text
|
||||
}
|
||||
|
||||
// expandPromptVars 展开自定义提示词(人格卡)里的版本占位符。
|
||||
//
|
||||
// 为什么需要:人格卡是**配置项**,一旦写死版本号就会随内核发版而说谎 ——
|
||||
|
||||
Reference in New Issue
Block a user