ESC
AI 2 分钟阅读

Agent Memory Repo 开放规范发布:用 git 仓库管理 AI Agent 的跨会话记忆

Cognition 发布开放规范 Agent Memory Repo,将 AI Agent 的跨会话记忆以 git 仓库形式管理,借助版本历史、合并与权限机制实现持久化。规范定义了克隆-检索-更新-提交的记忆循环,以及定期整理记忆的“做梦”机制,支持个人记忆、Agent 集群协作与团队知识共享,已在 GitHub 开源并接受社区贡献。

来源:GitHub

Agent Memory Repo

Agent 需要能够跨会话持续存在的记忆,而单一的 MEMORY.md 文件已经不够用了。Agent Memory Repo 是一项开放规范,它将 Agent 记忆视为一个 git 仓库。

Git 为记忆提供了历史记录、合并机制和权限控制。而 Agent 早已知道如何使用 Git。

该规范同时发布于 cognition.ai/agent-memory-repo。

记忆循环

每次会话都遵循相同的步骤。

  1. **Clone(克隆)**最新记忆。
  2. **Grep(检索)**任务所需的内容,或顺着链接查找。
  3. Agent 在学习过程中 **Update(更新)**条目,无需人工介入。
  4. 每次编辑后 Commit(提交)。

Dreaming(做梦)

Dreaming 是一个定期运行的专用 Agent。它有两项任务。

  • **添加新记忆。**发现跨会话的规律模式,并将其保存为新条目。
  • **清理记忆。**合并重复条目、移除过时条目,并核查来源以化解矛盾。

使用场景

**个人记忆。**跨会话记住用户的上下文,比如他们的合作对象、项目之间的关联。每次会话读取并更新同一个记忆仓库。

**Agent 集群。**在并行工作的多个 Agent 之间共享发现。Git 会合并它们的改动并暴露冲突。

**团队记忆。**共享关于客户、流程和工具的知识,尤其适合没有代码仓库的团队。某位成员在支持调查中获得的经验,可供所有人的 Agent 使用。

**多人协作。**记忆本质上是文件夹,因此可以自由组合。当新用户加入会话时,其记忆仓库可以被克隆到同一台机器上。

格式:仓库结构、条目、元数据与交叉链接

完整的文件结构规范见 SPEC.md。

仓库结构

文件和文件夹的组织方式完全由你决定。仓库中可以包含 Markdown 笔记、SQL 查询、脚本及其他文件。

memory-joe/
  MEMORY.md
  team_structure.md
  using_datadog_mcp.md
  projects/
    payments.md
    website.md
  billing/
    count_paying_customers.sql

MEMORY.md

MEMORY.md 是仓库的入口。Agent 在每次会话开始时都会加载它,因此要保持简短:只包含每次会话都需要的内容,并附上指向其余内容的链接。

MEMORY.md:

# Memory: Joe

- Joe leads the product team [source: https://example.com/sessions/100]

## Index
- [[team_structure]]
- [[projects/payments]]
- [[projects/website]]

条目与元数据

在 Markdown 笔记中,每个条目是单行的一个列表项,末尾可附带可选的元数据。当信息发生变化时,更新或删除相应条目。

- Joe coordinates the billing launch [source: https://example.com/sessions/101]
- Payments and website share a 2026-10-15 launch deadline [source: https://example.com/sessions/102; added: 2026-09-03]

元数据使用 [key: value; key: value] 格式。键名是开放的。推荐使用的键:

  • source:指向学到该信息的 Agent 会话的链接。
  • added:保存时间,格式为 YYYY-MM-DD。

交叉链接

使用 [[path]] 在文件之间建立链接。路径从记忆根目录开始。Markdown 文件可省略 .md 后缀;其他文件保留扩展名,例如 [[billing/count_paying_customers.sql]]。将信息集中存放于一处,在其他地方通过链接引用。移动或重命名文件时记得更新链接。

- Priya owns pricing for the billing launch; see [[team_structure]].

可组合性

一次会话可以同时加载多个记忆仓库。例如,Alice 开始会话时带着自己的记忆。当 Bob 加入时,Agent 会把他的记忆克隆到同一台机器上。

1. Alice starts a session

vm/
└── memory-alice/        ← cloned at session start
    ├── MEMORY.md
    └── …

2. Bob joins the session

vm/
├── memory-alice/
│   ├── MEMORY.md
│   └── …
└── memory-bob/          ← cloned when Bob joins
    ├── MEMORY.md
    └── …

Bob 的仓库进入机器后,Agent 会读取两份 MEMORY.md 并按需追踪链接。只有当 Bob 选择与会话共享时,他的记忆才会被克隆。

各仓库保持相互独立。Agent 会追踪“谁说了什么”,并把每条记忆写入正确的仓库:Alice 的偏好写入 memory-alice/,Bob 的写入 memory-bob/。当归属不明确时,Agent 会主动询问。

由于每个仓库都保留着自己的归属、权限和历史,未来的会话可以按任意组合方式使用它们。

实例演示:从代码中学习 SQL 查询

假设 Joe 问道:“我们有多少付费客户?”

Agent 阅读计费代码后发现,付费客户是指拥有有效付费订阅的组织。测试组织被排除在外,且一个组织可能拥有多个订阅,因此查询必须统计不重复的组织。

确认查询无误后,Agent 将其保存:

billing/count_paying_customers.sql:

SELECT COUNT(DISTINCT s.organization_id)
FROM subscriptions s
JOIN organizations o ON o.id = s.organization_id
WHERE s.status = 'active'
  AND s.plan = 'paid'
  AND o.is_test = false;

MEMORY.md 中的一条条目说明了该查询的用途并链接到它:

MEMORY.md:

- [[billing/count_paying_customers.sql]] counts organizations with active, paid subscriptions. Excludes test organizations and counts each organization once [source: https://example.com/sessions/105]

之后的会话只需追踪该链接并运行已保存的 SQL,即可得到当前统计结果,无需重新摸索连接和过滤条件。

在你的 Agent 中试用

安装 agent-memory-repo 技能。它会教会 Agent 将记忆保存在一个遵循本规范的独立本地 git 仓库中。

npx skills add AgentMemoryRepo/agentmemoryrepo --skill agent-memory-repo

安装程序会询问要为哪些 Agent 安装。在 Devin 中,可以将其作为插件安装:

devin plugins install AgentMemoryRepo/agentmemoryrepo

然后在两次会话中进行尝试。此试用在本地进行,因此请在同一台机器、同一存储、同一项目下运行两次会话。

第 1 次会话:

Use the agent-memory-repo skill to set up a separate local memory repo for this trial. Save this trial preference: I prefer concise bullet-point summaries. Do not configure a remote. Tell me the full path to the memory repo so I can reuse it next session.

第 2 次会话(新会话中):

Use the agent-memory-repo skill with the memory repo at <paste the full path from the previous session>. What trial preference did I save?

记忆会保存在本地,除非你连接了自己拥有的私有仓库。在新云机器或另一台电脑上,本地记忆仓库并不存在,此时可让 Agent 先克隆你的私有记忆仓库。

开放开发

Agent Memory Repo 由 Cognition 最初开发,并以开放标准的形式发布,欢迎更广泛的生态参与贡献。

可在 GitHub 仓库中提交变更建议并参与讨论。

许可证

MIT