AI Agent 乱写记忆数据是个巨大的隐患
现在的 AI Agent 开发,大家好像都在死磕检索(Retrieval)怎么做才更准:用哪个向量数据库、Chunk 怎么切、Embedding 模型选哪个、top_k 设置多少……但我发现大家忽略了一个更致命的问题:如果 Agent 决定把一条错误的信息“写进”长期记忆里,哪怕你的检索算法再牛,最后找出来的也全是垃圾。
下一篇
Kindle 导出的笔记被锁死怎么办? →
举个实战场景:一个 Agent 在调研供应商时,从 Vendor X 的官网看到一句话:“Vendor X 已通过合规性认证”。Agent 觉得这很重要,直接把它存入公司的知识库,并标记为“安全策略”。结果呢?官网说的话并不能代表公司的安全准则,这属于典型的“权限越权”。
这种问题本质上不是存储问题,而是准入问题。我最近在思考一个概念,叫 Write-Side Custody(写侧托管)。它不关心信息对不对,它只关心:谁想写?信息来源在哪?它声称的权威性是否合法?
我尝试用 Go 写了一个简单的逻辑框架,核心思路是把“写操作”和“存储操作”彻底解耦。
首先,我们不能只传一个字符串,必须定义一个包含元数据的结构体:
type ProposedWrite struct {
Content string
Source string
ProducedBy string
ClaimedAuthority string // Agent 声称的权威级别
}接着,最关键的一步是建立一套独立的 Policy(策略层)。Agent 怎么说不重要,重要的是系统里预设的规则。比如,只有“内部安全文档”这种 SourceType 才能获得“security-policy”这种 Authority。
type Authority string
type SourceType string
type Policy struct {
AuthoritySources map[Authority][]SourceType
}
// 这里的规则是硬性的,Agent 没法通过提示词来绕过
var policy = Policy{
AuthoritySources: map[Authority][]SourceType{
"security-policy": {
"internal-security-document",
"security-authority-api",
},
"user-preference": {
"user-input",
},
},
}最后,在数据落盘前,必须经过一个校验门禁(Gate):
type Verdict string
const (
Allow Verdict = "ALLOW"
Deny Verdict = "DENY"
)
type CustodyDecision struct {
Verdict Verdict
Reason string
Timestamp time.Time
}
func EvaluateWrite(
write ProposedWrite,
sourceType SourceType,
policy Policy,
) CustodyDecision {
allowedSources, ok := policy.AuthoritySources[Authority(write.ClaimedAuthority)]
if !ok {
return CustodyDecision{Verdict: Deny, Reason: "Unknown authority type"}
}
for _, s := range allowedSources {
if s == sourceType {
return CustodyDecision{Verdict: Allow, Reason: "Source authorized"}
}
}
return CustodyDecision{Verdict: Deny, Reason: "Source lacks required authority"}
}这种架构设计的意义在于,它把 Agent 的“推理能力”和系统的“决策权限”分开了。Agent 可以尽情地去调研、去总结,但当它想改变系统的长期状态或知识边界时,必须通过这个 Gate。对于做生产级 AI Agent 工作流的开发者来说,这种“写侧控制”的思想比单纯优化 RAG 效果要重要得多。
免费 AI 工具箱 · 全部完全免费
AI工具与大模型实操经验整理在Claude实战技巧汇总,有不少直接可参考的案例。
