思考用于 AI 编码 agent 的记忆
2 分•作者: hoangnnguyen•24 天前
我一直在日常工作中尝试使用 AI 编码助手,并遇到了一个反复出现的问题:我一直在重复相同的工程原则。<p>比如验证输入、谨慎使用新依赖项,或者遵守某些产品约束。通常的解决方案是提示或规则。<p>在使用这两种方法一段时间后,我感觉都不太合适。
- 提示在每次任务后都会消失。
- 规则仅在狭窄的上下文中触发,通常与特定文件或模式相关。
- 有些原则是个人偏好,我不想在项目层面强制执行。
- 另一些根本不是“规则”,而是关于产品约束和过去权衡的知识。<p>这促使我尝试为 AI 助手创建一个单独的“记忆”层。不是聊天记录,而是小的、原子的知识片段:决策、约束和可以根据需要检索的重复出现的原则。<p>在开始认真使用它之后,一些事情变得显而易见:
- 模糊的记忆会导致模糊的行为
- 冗长的记忆会污染上下文
- 重复的条目会使检索效果变差
- 许多问题只有在您每天真正依赖助手时才会出现<p>当上下文正确时,AI 在执行方面表现出色。但是,决定应该记住什么、应该拒绝什么,以及何时可预测性比聪明才智更重要,仍然需要人为判断。<p>很好奇其他人是如何处理这个问题的。您在使用 AI 编码助手时,主要依赖提示、规则,还是某种形式的持久知识?
查看原文
I’ve been experimenting with AI coding agents in real day-to-day work and ran into a recurring problem, I keep repeating the same engineering principles over and over.<p>Things like validating input, being careful with new dependencies, or respecting certain product constraints. The usual solutions are prompts or rules.<p>After using both for a while, neither felt right.
- Prompts disappear after each task.
- Rules only trigger in narrow contexts, often tied to specific files or patterns.
- Some principles are personal preferences, not something I want enforced at the project level.
- Others aren’t really “rules” at all, but knowledge about product constraints and past tradeoffs.<p>That led me to experiment with a separate “memory” layer for AI agents. Not chat history, but small, atomic pieces of knowledge: decisions, constraints, and recurring principles that can be retrieved when relevant.<p>A few things became obvious once I started using it seriously:
- vague memory leads to vague behavior
- long memory pollutes context
- duplicate entries make retrieval worse
- many issues only show up when you actually depend on the agent daily<p>AI was great at executing once the context was right. But deciding what should be remembered, what should be rejected, and when predictability matters more than cleverness still required human judgment.<p>Curious how others are handling this. Are you relying mostly on prompts, rules, or some form of persistent knowledge when working with AI coding agents?