fix(compress): count tool definitions toward compression trigger - #441
Open
openjiuwen-sync-bot[bot] wants to merge 1 commit into
Open
fix(compress): count tool definitions toward compression trigger#441openjiuwen-sync-bot[bot] wants to merge 1 commit into
openjiuwen-sync-bot[bot] wants to merge 1 commit into
Conversation
trigger_add_messages compared only message tokens against tokens_threshold, so a context whose tool definitions already consumed most of the window could stay over the model limit even after compression ran (#1506). Add the tool-definition token count (context.get_tools() + token_counter.count_tools) to the trigger decision. The accessor and the counter result are guarded: contexts without get_tools() and counters without count_tools() behave exactly as before. Closes #1506. Co-Authored-By: AtomCode (deepseek-v4-flash) <noreply@atomgit.com>
|
|
|
head_sha: 变更摘要本次 PR 修复了 #1506: 主要改动
|
|
head_sha: 代码审查✅ 未发现问题 |
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.
Paired: GitHub #441 ↔ GitCode !2265
Summary
Fixes #1506: context compression was triggered by comparing message tokens only against
tokens_threshold, so a context whose tool definitions already consumed most of the model window could stay over the limit even after compression ran.Change (
openjiuwen/core/context_engine/processor/compressor/current_round_compressor.py)trigger_add_messagesnow adds the tool-definition token count (context.get_tools()→token_counter.count_tools(...)) to the running total before comparing against the threshold.Both access points are guarded so existing behavior is unchanged where the pieces are absent:
getattr(context, "get_tools", None)— contexts that do not exposeget_tools()(e.g.SessionModelContext) skip the tools term entirely (regression fixed after initial attempt crashed them withAttributeError).isinstance(tools_tokens, int)— lightweight token counters that only implementcount_messagesreturn a non-int via mocks/fallbacks; those are ignored rather than polluting the total.Tests (
tests/unit_tests/core/context_engine/test_current_round_compressor.py)Two new cases:
trigger_add_messagesreturnsTrue(regression for #1506)count_toolsnever invokedVerification
uv run pytest tests/unit_tests/core/context_engine/test_current_round_compressor.py— 10 passed (8 existing + 2 new)Linked Closing Issues: