Merged
Conversation
d7660fe to
5609e6f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## alpha/08 #746 +/- ##
===========================================
Coverage ? 80.04%
===========================================
Files ? 145
Lines ? 15266
Branches ? 0
===========================================
Hits ? 12220
Misses ? 2083
Partials ? 963 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5609e6f to
7ac19a9
Compare
8b3de42 to
b1fbde2
Compare
c119c56 to
b6ded0a
Compare
mrh997
reviewed
Feb 4, 2026
mrh997
reviewed
Feb 4, 2026
b6ded0a to
34aa0fc
Compare
mrh997
reviewed
Feb 4, 2026
b70f5fa to
419a3e8
Compare
419a3e8 to
8f1bba1
Compare
mrh997
reviewed
Feb 4, 2026
| ToolOffload: &ToolOffload{ | ||
| TokenCounter: defaultTokenCounter, | ||
| ToolOffloadThreshold: &ToolOffloadThresholdConfig{ | ||
| MaxTokens: 300000, |
Contributor
There was a problem hiding this comment.
300k 是不是定太大了,现在的模型上下文窗口基本 200k 以下
8f1bba1 to
afcef83
Compare
1e62bd2 to
e52ae49
Compare
shentongmartin
approved these changes
Feb 4, 2026
hi-pender
pushed a commit
that referenced
this pull request
Feb 14, 2026
* feat(adk): tool reduction middleware * refactor(adk): move ancient reduction middleware to internal package * chore(adk): reduction mw add i18n, rename TokenCounter * chore(adk): add reduction mw comments * chore(adk): refactor reduction mw config field, tool stream copy
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.
What type of PR is this?
Check the PR title.
(Optional) Translate the PR title into Chinese.
重构 ADK 工具上下文压缩中间件(Tool Reduction Middleware)
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
This PR introduces a tool context reduction middleware in ADK that supports per-tool configurable truncation of tool outputs (by max content length and max line length) for both invokable and streamable tools, and a token-based offload mechanism that, once the estimated tokens of conversation messages exceed a configurable threshold, offloads full tool results to a pluggable backend (with a default in-memory backend and /tmp file-path strategy) while replacing in-context content with a short reference string, along with utilities such as default tokenizer, default offload handler, and comprehensive unit tests covering truncation, offload, and default middleware construction behaviors.
zh(optional):
本 PR 在 ADK 中新增 context 压缩 middleware,支持按工具配置输出截断策略(包括按整体长度和单行长度截断),同时在对话消息估算 token 数超过可配置阈值时,对工具调用结果进行自动卸载 (offloading),将完整结果写入可插拔后端存储(默认使用内存文件系统与 "/tmp" 路径),并在上下文中以短提示文案替代原始内容;同时提供默认分词器、默认 offload 处理逻辑、默认压缩 middleware 配置,并补充了覆盖截断逻辑、offload 流程以及默认中间件构造的单元测试
(Optional) Which issue(s) this PR fixes:
(optional) The PR that updates user documentation: