Skip to content

feat(adk): reduction mw support tool_call & tool_resp messages rewrite - #956

Merged
N3kox merged 1 commit into
mainfrom
feat/clear_tool_call
Apr 27, 2026
Merged

feat(adk): reduction mw support tool_call & tool_resp messages rewrite#956
N3kox merged 1 commit into
mainfrom
feat/clear_tool_call

Conversation

@N3kox

@N3kox N3kox commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

feat

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

feat(adk/reduction): 新增 ClearRewriteMessagesHandler 功能,支持工具调用 / 工具返回消息消息重写

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
This PR adds a new ClearRewriteMessagesHandler to the reduction middleware, allowing users to rewrite assistant and tool message pairs through this preprocessing step before actual tool cleanup.

Since directly removing parameters of certain tool calls (such as write_file/edit_file) may cause hallucination, rewriting them as user messages can both retain the tool call records and remove a large amount of content context.

zh(optional):
本 PR 为 reduction 中间件新增了 ClearRewriteMessagesHandler 功能,允许用户在实际的工具清理前,通过这个预处理环节重写助手和工具消息对。

由于直接移除某些工具调用(如 write_file/edit_file)的参数可能导致幻觉,此时将其重写为 user 消息既可以保留工具调用记录,又可以移除大量的 content 上下文。

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

@codecov

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.89%. Comparing base (9b80f95) to head (c7ccebc).

Files with missing lines Patch % Lines
adk/middlewares/reduction/reduction.go 92.85% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #956      +/-   ##
==========================================
+ Coverage   82.87%   82.89%   +0.01%     
==========================================
  Files         148      148              
  Lines       16740    16788      +48     
==========================================
+ Hits        13874    13916      +42     
- Misses       1904     1911       +7     
+ Partials      962      961       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@N3kox
N3kox force-pushed the feat/clear_tool_call branch 2 times, most recently from ea8f6d6 to 607ee0b Compare April 13, 2026 13:53
@N3kox
N3kox marked this pull request as ready for review April 14, 2026 03:07
Comment thread adk/middlewares/reduction/reduction.go Outdated
Comment thread adk/middlewares/reduction/reduction.go Outdated
@shentongmartin shentongmartin added C-enhancement Category: This is a PR that adds a new feature or fixes a bug. D-adk Domain: this is an issue related to the adk package labels Apr 20, 2026
Comment thread adk/middlewares/reduction/reduction.go Outdated
@N3kox
N3kox force-pushed the feat/clear_tool_call branch from 607ee0b to 264800f Compare April 27, 2026 12:50
Comment thread adk/middlewares/reduction/reduction.go Outdated
rewritten = append(rewritten, rewrittenMessages...)
i = trEnd
default: // unexpected
i++

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

或者返回 error 吧?

@N3kox
N3kox force-pushed the feat/clear_tool_call branch 2 times, most recently from 50d1292 to bdcb895 Compare April 27, 2026 13:06
@N3kox
N3kox force-pushed the feat/clear_tool_call branch from bdcb895 to c7ccebc Compare April 27, 2026 13:17
@N3kox
N3kox merged commit 4eafc54 into main Apr 27, 2026
19 checks passed
@N3kox
N3kox deleted the feat/clear_tool_call branch April 27, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement Category: This is a PR that adds a new feature or fixes a bug. D-adk Domain: this is an issue related to the adk package

Development

Successfully merging this pull request may close these issues.

3 participants