技巧

AI Agent 记忆系统拆解:上下文、笔记、语义、程序性、情景五层机制

精选理由

把 agent 记忆讲得特别清楚,五层各管什么、哪些能跨会话保留,配了 MEMORY.md 这种具体实现例子,做 agent 开发的可以先收藏。

LLM 本身无状态,agent 的记忆全靠 harness 写入磁盘并在需要时加载。常见 agent harness 把记忆分为五层:context 层在接近上限时对旧消息做摘要腾空间;notes 是任务中途持续更新的进度文件,供下一个会话接续;semantic 层记录用户偏好和项目信息,如 Hermes 存在 MEMORY.md 和 USER.md 中;procedural 层把难题解法固化为可复用的 skill;episodic 层保存历史会话日志供检索。前两层随会话结束失效,后三层跨会话持久存在。

原文 · Shubham Saboo

Memory in AI Agent Harness.

LLMs are stateless, so every bit of memory in an AI agent is something the harness saves to disk and loads back in when it needs it.

most good agent harnesses split that memory into a few layers, let's look at each one of them:

• context: what the model can see in the current session. when it gets close to full, the harness summarizes the older messages to make room.

• notes: a progress file the agent keeps updating while it works, so if a session ends halfway the next one can read it and continue from there.

• semantic: facts about you, your team and your project, like your preferences or which repo you work in. Hermes keeps these in MEMORY.md and USER.md.

• procedural: how to do a specific job. when the agent figures out something hard, it writes it down as a skill and uses that skill the next time.

• episodic: a log of every past session that the agent can search when it needs to remember what happened before.

First two only last as long as the session or the task. Other three are persistent, so they're still there the next time you start the agent.

save this for the next time someone asks how agents remember.

follow @Saboo_Shubham_ for more on Agent Harness.