# 本章小结

### 本章小结

本章探讨了上下文工程的压缩策略，涵盖信息密度原理、摘要技术、对话历史管理和优化方法。

#### 关键概念清单

| 概念    | 定义                 |
| ----- | ------------------ |
| 信息密度  | 单位 Token 中包含的有效信息量 |
| 抽取式压缩 | 从原文中选择关键内容         |
| 生成式压缩 | 使用 LLM 生成精简表述      |
| 递进式摘要 | 分层次逐步压缩长文档         |
| 滑动窗口  | 只保留最近 N 轮对话的策略     |
| 上下文预算 | 为不同组成部分分配 Token 配额 |

#### 核心观点

1. **压缩是必要的优化**：
   * 控制 Token 用量和成本
   * 提高上下文利用效率
   * 改善响应延迟
2. **压缩方法各有适用场景**：
   * 抽取式：需要精确引用
   * 生成式：需要流畅表达
   * 信息提取：需要结构化数据
3. **对话历史需要专门管理**：
   * 结合滑动窗口和压缩
   * 保留关键信息点
   * 分层次管理不同时间距离的内容
4. **上下文优化是系统工程**：
   * 预算分配
   * 格式优化
   * 缓存复用
   * 持续监控

#### 常见误区

* **误区一**：压缩就是截断 **正解**：压缩是提炼精华，需要保留关键信息
* **误区二**：压缩率越高越好 **正解**：需要在压缩率和信息完整性之间平衡
* **误区三**：一次压缩永久使用 **正解**：不同任务可能需要不同的压缩版本

#### 实践建议

1. **建立 Token 预算**：明确各部分的 Token 分配
2. **优化最大消耗点**：通常是检索内容和对话历史
3. **组合多种策略**：摘要 + 提取 + 窗口管理
4. **监控优化效果**：对比压缩前后的任务效果和成本
5. **保留原始信息**：压缩结果可能需要回溯验证

#### 预告

### 下一章将讨论隔离策略——如何通过结构化组织提升上下文的清晰度和有效性，包括 XML 标签、指令分层和多任务隔离技术。

> 📝 **发现错误或有改进建议？** 欢迎提交 [Issue](https://github.com/yeasy/context_engineering_guide/issues) 或 [PR](https://github.com/yeasy/context_engineering_guide/pulls)。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/context_engineering_guide/di-er-bu-fen-he-xin-ji-shu-yu-ce-le/06_compress/summary.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
