Skip to content

feat(async-context-compression): add compression style control#78

Merged
Fu-Jie merged 1 commit into
Fu-Jie:mainfrom
NexZhu:feat/async-context-compression-style-control
May 22, 2026
Merged

feat(async-context-compression): add compression style control#78
Fu-Jie merged 1 commit into
Fu-Jie:mainfrom
NexZhu:feat/async-context-compression-style-control

Conversation

@NexZhu
Copy link
Copy Markdown
Contributor

@NexZhu NexZhu commented May 22, 2026

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+).

image image

This PR add compression style control with a new compression_style config and three prompts to adjust the compression behavior.

Change

  • Add compression_style to Async Context Compression with aggressive, balanced, and faithful summary
    modes.
  • Release Async Context Compression v1.6.5 with 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.py
  • git diff --check
  • ../.venv/bin/python -m unittest -k summary_prompt plugins/filters/async-context-compression/ test_async_context_compression.py

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

此拉取请求将异步上下文压缩过滤器更新至 1.6.5 版本,引入了 compression_style 配置项以支持 aggressive、balanced 和 faithful 三种压缩风格。更改涉及多语言文档更新、Prompt 构建逻辑优化及单元测试完善。审查反馈指出,Valves 类字段命名应遵循仓库规范使用大写蛇形命名法,建议将 compression_style 更名为 COMPRESSION_STYLE,并同步修正文档、代码实现及测试脚本中的所有相关引用。

"the caller (useful for debugging or surfacing breakage hard)."
),
)
compression_style: Literal["aggressive", "balanced", "faithful"] = Field(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

根据仓库规范(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
  1. 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")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

建议同步更新字段名访问方式。既然 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
  1. Valves(BaseModel) with UPPER_SNAKE_CASE fields (link)

)

def test_build_summary_prompt_supports_aggressive_style(self):
self.filter.valves.compression_style = "aggressive"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

更新测试代码以匹配 Valves 字段名的修改。

Suggested change
self.filter.valves.compression_style = "aggressive"
self.filter.valves.COMPRESSION_STYLE = "aggressive"

)

def test_build_summary_prompt_supports_faithful_style(self):
self.filter.valves.compression_style = "faithful"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

更新测试代码以匹配 Valves 字段名的修改。

Suggested change
self.filter.valves.compression_style = "faithful"
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"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

更新测试代码以匹配 Valves 字段名的修改。

Suggested change
self.filter.valves.compression_style = "verbose"
self.filter.valves.COMPRESSION_STYLE = "verbose"

@NexZhu NexZhu force-pushed the feat/async-context-compression-style-control branch from c7d8340 to 1437cfd Compare May 22, 2026 13:11
@Fu-Jie Fu-Jie merged commit 7674062 into Fu-Jie:main May 22, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants