mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-07 01:37:34 +00:00
fix(memory,llm): L2 预填充并入召回主路 + 回退换 provider 时换 model(视觉失效真因)
## 1. L2(冷上下文)预填充此前只走「注入文本」,等于没有
设计:prune 与 recall 是一对 —— 工具声明 ContextPolicy=prune + RecallPolicy=auto
时,工具输出既触发裁剪、也触发预填充(memoryPass → recallTextFor)。
但 L2 那一路只写在 buildSystemPrompt 里,query 用的是**注入文本**;
QQ 注入的是「来自「X」的私聊消息(message_id=…),先用 qq_get_message 取正文」,
与用户真正说的话毫无相似度 ⇒ 冷上下文预填充恒为空。
(现场:头天晚上讲的冷笑话,第二天早上完全唤不回;14 小时里
memory recall (input…) 只有 5 次、且 query 是元信息。)
改法:把 L2 检索并入 buildMemoryContext —— 输入路用输入文本、工具路用工具正文,
两条路共用同一次召回与预算;buildSystemPrompt 里那份重复注入删掉。
中断消息仍然 NoMemory + RecallPolicy=none(不裁剪、不召回、不进记忆),
这是设计要求,未改动。
## 2. 回退换 provider 时必须换 model(视觉失效的真因)
现场日志:
deepseek 402 Insufficient Balance
→ 回退 llmsproxy,但 req 仍带 model=「deepseek-flash」
→ llmsproxy 403 model_not_allowed
→ llmsproxy 被整源标记 unavailable(冷却)
→ 视觉回退 resolveModalFallback 跳过它 ⇒「配置了视觉却说没有视觉」
两处修正:
· 每个 provider 用自己的 model 发请求(model 是 provider 的属性)
· 403 区分「模型不被该 key 允许」与「凭证失效」:前者只否一个 model,
provider 仍可用于其他 model 与视觉回退
判据:internal/agent/core/provider_model_fallback_test.go
This commit is contained in:
@ -37,6 +37,25 @@ func (a *Agent) buildMemoryContext(input string, maxTokens int, scenes []string)
|
||||
s += "[Related media]\n" + mc
|
||||
}
|
||||
|
||||
// ★ L2(冷上下文)相似度预填充:**必须在这里做**,不能只在上层 buildSystemPrompt。
|
||||
//
|
||||
// 设计里 prune 与 recall 是一对:工具声明 ContextPolicy=prune + RecallPolicy=auto
|
||||
// 时,工具输出既触发裁剪也触发预填充(memoryPass → recallTextFor → 本函数)。
|
||||
// 而此前 L2 那一路只写在 buildSystemPrompt 里、且 query 是**注入文本**
|
||||
// (QQ 是"来自「X」的私聊消息(message_id=…),先用 qq_get_message 取正文"),
|
||||
// 跟用户真实说的话毫不相似 ⇒ 冷上下文预填充等于没有
|
||||
//(2026-10-27 现场:头天晚上讲的冷笑话第二天早上完全唤不回)。
|
||||
//
|
||||
// 放进本函数后:输入路用输入文本、工具路用工具正文,两条路都能召回 L2 摘要。
|
||||
if a.docStore != nil {
|
||||
if md := a.crossModalMarkdown(a.retrieveCrossModal(input, 3, a.fusionCfg)); md != "" {
|
||||
if s != "" {
|
||||
s += "\n"
|
||||
}
|
||||
s += md
|
||||
}
|
||||
}
|
||||
|
||||
if maxTokens > 0 {
|
||||
s = TruncateByTokens(s, maxTokens)
|
||||
}
|
||||
@ -200,15 +219,8 @@ func (a *Agent) buildSystemPrompt(memContext string, userInput string) string {
|
||||
//(【记忆清理】前缀)。这里只保留那条**不看描述也会犯**的错:只描述计划不执行。
|
||||
prompt = appendPromptBlock(prompt, "[Memory maintenance] To tidy or clear memory, call the memory_* tools - a described plan is not the work. Report the result in one sentence.")
|
||||
|
||||
// 跨模态召回:文本路(fastText/TF-IDF 文档层,媒体描述文本已随记忆进入)
|
||||
// + 视觉路(多模态文本编码 → 媒体库坐标)两路归一化融合。
|
||||
// 未配置多模态空间时视觉路为空,等价旧的 docStore.Query。
|
||||
if a.docStore != nil {
|
||||
hits := a.retrieveCrossModal(userInput, 3, a.fusionCfg)
|
||||
if md := a.crossModalMarkdown(hits); md != "" {
|
||||
prompt = appendPromptBlock(prompt, md)
|
||||
}
|
||||
}
|
||||
// L2(冷上下文)预填充已并入 buildMemoryContext(输入路/工具路共用一次),
|
||||
// 这里不再重复注入,否则同一批摘要会出现两遍。
|
||||
|
||||
prompt = appendPromptBlock(prompt, "[Interrupt] During long tasks a system message prefixed [Interrupt] may arrive (new message, terminal output, timer). It is not user speech, but handle it: pause, respond, or consciously continue.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user