shareAI-lab / shareAI-lab/learn-claude-code

s09:建议基于 MEMORY.md 目录按需读取记忆,简化默认自动召回流程

Open
#564 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
77.2k
Forks
12.4k
Avg merge
2d 5h
Merged PRs (30d)
6

Description

建议

能否让 s09 默认采用类似 Skill 渐进式加载的方式:每轮注入 MEMORY.md 目录,由主模型判断相关性,再通过 read_file 按需读取 .memory/ 中的具体记忆?提前自动召回可以作为进阶方案介绍。

当前实现

阅读 s09_memory/code.py 时发现:

  • agent_loop() 先调用 load_memories(messages),再构建系统提示词。
  • select_relevant_memories() 扫描记忆文件,用名称和描述重新构建目录;存在记忆和查询时,额外调用一次模型选择记录,默认最多 5 条,调用异常时退回关键词匹配。
  • build_system() 同时向主模型注入 MEMORY.md 的完整目录和已选记忆的正文。
  • 主模型已经具备 read_file 工具。

因此,当前主模型已经能看到完整目录,但在它处理请求前,又单独运行了一套记忆选择流程。对于教学示例和小规模记忆库,这一步是否有必要?

建议的最小改动

  1. agent_loop() 开头简化为 system = build_system(),取消默认路径上的提前筛选和正文注入。
  2. 在系统提示词中明确:目录条目对应 .memory/ 下的文件;按任务需要读取相关记忆,不能把目录摘要当作已读过完整正文。
  3. 保留记忆提取、保存、整理和 MEMORY.md 重建流程,以及“记忆是背景信息,当前用户请求优先”的约束。
  4. 在三语 README 中解释目录与正文的渐进式加载,并说明自动召回适用的场景。

这里不需要引入统一接口或新的框架,复用现有目录和文件读取工具即可。

收益与取舍

这样可以减少默认流程中的独立筛选逻辑,让主模型结合它已获得的任务上下文决定读取哪些记忆,也便于理解 Skill 与 Memory 都可以采用“先看目录,再读正文”的方式。

这并不保证总成本或延迟一定下降:按需读取通常需要额外工具往返,模型也可能忽略应读的记忆。提前召回则能让选中记忆在主模型第一次处理请求时就可用,但当前基于相关性的筛选同样可能漏掉长期偏好。建议在文档中明确这些取舍;如果保留现有默认实现,也希望说明它相对于按需读取方案的教学目的。

相关讨论:#469 曾涉及 Skill/Memory 的上下文管理;本提议聚焦默认记忆读取方式的简化。

本文由 AI 协助核对代码并整理,源于学习 s09 时对召回设计的讨论。

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read s09_memory/code.py, starting with agent_loop(), load_memories(), select_relevant_memories(), build_system(), and the existing read_file tool. Then review the three-language README sections and related discussion #469. Done means the default flow, preserved memory workflows, and documented progressive-loading tradeoffs match the agreed design.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, documentation
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.