> ## Documentation Index
> Fetch the complete documentation index at: https://docs.arouter.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 消息转换

> 使用 context-compression 插件自动压缩超出模型上下文窗口的提示词。

当提示词超过模型的上下文长度时，ARouter 可以使用 `context-compression` 插件自动压缩它。

## 上下文压缩

```json theme={null}
{"model": "anthropic/claude-sonnet-4.6", "messages": [...], "plugins": [{"id": "context-compression"}]}
```

## 工作原理

该插件从对话**中间**删除或截断消息，直到提示词能够放入上下文窗口。这样可以保留开头（系统指令）和末尾（最新消息）。

## 小上下文模型的默认行为

所有**上下文长度为 8,192 个 Token 或更少**的模型默认**启用**上下文压缩。

要显式禁用：

```json theme={null}
{"plugins": [{"id": "context-compression", "enabled": false}]}
```

## 适用场景

以下情况适合使用上下文压缩：

* 你有较长的多轮对话
* 处理可能偶尔超出上下文窗口的文档
* 你想要弹性行为而无需手动管理上下文长度

当需要完美召回时，上下文压缩**不**是理想选择。

## 相关

* [Plugins 概览](/zh/guides/features/plugins-overview)
* [模型变体 :extended](/zh/guides/features/model-variants)
