Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
32701aa3
authored
Jun 22, 2026
by
YeYuheng
Committed by
GitHub
Jun 22, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize context compression algorithm (#7052)
parent
8b19376a
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
156 additions
and
20 deletions
+156
-20
packages/service/core/ai/llm/compress/constants.ts
+9
-8
packages/service/core/ai/llm/compress/index.ts
+0
-0
packages/service/core/ai/llm/compress/prompt.ts
+147
-12
packages/service/test/core/ai/llm/compress/index.test.ts
+0
-0
No files found.
packages/service/core/ai/llm/compress/constants.ts
View file @
32701aa3
...
@@ -3,20 +3,21 @@
...
@@ -3,20 +3,21 @@
*
*
* ## 设计原则
* ## 设计原则
*
*
* 1. **空间分配**
* 1. **压缩触发水位**
* - 输出预留:30%(模型生成答案 + 缓冲)
* - Depends on:超过上下文 15% 后压缩
* - 系统提示词(Depends on):15%
* - Agent 对话历史:超过上下文 80% 后压缩
* - Agent 对话历史:55%
* - 单个 tool response / 文件读取结果:超过上下文 50% 后压缩
* - 知识库检索结果:超过上下文 20% 后触发相关性筛选
*
*
* 2. **压缩策略**
* 2. **压缩策略**
* - 触发阈值:接近空间上限时触发
* - 触发阈值:接近空间上限时触发
* - 压缩目标:保留可续跑上下文,具体摘要粒度交给模型判断
* - 压缩目标:保留可续跑上下文,具体摘要粒度交给模型判断
* - 约束机制:
单个 tool 有绝对大小限制
* - 约束机制:
最终结果用真实 token 校验,LLM 输出长度只通过 prompt 软约束
*
*
* 3. **协调关系**
* 3. **协调关系**
* - Depends on 使用完整 response,
需要较大空间(15%)
* - Depends on 使用完整 response,
先在较小水位触发
* - Agent 历史包含
所有 tool responses,是动态主体(55%)
* - Agent 历史包含
多轮 user/assistant/tool 消息,接近上下文上限才整体 checkpoint
* - 单个 tool
不能过大,避免挤占其他空间(10%)
* - 单个 tool
/file response 不能过大,避免挤占后续对话和模型输出空间
*/
*/
export
const
COMPRESSION_CONFIG
=
{
export
const
COMPRESSION_CONFIG
=
{
...
...
packages/service/core/ai/llm/compress/index.ts
View file @
32701aa3
This diff is collapsed.
Click to expand it.
packages/service/core/ai/llm/compress/prompt.ts
View file @
32701aa3
This diff is collapsed.
Click to expand it.
packages/service/test/core/ai/llm/compress/index.test.ts
View file @
32701aa3
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment