mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-23 02:18:06 +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:
@ -215,6 +215,7 @@ type injectParams struct {
|
||||
TextRef SharedRef `json:"text_ref,omitempty"`
|
||||
NoMemory bool `json:"no_memory,omitempty"`
|
||||
ContextPolicy string `json:"context_policy,omitempty"`
|
||||
RecallPolicy string `json:"recall_policy,omitempty"`
|
||||
CleanerName string `json:"cleaner_name,omitempty"`
|
||||
// Priority 声明中断注入的优先级(L1..L3);L4 内核独占,见 InjectOptions。
|
||||
Priority string `json:"priority,omitempty"`
|
||||
@ -237,6 +238,7 @@ type injectMediaParams struct {
|
||||
BlocksRef SharedRef `json:"blocks_ref,omitempty"`
|
||||
NoMemory bool `json:"no_memory,omitempty"`
|
||||
ContextPolicy string `json:"context_policy,omitempty"`
|
||||
RecallPolicy string `json:"recall_policy,omitempty"`
|
||||
CleanerName string `json:"cleaner_name,omitempty"`
|
||||
Priority string `json:"priority,omitempty"`
|
||||
}
|
||||
@ -245,10 +247,11 @@ type injectMediaParams struct {
|
||||
//
|
||||
// 单独提一个转换函数是为了让「默认值」只有一个出处:零值即记入记忆 + 不裁剪,
|
||||
// 与旧三参数注入等价。
|
||||
func pubSdkInjectOpts(noMemory bool, policy, cleanerName, priority string) pubsdk.InjectOptions {
|
||||
func pubSdkInjectOpts(noMemory bool, policy, recallPolicy, cleanerName, priority string) pubsdk.InjectOptions {
|
||||
return pubsdk.InjectOptions{
|
||||
NoMemory: noMemory, ContextPolicy: policy, CleanerName: cleanerName,
|
||||
Priority: clampExternalPriority(priority),
|
||||
NoMemory: noMemory, ContextPolicy: policy, RecallPolicy: recallPolicy,
|
||||
CleanerName: cleanerName,
|
||||
Priority: clampExternalPriority(priority),
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,6 +283,14 @@ func validateContextPolicy(where, policy string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateRecallPolicy 校验召回策略取值,与 context_policy 同一套规则。
|
||||
func validateRecallPolicy(where, policy string) error {
|
||||
if !pubsdk.ValidRecallPolicy(policy) {
|
||||
return fmt.Errorf("%s: recall_policy 只允许 none/auto,实际 %q", where, policy)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// resolveJSONRef 若 ref 非零则从共享内存读取并 JSON 反序列化到 out;
|
||||
// ref 为零时不动 out(调用方已填的内联值生效)。
|
||||
//
|
||||
@ -424,6 +435,9 @@ func (h *coreHandler) toolRegister(params json.RawMessage) (interface{}, error)
|
||||
if err := validateContextPolicy("tool.register", p.Def.ContextPolicy); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := validateRecallPolicy("tool.register", p.Def.RecallPolicy); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.Def.Plugin = h.name
|
||||
// 函数本身不进 JSON;has_cleaner 只声明其存在,实际执行回到插件进程。
|
||||
cleaner, err := h.cleanerProxy(CleanerScopeTool, p.Name, p.HasCleaner)
|
||||
|
||||
Reference in New Issue
Block a user