fix(harness): 保留跳过摘要时的轻量上下文裁剪结果 - #2971
Open
yyyzl wants to merge 1 commit into
Open
Conversation
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
关联问题
Fixes #2970
AgentScope-Java Version
2.0.3-SNAPSHOT,基于main的ea511ec2f68ca929a6bbc4e92cd0c0952a38c592。背景与必要性
ConversationCompactor.compactIfNeeded()在判断是否需要 LLM 摘要前,先执行工具参数截断和工具结果裁剪。但下面两个提前返回分支会丢弃已经生成的裁剪结果:这两个分支都返回
Optional.empty()。CompactionMiddleware因此继续传递原始ReasoningInput,也不更新工作AgentState。结果是:轻量裁剪确实执行了,下一次模型请求却仍携带原始大段内容,可能继续触发上下文超限。这与 #2267 / #2319 修复的
ToolResultEvictionMiddleware状态和输入不同步问题不同;本次问题位于ConversationCompactor的提前返回路径。变更内容
Optional.empty()。两个轻量处理方法在无改动时都会返回原列表,因此这里只比较列表引用,不对大段消息做深度比较。
复现与验证
最小输入为一条用户消息、一条工具调用及其匹配结果。工具结果含
"x".repeat(10_000);配置triggerTokens(1_000)、keepTokens(0)、keepMessages(20),以及protectTokens(0)、minimumTokens(1)、maxOutputChars(100)的裁剪策略。裁剪后低于阈值,但原实现仍把原始请求传给next。设置
triggerMessages(3)可覆盖安全切分点为 0 的分支;将大段内容放到write_file参数并启用参数截断,可复现参数截断对应的两个分支。新增 6 个参数化场景:
修复前:4 个裁剪场景全部失败,2 个无变化场景通过。修复后:
ConversationCompactorTest和CompactionMiddlewareTest共 23 项全部通过。此外,
mvn -pl agentscope-harness -am test构建成功:Core 共 2,318 项(跳过 9 项),Harness 共 925 项(跳过 5 项),均为 0 failures / 0 errors。验证环境为 Java 17 / Maven 3.8.7,运行时状态目录隔离到临时测试目录。断言同时检查下游输入、工作状态、原输入不被修改、系统消息和工具调用配对保留、tools/options 透传,并确认轻量裁剪不触发模型调用。测试使用 mock model,不需要模型凭证或网络调用。
当前范围与兼容性
想请维护者确认的取舍
这里保留
Optional<List<Msg>>,将非空结果解释为“存在应应用的替换消息”,不再隐含“一定生成了摘要”。目前仓内两个生产调用点都按替换列表使用结果。希望确认这一返回语义是否符合项目预期;若外部调用方需要区分轻量裁剪和摘要,可另行讨论显式结果类型,本 PR 暂不扩大 API 改动范围。Checklist
mvn spotless:apply。验证范围为 Core/Harness,未宣称其他所有模块的全仓
mvn test已通过。