Files
myWiki/concepts/context-compression.md

32 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Context Compression上下文压缩"
created: 2026-05-11
updated: 2026-05-11
type: concept
tags: [context-management, summarization, agent-architecture]
sources: [[prompt-caching-architecture]]
---
# Context Compression上下文压缩
## 定义
Context Compression 是当 Agent 对话长度触及 Context Window 限制时,对历史对话进行摘要压缩的技术。其核心挑战是在压缩过程中避免触发 [[cache-invalidation|缓存失效]]。
## 两种压缩方式
| 方式 | 做法 | 缓存影响 |
|------|------|----------|
| 传统(错误) | 独立 API 调用,使用默认 System Prompt | 前缀不一致 → 缓存全失效 |
| [[cache-safe-forking|Cache-Safe Forking]] | 复用父会话完整前缀 | 仅最后几百 Token 需计算 |
## 工程陷阱
最常见的错误:发起新的独立 API 调用请求总结,该调用使用与原始会话不同的 System Prompt → 完全前缀不一致 → 成本剧增。
## 相关概念
- [[cache-safe-forking|缓存安全分叉]]
- [[prompt-caching|Prompt Caching]]
- [[agentic-systems|Agentic Systems]]