跳到主内容
@wquguru
精选88r/LLMDevs(Reddit)技巧与观点

AI Agent记忆层对抗重复谎言的修复方案

If your AI agent reads a document that repeats a lie 8 times, it'll believe the document over you. I measured it, and the fix was one field and the order of two checks

原文
发到 X
推荐理由

Agent开发中记忆冲突是高频痛点,这篇提供了经过量化验证的具体工程解法与参数取舍,直接可复用。

Quick example of the failure. You tell your assistant once "I'm allergic to penicillin". Later it ingests some old medical export that says "no known allergies" in eight places. Ask it again. Most memory setups will now answer with the document, because repetition looks like confidence and nothing records who said what.

一个失败的快速示例。你告诉你的助手一次“我对青霉素过敏”。后来它读取了一些旧的医疗导出文件,其中八处写着“无已知过敏史”。再次询问它。大多数记忆设置现在都会引用该文档作为回答,因为重复看起来像自信,且没有任何记录能表明是谁说了什么。

I build a memory layer and measured this properly, 12 seeds, 60 background facts per run. Before my fix, 2 repetitions of a false value were enough for 12/12 runs to serve the lie. And an explicit correction after 3 repetitions still lost 11 times out of 12, because the repetition had made the lie the strongest thing in memory. I tried thresholds, margins, confidence gates. None of it helps against someone who just repeats.

我构建了一个记忆层并进行了严谨的测量:12个随机种子,每次运行60条背景事实。在我的修复之前,虚假值重复两次就足以让12/12次运行都输出这个谎言。即使在第三次重复后进行了明确纠正,它在12次运行中仍有11次失败,因为重复使得谎言成为记忆中最强的内容。我尝试过阈值、边距和置信度门控。这些方法都无法抵御单纯的重复行为。

What fixed it: every fact stores where it came from. "Declared" means the user said it in their own conversation, "graph" means inferred or imported from a doc, "unknown" for old stuff, and unknown never gets upgraded to declared. The part I didn't expect is that the order is everything. With the provenance check placed after the memory's own arbitration it did literally nothing, the lie still won 12/12. Placed before, a lie repeated 8 times in a document doesn't beat a fact the user said once. 12/12 at every level. Same thing for overwrites: if a document is allowed to revise a declared fact, the lie wins 12/12 again.

解决问题的关键:每个事实都存储其来源。“Declared”(已声明)意味着用户在其自己的对话中说过,“graph”(图谱)意味着从文档推断或导入,“unknown”(未知)用于旧数据,且“unknown”永远不会升级为“declared”。我没预料到的是顺序至关重要。如果溯源检查放在记忆自身仲裁之后,它实际上毫无作用,谎言依然以12/12获胜。如果放在之前,文档中重复8次的谎言也打不过用户只说了一次的事实。在每一层级都是12/12。覆盖写入的情况也是如此:如果允许文档修订已声明的事实,谎言会再次以12/12获胜。

For comparison I ran a plain semantic RAG (MiniLM + FAISS) on 40 questions, same model on top. It actually found slightly more (0.85 coverage vs my 0.775) but served an outdated value 28.6% of the time once a fact had changed, because similarity search finds the old sentence as well as the new one. Mine had 0 stale answers and about 20% fewer tokens per correct answer. One seed on that one, so it's a direction, not a leaderboard.

作为对比,我在40个问题上使用纯语义RAG(MiniLM + FAISS)进行了测试,顶层使用相同的模型。它的召回率实际上略高(覆盖率0.85 vs 我的0.775),但一旦事实发生变化,它有28.6%的时间提供了过时值,因为相似性搜索既找到了旧句子也找到了新句子。我的方案没有过时答案,且每个正确答案消耗的Token减少了约20%。这里只用了1个随机种子,所以这只是一个方向性的参考,而非排行榜成绩。

Not authentication btw. "Declared" means "written in their own conversation", not "this person is who they claim".

顺便说一下,这不是身份验证。“Declared”意味着“写在他们自己的对话中”,而不是“这个人就是他们声称的那个人”。

How are you handling this? Do your memories carry a source, or does everything go into the same vector store with the same weight?

你们是如何处理这个问题的?你们的记忆带有来源标记吗,还是所有内容都以相同的权重进入同一个向量存储?

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件