由 ReMe 驱动的记忆管理系统,支持跨会话记忆持久化、自动应用用户偏好以及智能上下文压缩...
内存-reme - ReMe内存管理. 由ReMe提供电源的内存管理系统,提供持续的跨会话内存,自动用户偏好应用程序,以及智能上下文c是一项面向实际任务的技能。它将相关步骤、工具调用和结果整理方式集中到统一流程中,帮助使用者更快完成目标并减少重复操作。
实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。
执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
一个由 ReMe 驱动的记忆管理系统,提供跨会话持久化记忆、自动应用用户偏好以及智能上下文压缩能力。
在以下情况中启用本技能:
1. 长期记忆(MEMORY.md)
2. 日常记忆(memory/YYYY-MM-DD.md)
3. 内存中上下文(In-Memory Context)
| 类型 | 用途 | 示例 |
|---|---|---|
| Personal(个人类) | 用户偏好、习惯 | “偏好简洁代码”、“始终发送文件” |
| Task(任务类) | 执行经验、模式总结 | “Python 脚本必须包含错误处理” |
| Tool(工具类) | 工具使用经验 | “web_fetch 对该网站需设置 timeout=30s” |
pip install reme-ai
每次会话开始时均需执行:
# 初始化
from reme.reme_light import ReMeLight
reme = ReMeLight(working_dir=".reme", language="zh")
await reme.start()
# 检索偏好
prefs = await reme.memory_search(
query="用户偏好 文件发送",
max_results=5
)
# 应用
if prefs and "必须发送" in prefs[0]['content']:
auto_send_files = True
┌─────────────────────────────────┐ │ 1. 初始化 ReMe │ │ 2. 加载 MEMORY.md │ │ 3. 检索用户偏好 │ │ 4. 应用于当前上下文 │ └─────────────────────────────────┘
操作命令:
python3 C:pathtomemory-remescriptsinit_reme.py
预期输出:
✓ ReMe initialized 📖 Retrieved 3 preferences - User prefers concise code - Files must be sent automatically - Prefer markdown over plain text ✓ Preferences applied
执行动作前须检查:
生成文件前:
调用工具前:
接收用户反馈时:
示例:
用户:“你怎么总是忘记发送文件?记住,生成文件后必须直接发送!”
操作:
# 从反馈中学习
await reme.add_memory(
memory_content="用户偏好:生成文件后必须使用message工具直接发送文件,不接受链接地址。原因:用户需要直观可见的内容。",
user_name="阿伟",
memory_type="personal"
)
┌─────────────────────────────────┐ │ 1. 提取关键事件 │ │ 2. 生成摘要 │ │ 3. 写入 memory/ 目录 │ │ 4. 更新 MEMORY.md │ │ 5. 清理工具运行结果 │ │ 6. 关闭 ReMe │ └─────────────────────────────────┘
操作命令:
python3 C:pathtomemory-remescriptssave_summary.py
输出:
💾 Summary saved to memory/2026-03-06.md ✓ MEMORY.md updated ✓ Tool results cleaned ✓ ReMe closed
触发条件:用户请求生成文件
工作流程:
示例:
📖 Retrieved: "Send files automatically" User: 生成AI日报 ✓ Generated: AI日报_2026-03-06.md 📤 Sending file... ✓ Sent successfully
触发条件:用户要求编写代码
工作流程:
示例:
📖 Retrieved: "Prefer concise, well-commented code" User: 写个Python函数 ✓ Applied: Concise style with docstrings
触发条件:用户纠正你的行为
工作流程:
示例:
User: Why do you keep forgetting to send files? 🧠 Learning... ✓ Rule recorded: "Always send files automatically" ✓ Will apply next time
触发条件:对话长度接近 token 限制的 70%
工作流程:
全自动处理 — 无需人工干预。
| 目标 | 查询语句 |
|---|---|
| 文件处理偏好 | "文件发送 偏好 自动发送" |
| 代码风格 | "代码风格 简洁 注释" |
| 工具配置 | "工具 超时 重试" |
| 用户习惯 | "用户习惯 偏好" |
| 历史错误 | "错误 避免 重复" |
必须执行的操作:
示例:
results = await reme.memory_search(query="文件发送 偏好", max_results=3)
for i, result in enumerate(results, 1):
print(f"{i}. {result['content']}")
if "必须发送" in result['content']:
self.auto_send_files = True
print(f"✓ Applied: auto_send_files = {self.auto_send_files}")
# MEMORY.md - Long-term Memory ## User Profile - **Name**: 阿伟 - **Role**: 90后程序员、AI博主 ## Preferences ### File Handling - **Rule**: 生成文件后必须使用message工具直接发送 - **Reason**: 用户需要直观可见的内容 - **Status**: Active - **Learned**: 2026-03-06 ### Code Style - **Rule**: 代码要简洁,有注释 - **Reason**: 便于维护和理解 - **Status**: Active - **Learned**: 2026-03-05 ## Tool Usage ### web_fetch - **Timeout**: 30s - **Retry**: 3 times - **Reason**: 某些网站响应慢 ### browser - **Timeout**: 60s - **Wait time**: 3s for page load - **Reason**: 确保页面完全加载
# 2026-03-06 Session Summary ## Session 1 - AI News Aggregation ### User Request "给我今天的AI资讯" ### Processing - Scraped 8 sources - Filtered 20+ articles - Selected 14 items ### Output - File: AI日报_2026-03-06.md - Size: 3611 bytes - Sent: ✓ ### User Feedback "你怎么总是忘记发送文件?记住,生成文件后必须直接发送!" ### Learning ✓ New rule: Auto-send files ✓ Updated MEMORY.md --- ## Session 2 - ReMe Integration ### User Request "接入ReMe后工作流程是怎样的" ### Processing - Analyzed ReMe documentation - Designed workflow - Created integration plan ### Output - File: ReMe工作流程设计.md - File: ReMe存在形式与影响.md - Sent: ✓ ### No User Feedback ### Learning No new rules
反面示例:
# 未加载记忆即启动 user_request = get_user_input() process_request(user_request)
推荐做法:
# 启动前先加载记忆 reme = await init_reme() prefs = await reme.memory_search(query="用户偏好") apply_preferences(prefs) user_request = get_user_input() process_request(user_request)
当用户说 “你忘了 X” 时:
示例:
User: 你总是忘记发送文件! Me: ✓ 已记住:生成文件后必须发送文件 正在添加到 MEMORY.md... Next file generation: ✓ File created 📤 Auto-sending... ✓ Sent
反面示例:
- User prefers good code
推荐写法:
- User prefers concise, well-commented Python code - Use docstrings for functions - Maximum 3 levels of nesting - Prefer list comprehensions over loops
每日任务:
每周任务:
低效查询:
高效查询:
原因: 更具体的查询可获得更高相关性的结果。
典型现象:
解决方法:
# 调试检索
results = await reme.memory_search(query="文件")
print(f"Found {len(results)} results")
for r in results:
print(f" - {r['content'][:50]}...")
典型现象:
解决方法:
典型现象:
解决方法:
工作流程:
1. 检索 docx 相关偏好 2. 应用格式化规则 3. 使用 docx 技能生成文档 4. 判断是否需自动发送 5. 如需则执行发送
工作流程:
1. 检索代码编写相关偏好 2. 应用编码风格规范 3. 使用 coding-agent 生成代码 4. 检查是否存在自动 review 规则 5. 如需则执行 review
| 操作 | 耗时 | 影响 |
|---|---|---|
| 会话启动 | ~500ms | 可忽略 |
| 记忆检索 | ~200ms | 可忽略 |
| 文件操作 | ~100ms | 可忽略 |
| 摘要生成 | ~300ms | 可忽略 |
| 单次会话总耗时 | ~1s | 极小 |
.reme/ ├── MEMORY.md ~10KB ├── memory/ ~150KB (30 天) ├── tool_result/ ~5MB (自动清理) └── .embeddings/ ~1MB 总计:~6MB(一个月)
仅在相关场景下应用:
prefs = await reme.memory_search(query="文件发送")
if file_generated and prefs:
# 应用文件处理偏好
if "必须发送" in prefs[0]['content']:
await send_file(file_path)
根据当前任务类型动态构造查询:
if task_type == "coding":
query = "代码风格 Python"
elif task_type == "writing":
query = "写作风格 简洁"
elif task_type == "file_generation":
query = "文件发送 偏好"
自动清理策略:
手动清理命令:
# 归档旧会话 mv memory/2026-01-*.md memory/archive/ # 压缩大文件 gzip MEMORY.md
本技能实现持久化记忆、自动应用用户偏好及智能上下文管理。可用于:
核心原则:记忆只有在被检索并实际应用时才真正有效。务必在每次会话起始时执行记忆检索,并在整个对话过程中持续验证其应用效果。