feat(async-context-compression): add compression style control#78
Merged
Fu-Jie merged 1 commit intoMay 22, 2026
Merged
Conversation
| "the caller (useful for debugging or surfacing breakage hard)." | ||
| ), | ||
| ) | ||
| compression_style: Literal["aggressive", "balanced", "faithful"] = Field( |
There was a problem hiding this comment.
根据仓库规范(Repository Style Guide 第 53 行),Valves 类中的字段应使用 UPPER_SNAKE_CASE 命名。建议将 compression_style 修改为 COMPRESSION_STYLE。
Suggested change
| compression_style: Literal["aggressive", "balanced", "faithful"] = Field( | |
| COMPRESSION_STYLE: Literal["aggressive", "balanced", "faithful"] = Field( |
References
- Valves(BaseModel) with UPPER_SNAKE_CASE fields (link)
|
|
||
| def _get_compression_style(self) -> str: | ||
| """Return a normalized compression style with a safe fallback.""" | ||
| style = getattr(self.valves, "compression_style", "balanced") |
There was a problem hiding this comment.
建议同步更新字段名访问方式。既然 COMPRESSION_STYLE 已经在 Valves 中定义,可以直接通过 self.valves.COMPRESSION_STYLE 访问,或者更新 getattr 中的属性名。
Suggested change
| style = getattr(self.valves, "compression_style", "balanced") | |
| style = getattr(self.valves, "COMPRESSION_STYLE", "balanced") |
References
- Valves(BaseModel) with UPPER_SNAKE_CASE fields (link)
| ) | ||
|
|
||
| def test_build_summary_prompt_supports_aggressive_style(self): | ||
| self.filter.valves.compression_style = "aggressive" |
| ) | ||
|
|
||
| def test_build_summary_prompt_supports_faithful_style(self): | ||
| self.filter.valves.compression_style = "faithful" |
| ) | ||
|
|
||
| def test_build_summary_prompt_falls_back_to_balanced_for_unknown_style(self): | ||
| self.filter.valves.compression_style = "verbose" |
c7d8340 to
1437cfd
Compare
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.
Problem/Requirement
Users have different requirements for context compression, some prefer aggressive compression to save more input tokens, som prefer keeping more precise context at the price for more input tokens. Currently even though I set higher max_summary_tokens (50000), the filter still compressed the context very agressively (down to 6000 tokens from 100000+).
This PR add compression style control with a new
compression_styleconfig and three prompts to adjust the compression behavior.Change
compression_styleto Async Context Compression withaggressive,balanced, andfaithfulsummarymodes.
v1.6.5with updated English/Chinese docs, docs-site pages, index metadata,and release notes.
Verification
../.venv/bin/python -m py_compile plugins/filters/async-context-compression/async_context_compression.pygit diff --check../.venv/bin/python -m unittest -k summary_prompt plugins/filters/async-context-compression/ test_async_context_compression.py