memory-manager

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Memory Manager

内存管理器

External persistent memory system for maintaining knowledge across autonomous coding sessions.
用于在自主编码会话间维护知识的外部持久化内存系统。

Quick Start

快速开始

Store a Memory

存储一条记忆

python
from scripts.memory_manager import MemoryManager

memory = MemoryManager(project_dir)
memory.store(
    key="auth_solution",
    value="Added User-Agent header to fix 403",
    memory_type="causal"
)
python
from scripts.memory_manager import MemoryManager

memory = MemoryManager(project_dir)
memory.store(
    key="auth_solution",
    value="Added User-Agent header to fix 403",
    memory_type="causal"
)

Store Causal Chain (Error→Solution)

存储因果链(错误→解决方案)

python
memory.store_causal_chain(
    error="403 Forbidden on API call",
    solution="Add User-Agent header to requests"
)
python
memory.store_causal_chain(
    error="403 Forbidden on API call",
    solution="Add User-Agent header to requests"
)

Retrieve Similar Errors

检索相似错误

python
solutions = memory.get_similar_errors("403 error calling API")
python
solutions = memory.get_similar_errors("403 error calling API")

Returns: [{"error": "403 Forbidden...", "solution": "Add User-Agent..."}]

Returns: [{"error": "403 Forbidden...", "solution": "Add User-Agent..."}]

undefined
undefined

Memory Types

记忆类型

┌─────────────────────────────────────────────────────────────┐
│                    MEMORY TYPES                              │
├─────────────────────────────────────────────────────────────┤
│                                                              │
│  EPISODIC                                                    │
│  ├─ Past events and outcomes                                │
│  ├─ "Last time we deployed, X happened"                     │
│  └─ Session summaries                                       │
│                                                              │
│  PROCEDURAL                                                  │
│  ├─ Learned skills and patterns                             │
│  ├─ "How to set up database migrations"                     │
│  └─ Working code patterns                                   │
│                                                              │
│  SEMANTIC                                                    │
│  ├─ Factual knowledge about project                         │
│  ├─ "Database uses PostgreSQL"                              │
│  └─ Architecture decisions                                  │
│                                                              │
│  CAUSAL                                                      │
│  ├─ Error → Solution chains                                 │
│  ├─ "403 error → Add User-Agent header"                     │
│  └─ Self-healing patterns                                   │
│                                                              │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│                    记忆类型                                  │
├─────────────────────────────────────────────────────────────┤
│                                                              │
│  情景记忆(EPISODIC)                                          │
│  ├─ 过去的事件和结果                                        │
│  ├─ "上次部署时发生了X问题"                                   │
│  └─ 会话摘要                                               │
│                                                              │
│  过程记忆(PROCEDURAL)                                        │
│  ├─ 已掌握的技能和模式                                     │
│  ├─ "如何设置数据库迁移"                                     │
│  └─ 可用的代码模式                                           │
│                                                              │
│  语义记忆(SEMANTIC)                                          │
│  ├─ 项目相关的事实性知识                                     │
│  ├─ "数据库使用PostgreSQL"                                    │
│  └─ 架构决策                                                │
│                                                              │
│  因果记忆(CAUSAL)                                          │
│  ├─ 错误→解决方案链                                         │
│  ├─ "403错误 → 添加User-Agent请求头"                         │
│  └─ 自修复模式                                               │
│                                                              │
└─────────────────────────────────────────────────────────────┘

Storage Location

存储位置

project/
└── .claude/
    └── memory/
        ├── episodic.json
        ├── procedural.json
        ├── semantic.json
        └── causal.json
project/
└── .claude/
    └── memory/
        ├── episodic.json
        ├── procedural.json
        ├── semantic.json
        └── causal.json

Causal Memory Pattern

因果记忆模式

python
undefined
python
undefined

Traditional error handling:

传统错误处理:

Error occurs → Unclear response

发生错误 → 响应不明确

Causal memory:

因果记忆:

Error: 403 Forbidden

错误: 403 Forbidden

Memory: [403] → [missing User-Agent] → [added header] → [success]

记忆: [403] → [缺少User-Agent] → [添加请求头] → [成功]

Response: "Adding User-Agent header (learned from previous error)"

响应: "添加User-Agent请求头(从之前的错误中学习到的)"

undefined
undefined

Integration Points

集成点

  • error-recoverer: Uses causal memory for self-healing
  • context-compactor: Stores summaries in episodic memory
  • coding-agent: Stores procedural patterns
  • error-recoverer: 使用因果记忆实现自修复
  • context-compactor: 将摘要存储到情景记忆中
  • coding-agent: 存储过程模式

References

参考资料

  • references/MEMORY-TYPES.md
    - Detailed type documentation
  • references/RETRIEVAL-PATTERNS.md
    - Search patterns
  • references/MEMORY-TYPES.md
    - 详细的记忆类型文档
  • references/RETRIEVAL-PATTERNS.md
    - 检索模式文档

Scripts

脚本文件

  • scripts/memory_manager.py
    - Core MemoryManager
  • scripts/semantic_store.py
    - Keyword-based storage
  • scripts/causal_memory.py
    - Error→Solution chains
  • scripts/knowledge_base.py
    - Project knowledge
  • scripts/memory_manager.py
    - 核心MemoryManager
  • scripts/semantic_store.py
    - 基于关键词的存储
  • scripts/causal_memory.py
    - 错误→解决方案链
  • scripts/knowledge_base.py
    - 项目知识库