You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Verified against main @ 7399ed6 by source-level analysis (no build/run: this is a read-only check).
Root cause: the compaction trigger is compared against a character-ratio estimate that is not language-aware. TokenCounterUtil uses one constant for every script — agentscope-harness/src/main/java/io/agentscope/harness/agent/memory/compaction/TokenCounterUtil.java:49 (CHARS_PER_TOKEN = 2.5), applied at :224-225 (Math.ceil(text.length() / CHARS_PER_TOKEN)). ConversationCompactor gates solely on that value: :110-111 computes totalTokens and :226 returns true only when totalTokens >= config.getTriggerTokens().
For Chinese-dominant content a real BPE tokenizer lands near ~1 character/token, so the estimator reports roughly half the true count — which matches your observation exactly: ~38k estimated vs. 76789 inputTokens from the model, with triggerTokens=70000 never reached. Compaction therefore never fires and the request overflows.
Impact: the memory-compaction safety mechanism silently fails for CJK-heavy workloads; the run dies on context overflow instead of compacting. Severity: high.
Conservative fix directions (no heavyweight tokenizer forced into core by default):
CJK-aware weighting in estimateTextTokens — keep the ASCII ratio, use a lower ratio for non-ASCII code points; dependency-free.
Make the ratio configurable (charsPerToken / cjkCharsPerToken) on the compaction config instead of a private constant.
A pluggable TokenEstimator interface with the current char-based implementation as the default, so model-specific counters can be injected.
Two caveats for whoever fixes this: estimated counts are computed on demand and not persisted, so no cache invalidation is needed, but PruneConfig / TruncateArgsConfig thresholds are expressed in the same estimator units — tightening the estimate changes their effective aggressiveness and may need re-tuning by users who set them from observed token counts.
No automated PR will be generated for this issue:#2990 (fix(harness): prevent missed compaction for multilingual contexts, @guslegend0510, non-draft, mergeable, REVIEW_REQUIRED) already claims this issue and takes direction (1) plus additional scope (system prompt / tool definitions / response-schema inclusion in the trigger budget, primary-model context window when a separate summary model is configured, truncation/pruning when summarization is skipped). Reviewing there avoids two competing fixes in the same estimator and trigger code paths.
Activity
oss-maintainer commentedon Sep 13, 2026
Issue Evaluation
Category:
bug| Status: ConfirmedVerified against
main@7399ed6by source-level analysis (no build/run: this is a read-only check).Root cause: the compaction trigger is compared against a character-ratio estimate that is not language-aware.
TokenCounterUtiluses one constant for every script —agentscope-harness/src/main/java/io/agentscope/harness/agent/memory/compaction/TokenCounterUtil.java:49(CHARS_PER_TOKEN = 2.5), applied at:224-225(Math.ceil(text.length() / CHARS_PER_TOKEN)).ConversationCompactorgates solely on that value::110-111computestotalTokensand:226returnstrueonly whentotalTokens >= config.getTriggerTokens().For Chinese-dominant content a real BPE tokenizer lands near ~1 character/token, so the estimator reports roughly half the true count — which matches your observation exactly: ~38k estimated vs. 76789
inputTokensfrom the model, withtriggerTokens=70000never reached. Compaction therefore never fires and the request overflows.Impact: the memory-compaction safety mechanism silently fails for CJK-heavy workloads; the run dies on context overflow instead of compacting. Severity: high.
Conservative fix directions (no heavyweight tokenizer forced into core by default):
estimateTextTokens— keep the ASCII ratio, use a lower ratio for non-ASCII code points; dependency-free.charsPerToken/cjkCharsPerToken) on the compaction config instead of a private constant.TokenEstimatorinterface with the current char-based implementation as the default, so model-specific counters can be injected.Two caveats for whoever fixes this: estimated counts are computed on demand and not persisted, so no cache invalidation is needed, but
PruneConfig/TruncateArgsConfigthresholds are expressed in the same estimator units — tightening the estimate changes their effective aggressiveness and may need re-tuning by users who set them from observed token counts.No automated PR will be generated for this issue: #2990 (
fix(harness): prevent missed compaction for multilingual contexts, @guslegend0510, non-draft, mergeable,REVIEW_REQUIRED) already claims this issue and takes direction (1) plus additional scope (system prompt / tool definitions / response-schema inclusion in the trigger budget, primary-model context window when a separate summary model is configured, truncation/pruning when summarization is skipped). Reviewing there avoids two competing fixes in the same estimator and trigger code paths.Automated evaluation by github-manager-bot