memory
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMemory Management
内存管理
Efficient context and knowledge management.
高效的上下文与知识管理。
Instructions
操作指南
1. Working Memory Model
1. 工作内存模型
┌─────────────────────────────────────────┐
│ WORKING MEMORY │
├─────────────────────────────────────────┤
│ • Current task goal │
│ • Relevant file contents │
│ • Recent decisions │
│ • Active constraints │
└─────────────────────────────────────────┘
↑ Load ↓ Store
┌─────────────────────────────────────────┐
│ LONG-TERM MEMORY │
├─────────────────────────────────────────┤
│ • Project structure │
│ • User preferences │
│ • Past solutions │
│ • Domain knowledge │
└─────────────────────────────────────────┘┌─────────────────────────────────────────┐
│ WORKING MEMORY │
├─────────────────────────────────────────┤
│ • Current task goal │
│ • Relevant file contents │
│ • Recent decisions │
│ • Active constraints │
└─────────────────────────────────────────┘
↑ Load ↓ Store
┌─────────────────────────────────────────┐
│ LONG-TERM MEMORY │
├─────────────────────────────────────────┤
│ • Project structure │
│ • User preferences │
│ • Past solutions │
│ • Domain knowledge │
└─────────────────────────────────────────┘2. Context Prioritization
2. 上下文优先级排序
Order of importance for context:
| Priority | Content | Action |
|---|---|---|
| 🔴 Critical | Current task, active file | Always keep |
| 🟠 High | Related files, types | Keep if relevant |
| 🟡 Medium | Project structure | Summarize |
| 🟢 Low | History, logs | Forget if needed |
上下文重要性排序:
| 优先级 | 内容 | 操作 |
|---|---|---|
| 🔴 关键 | 当前任务、活跃文件 | 始终保留 |
| 🟠 高 | 相关文件、类型 | 相关时保留 |
| 🟡 中 | 项目结构 | 进行总结 |
| 🟢 低 | 历史记录、日志 | 必要时丢弃 |
3. Information Retention
3. 信息保留规则
markdown
undefinedmarkdown
undefinedWhat to Remember
需要保留的内容
✅ Keep in context:
- Current task objective
- File being modified
- Type definitions in use
- Recent error messages
- User preferences
❌ Safe to forget:
- Already processed files
- Resolved errors
- Intermediate calculations
- Verbose logs
undefined✅ 保留在上下文中:
- 当前任务目标
- 正在修改的文件
- 正在使用的类型定义
- 近期错误信息
- 用户偏好
❌ 可安全丢弃的内容:
- 已处理完成的文件
- 已解决的错误
- 中间计算过程
- 冗长的日志
undefined4. Context Summarization
4. 上下文总结
When context grows too large:
markdown
undefined当上下文规模过大时:
markdown
undefinedSummarization Rules
总结规则
- Files: Keep imports, types, key functions
- Errors: Keep message, remove stack trace
- Logs: Keep last 10 lines
- History: Keep decisions, remove process
- 文件:保留导入语句、类型、核心函数
- 错误:保留错误信息,移除堆栈跟踪
- 日志:保留最后10行
- 历史记录:保留决策结果,移除过程细节
Example
示例
Before (verbose):
"I looked at file A, then file B, noticed pattern X,
then explored file C, found issue Y, traced it to..."
After (summarized):
"Analyzed A, B, C. Found: pattern X, issue Y in C."
undefined总结前(冗长):
"我查看了文件A,然后是文件B,发现了模式X,
then explored file C,found issue Y,traced it to..."
总结后(精简):
"分析了A、B、C文件。发现:模式X,文件C中的问题Y。"
undefined5. Session State Pattern
5. 会话状态模式
typescript
// Conceptual session state
interface SessionMemory {
// Always retain
task: {
goal: string;
status: 'planning' | 'executing' | 'verifying';
progress: number;
};
// Retain while relevant
context: {
activeFiles: string[];
recentDecisions: string[];
constraints: string[];
};
// Summarize or forget
history: {
summary: string;
keyInsights: string[];
};
}typescript
// Conceptual session state
interface SessionMemory {
// Always retain
task: {
goal: string;
status: 'planning' | 'executing' | 'verifying';
progress: number;
};
// Retain while relevant
context: {
activeFiles: string[];
recentDecisions: string[];
constraints: string[];
};
// Summarize or forget
history: {
summary: string;
keyInsights: string[];
};
}6. Knowledge Retrieval
6. 知识检索
markdown
undefinedmarkdown
undefinedBefore Starting New Task
开始新任务前
- Check: Have I seen this before?
- Recall: What approach worked?
- Apply: Use proven patterns
- Adapt: Modify for current context
undefined- 检查:我之前处理过类似任务吗?
- 回忆:之前的解决方法是什么?
- 应用:使用已验证的模式
- 调整:根据当前上下文修改方案
undefined7. Memory Hygiene
7. 内存维护
markdown
undefinedmarkdown
undefinedPer-Turn Cleanup
每轮步骤完成后清理
After completing a step:
- ✅ Task still relevant? Keep
- ❓ Might need later? Summarize
- ❌ No longer needed? Forget
完成一个步骤后:
- ✅ 任务仍相关?保留
- ❓ 后续可能需要?进行总结
- ❌ 不再需要?丢弃
End of Task
任务结束后
- Extract learnings
- Update knowledge base
- Clear working memory
undefined- 提取经验教训
- 更新知识库
- 清空工作内存
undefined8. Context Window Management
8. 上下文窗口管理
markdown
undefinedmarkdown
undefinedToken Budget Allocation
Token 预算分配
| Category | Budget |
|---|---|
| System prompt | 10% |
| Task context | 30% |
| Active code | 40% |
| Conversation | 20% |
| 类别 | 预算占比 |
|---|---|
| 系统提示词 | 10% |
| 任务上下文 | 30% |
| 活跃代码 | 40% |
| 对话内容 | 20% |
When Near Limit
接近预算上限时
- Summarize conversation history
- Remove resolved issues
- Keep only relevant code sections
- Preserve critical context
undefined- 总结对话历史
- 移除已解决的问题
- 仅保留相关代码片段
- 保留关键上下文
undefined