P1 持久记忆插件 — 加载 AGENTS.md 并注入系统提示词。
工作原理
session_start— 从memory_files配置的路径(默认working_dir/AGENTS.md)读取记忆文件。 通过emit {:memory_contents, %{file_name => content}}将内容传递给 Agent, 由 Agent 更新state.memory_contents,再由SystemPrompt以<agent_memory>标签注入 每次 LLM 请求的 system prompt。after_tool— 监控write_file/edit_file工具对记忆文件的写入, 自动更新 plugin state 中的缓存内容,并再次 emit 触发重新加载。
<agent_memory> 注入格式
SystemPrompt 模块将 memory_contents 渲染为:
<agent_memory name="AGENTS.md">
...文件内容...
</agent_memory>配置
{CMDC.Plugin.Builtin.MemoryLoader,
memory_files: ["AGENTS.md"], # 相对于 working_dir 的记忆文件路径列表
auto_reload: true # 工具写入记忆文件后自动重新加载
}emit 事件协议
{:memory_contents, %{String.t() => String.t()}}— 记忆内容 map,key 为文件名
Agent 收到此 emit 后将更新 state.memory_contents,确保下一次 LLM 请求包含最新记忆。