feat: 添加报告压缩功能解决上下文超限问题 #551
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题描述
在使用 ReportEngine 生成报告时,三个引擎报告(query_engine, media_engine, insight_engine)的总大小约 60KB+,导致 LLM 上下文超限,报错:
即使使用 200k 上下文的
claude-opus-4-5模型也会超限。解决方案
实现两阶段差异化压缩策略:
阶段1-2(文档设计 + 篇幅规划)
阶段3(章节生成)
实现细节
新增文件
ReportEngine/utils/report_compressor.py- 报告压缩器核心类(约400行)修改文件
ReportEngine/utils/config.py- 添加8个压缩配置项ReportEngine/agent.py- 集成压缩器,实现两阶段策略ReportEngine/nodes/chapter_generation_node.py- 添加动态内容提取docker-compose.yml- 添加 ReportEngine 目录挂载新增配置项
功能特性
ENABLE_REPORT_COMPRESSION=False完全禁用测试验证
预期效果
日志示例
风险与缓解
信息丢失风险(中等)
可能丢失:详细描述、示例说明、过渡段落
缓解措施:
ENABLE_REPORT_COMPRESSION=False)性能影响(低)
相关 Issue
解决了报告生成时的上下文超限问题。
测试清单
后续优化方向