fix(harness): prevent missed compaction for multilingual contexts - #2990
fix(harness): prevent missed compaction for multilingual contexts#2990guslegend0510 wants to merge 3 commits into
Conversation
Include system prompts, tools, response schemas and reasoning text in compaction estimates. Preserve preprocessing results below the summary threshold and retain history on failed or empty summaries. Fixes agentscope-ai#2985
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
CryoThrust
left a comment
There was a problem hiding this comment.
The new request-overhead accounting is used to decide whether compaction starts, but it is not applied when choosing the preserved tail. compactIfNeeded(..., requestOverheadTokens) calls determineCutoffIndex(messages, totalTokens, config) with conversation-only tokens, and findTokenBasedCutoff still keeps up to the full config.getKeepTokens(). The rebuilt request then adds the same system/tool/response-schema overhead back on top of that tail.\n\nFor example, with keepTokens=800, a preserved 800-token conversation suffix and 400 fixed system/tool/schema tokens, compaction can report success but send roughly 1200 input tokens before the summary itself is counted. This is especially likely for large tool schemas, which is one of the cases this PR explicitly adds to the trigger budget.\n\nCould the cutoff budget be max(0, keepTokens - requestOverheadTokens) (with a documented behavior when the fixed overhead alone exceeds the budget), and could there be a regression test asserting that the post-compaction request estimate, including system/tools/response format, stays within the resolved budget? Otherwise the change detects the overflow earlier but cannot reliably make the final request fit.
AgentScope-Java Version
2.0.3-SNAPSHOT
Description
Fixes #2985
Chinese-heavy conversations could exceed the model's context window before compaction triggered. The estimator used the same character ratio for every language, while the trigger excluded system prompts and tool definitions.
This change:
Token counts remain estimates; exact Qwen tokenizer accuracy and live deployment behavior have not been validated.
Validation
Commands:
Related links
Checklist