Skip to content

Commit 36f058d

Browse files
committed
docs: add Context Compression feature and related documentation
1 parent 2e4109d commit 36f058d

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

.vitepress/config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export default defineConfig({
172172
{ text: "自定义规则", link: "/custom-rules" },
173173
{ text: "Agent 执行器", link: "/agent-runner" },
174174
{ text: "统一 Webhook 模式", link: "/unified-webhook" },
175+
{ text: "自动上下文压缩", link: "/context-compress" },
175176
{ text: "沙箱化代码执行器(beta)", link: "/code-interpreter" },
176177
],
177178
},
@@ -394,6 +395,7 @@ export default defineConfig({
394395
{ text: "Custom Rules", link: "/custom-rules" },
395396
{ text: "Agent Runner", link: "/agent-runner" },
396397
{ text: "Unified Webhook Mode", link: "/unified-webhook" },
398+
{ text: "Auto Context Compression", link: "/context-compress" },
397399
{ text: "Sandboxed Code Interpreter (beta)", link: "/code-interpreter" },
398400
],
399401
},

en/use/context-compress.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Context Compression
2+
3+
Starting from v4.11.0, AstrBot introduced an automatic context compression feature.
4+
5+
![alt text](/source/images/context-compress/image.png)
6+
7+
AstrBot automatically compresses the context when the conversation context **reaches 82% of the maximum context window length of the conversation model being used**, ensuring that as much conversation content as possible is retained without losing key information.
8+
9+
## Compression Strategies
10+
11+
There are currently two compression strategies:
12+
13+
1. Truncate by conversation rounds. This strategy simply removes the earliest conversation content until the context length meets the requirements. You can specify the number of conversation rounds to discard at once, with a default of 1 round. This is the **default strategy**.
14+
2. LLM-based context compression. This strategy calls the model itself to summarize and compress the conversation content, thereby retaining more key information. You can specify the conversation model to use for compression; if not selected, it will automatically fall back to the "truncate by conversation rounds" strategy. You can set the number of recent conversation rounds to retain during compression, with a default of 4. You can also customize the prompt used during compression. The default prompt is:
15+
16+
```
17+
Based on our full conversation history, produce a concise summary of key takeaways and/or project progress.
18+
1. Systematically cover all core topics discussed and the final conclusion/outcome for each; clearly highlight the latest primary focus.
19+
2. If any tools were used, summarize tool usage (total call count) and extract the most valuable insights from tool outputs.
20+
3. If there was an initial user goal, state it first and describe the current progress/status.
21+
4. Write the summary in the user's language.
22+
```
23+
24+
After one round of compression, AstrBot will perform a secondary check to verify if the current context length meets the requirements. If it still doesn't meet the requirements, it will adopt a halving strategy, cutting the current context content in half until the requirements are met.
25+
26+
- AstrBot will invoke the compressor for checking before each conversation request.
27+
- In the current version, AstrBot does not perform context compression during tool invocations. We will support this feature in the future, so stay tuned.
28+
29+
## ‼️ Important: Model Context Window Settings
30+
31+
By default, when you add a model, AstrBot automatically retrieves the model's context window size from the API provided by [MODELS.DEV](https://models.dev/) based on the model's ID. However, due to the wide variety of models and the fact that some providers even modify the model IDs, AstrBot cannot automatically infer the context window size for all models you add.
32+
33+
You can manually set the model's context window size in the model configuration, as shown in the image below:
34+
35+
![alt text](/source/images/context-compress/image1.png)
36+
37+
> [!NOTE]
38+
> If you don't see the configuration option shown in the image above, please delete the model and re-add it.
39+
40+
When the model context window size is set to 0, AstrBot will still automatically retrieve the model's context window size from MODELS.DEV for each request. If it remains 0, context compression will not be enabled for that request.
163 KB
Loading
304 KB
Loading

zh/use/context-compress.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# 上下文压缩
2+
3+
在 v4.11.0 之后,AstrBot 引入了自动上下文压缩功能。
4+
5+
![alt text](/source/images/context-compress/image.png)
6+
7+
AstrBot 会在对话上下文达到**使用的对话模型上下文窗口的最大长度的 82% 时**,自动对上下文进行压缩,以确保在不丢失关键信息的情况下,尽可能多地保留对话内容。
8+
9+
## 压缩策略
10+
11+
目前有两种压缩策略
12+
13+
1. 按照对话轮数截断。这种策略会简单地删除最早的对话内容,直到上下文长度符合要求。您可以指定一次性丢弃的对话轮数,默认为 1 轮。这种策略为**默认策略**
14+
2. 由 LLM 压缩上下文。这种策略会调用您指定的模型本身来总结和压缩对话内容,从而保留更多的关键信息。您可以指定压缩时使用的对话模型,如果不选择,将会自动回退到 “按照对话轮数截断” 策略。您可以设置压缩时保留最近对话轮数,默认为 4。您还可以自定义压缩时的提示词。默认提示词为:
15+
16+
```
17+
Based on our full conversation history, produce a concise summary of key takeaways and/or project progress.
18+
1. Systematically cover all core topics discussed and the final conclusion/outcome for each; clearly highlight the latest primary focus.
19+
2. If any tools were used, summarize tool usage (total call count) and extract the most valuable insights from tool outputs.
20+
3. If there was an initial user goal, state it first and describe the current progress/status.
21+
4. Write the summary in the user's language.
22+
```
23+
24+
在压缩一轮之后,AstrBot 会二次检查当前上下文长度是否符合要求。如果仍然不符合要求,则会采用对半砍策略,即将当前上下文内容砍掉一半,直到符合要求为止。
25+
26+
- AstrBot 会在每次对话请求前调用压缩器进行检查。
27+
- 当前版本下 AstrBot 不会在工具调用过程中进行上下文压缩,未来我们会支持这一功能,敬请期待。
28+
29+
## ‼️ 重要:模型上下文窗口设置
30+
31+
默认情况下,当您添加模型时,AstrBot 会自动根据模型的 id,从 [MODELS.DEV](https://models.dev/) 提供的接口中获取模型的上下文窗口大小。但由于模型种类繁多,部分提供商甚至会修改模型的 id,因此 AstrBot 不能自动推断出您所添加的模型的上下文窗口大小。
32+
33+
您可以手动在模型配置中设置模型的上下文窗口大小,参考下图:
34+
35+
![alt text](/source/images/context-compress/image1.png)
36+
37+
> [!NOTE]
38+
> 如果没有看到上图中的配置项,请您删除该模型,然后重新添加模型即可。
39+
40+
当模型上下文窗口大小被设置为 0 时,在每次请求时,AstrBot 仍会自动从 MODELS.DEV 获取模型的上下文窗口大小。如果仍为 0,则这次请求不会启用上下文压缩功能。
41+

0 commit comments

Comments
 (0)