46 lines
1.7 KiB
Markdown
46 lines
1.7 KiB
Markdown
---
|
||
title: "Memory Consolidation"
|
||
type: concept
|
||
tags:
|
||
- "agentic-ai"
|
||
- "memory-management"
|
||
- "long-horizon"
|
||
sources:
|
||
- "Your-AI-Isn-t-Stupid---It-Just-Needs-a-Better-Harness--Lychee-Technology-Engineering-Blog"
|
||
last_updated: 2026-04-20
|
||
---
|
||
|
||
## Overview
|
||
Memory Consolidation——Agent 空闲时周期性压缩累积工作日志(去重 + 解决矛盾 + 写入精简状态文件)的机制,防止长期运行 Agent 的记忆膨胀和决策冲突。
|
||
|
||
## Problem
|
||
随着 Agent 长时间运行,记忆日志变得臃肿且矛盾——旧决策与新决策冲突,冗余条目在每次读取时浪费 token。
|
||
|
||
## Solution
|
||
自动化压缩周期:Agent 空闲时(任务之间或低优先级窗口),触发后台作业:
|
||
1. 读取原始日志
|
||
2. 去重条目
|
||
3. 以最新数据为准解决矛盾
|
||
4. 写入干净、压缩的状态文件
|
||
|
||
## Empirical Result
|
||
实测案例:32K token 嘈杂、重复历史 → 压缩为 7K token 干净状态文件,无有意义信息丢失。
|
||
|
||
## Implementation
|
||
```python
|
||
# When agent is idle (between tasks or during low-priority windows)
|
||
def consolidate_memory(raw_logs):
|
||
deduped = deduplicate(raw_logs)
|
||
resolved = resolve_conflicts(deduped, prefer='latest')
|
||
compressed = compress(resolved)
|
||
write_state_file(compressed)
|
||
```
|
||
|
||
## Relationship to Other Concepts
|
||
- [[Agent-Collapse]]:Memory Consolidation 防止状态臃肿导致的决策质量下降
|
||
- [[State-Externalization]]:压缩后的状态以结构化文件形式持久化
|
||
- [[Context-Reset]]:Context Reset 解决当前上下文容量问题,Memory Consolidation 解决长期记忆质量问题——两者互补
|
||
|
||
## Source
|
||
- [[Your-AI-Isn-t-Stupid---It-Just-Needs-a-Better-Harness--Lychee-Technology-Engineering-Blog]]
|