# 编码记忆(Coding Memory) 编码记忆是 Code 模式下的专属记忆系统,使 Agent 在代码任务中可以读取、写入和编辑持久化的代码上下文。 --- ## 启用 编码记忆在切换到 Code 模式时自动启用,无需额外配置。相关配置位于 `config/config.yaml` 的 `modes.code` 段: ```yaml modes: code: rails: - FileSystemRail - SkillUseRail - LspRail tools: - web_free_search - web_fetch_webpage - web_paid_search - user_todos embedding_config: model_name: null # 留空则用全局 Embedding 配置 base_url: null api_key: null ``` --- ## 工具说明 编码记忆提供三个工具,由 `CodingMemoryRail` 在子进程内自动注册: ### coding_memory_read 读取当前编码记忆内容。 | 参数 | 类型 | 说明 | |------|------|------| | `query` | string | 查询关键词,用于检索相关的编码上下文 | 返回匹配的代码片段和上下文说明。 ### coding_memory_write 向编码记忆写入新的代码上下文或经验。 | 参数 | 类型 | 说明 | |------|------|------| | `content` | string | 要写入的代码内容或经验 | | `section` | string | 分类标签(如 `architecture`、`bugfix`、`pattern`) | ### coding_memory_edit 编辑已有的编码记忆条目。 | 参数 | 类型 | 说明 | |------|------|------| | `memory_id` | string | 要编辑的记忆条目 ID | | `content` | string | 新的内容 | | `section` | string | 可选,修改分类标签 | --- ## 与其他记忆系统的关系 | 记忆系统 | 适用模式 | 说明 | |----------|---------|------| | 内建记忆(`write_memory` / `read_memory`) | Agent 模式 | 通用对话记忆 | | 经验记忆(`experience_retrieve` / `experience_learn`) | 全模式 | 任务级经验检索与沉淀 | | 编码记忆(`coding_memory_read` / `write` / `edit`) | Code 模式 | 代码上下文与编码经验 | 在 Code 模式下,三种记忆系统可以共存使用。 --- ## 存储 编码记忆数据存储在 `workspace/agent/memory/` 目录下,与内建记忆共享存储路径。 --- ## 睡时记忆整理(Dreaming) Code 模式启用 Dreaming 后,系统会闲时回看历史 coding 会话,自动提取调试根因、API 边界行为、设计决策等可复用经验,写入 `{workspace}/coding_memory/consolidated_{hash}.md`。这是对上述 `coding_memory_*` 工具(会话内主动写入)的离线补充。 启用方式与提取细节详见 [记忆系统 → Dreaming 睡时记忆整理](记忆.md#dreaming-睡时记忆整理)。 --- ## 详见 - [模式系统](模式系统.md) — 各模式配置与切换 - [记忆系统](记忆.md) — 内建记忆与外接记忆 - [经验记忆](经验记忆.md) — 任务级经验检索