feat(adk): export NewEventSenderToolWrapper for customizable tool event position#926
Merged
shentongmartin merged 1 commit intoalpha/09from Apr 1, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha/09 #926 +/- ##
===========================================
Coverage ? 81.46%
===========================================
Files ? 158
Lines ? 18902
Branches ? 0
===========================================
Hits ? 15399
Misses ? 2367
Partials ? 1136 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
0a17522 to
66ddc57
Compare
66ddc57 to
13eb46d
Compare
…nt position Change-Id: I273d897c22489b19cda204e257cf1c9050e28280
13eb46d to
04527e2
Compare
N3kox
approved these changes
Apr 1, 2026
shentongmartin
added a commit
that referenced
this pull request
Apr 7, 2026
shentongmartin
added a commit
that referenced
this pull request
Apr 8, 2026
shentongmartin
added a commit
that referenced
this pull request
Apr 8, 2026
mrh997
pushed a commit
that referenced
this pull request
Apr 10, 2026
shentongmartin
added a commit
that referenced
this pull request
Apr 13, 2026
shentongmartin
added a commit
that referenced
this pull request
Apr 14, 2026
N3kox
pushed a commit
that referenced
this pull request
Apr 14, 2026
shentongmartin
added a commit
that referenced
this pull request
Apr 14, 2026
shentongmartin
added a commit
that referenced
this pull request
Apr 15, 2026
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.
Summary
eventSenderToolHandlerwas unexported and unconditionally injected, giving users no control over when tool-resultAgentEvents fire in the middleware chain. The model side already hadNewEventSenderModelWrapperfor this.NewEventSenderToolHandler() ChatModelAgentMiddlewareso users place it inHandlers, controlling its position. Converge default and user paths onto the singleeventSenderToolWrapperimplementation.Key Insight
The model event sender used a clean interface type-assertion for detection (
handler.(*eventSenderModelWrapper)), while the initial tool implementation usedsync.Map+reflect.ValueOf().Pointer()becausecompose.ToolMiddlewareis a struct, not an interface. Switching the tool event sender to aChatModelAgentMiddleware(just like the model wrapper) eliminated this asymmetry — both now use the same detection pattern. The default path also converges: it creates aNewEventSenderToolHandler()and adapts it throughhandlersToToolMiddlewares, eliminating the oldeventSenderToolHandlerstruct entirely.What Changed
adk/wrappers.goeventSenderToolHandlerstruct and its 4 compose-level methods (141 lines of dead code after convergence).eventSenderToolWrapperstruct implementingChatModelAgentMiddlewarewith 4Wrap*ToolCallmethods.NewEventSenderToolHandler() ChatModelAgentMiddlewareconstructor.hasUserEventSenderToolHandler()using type assertion (same pattern ashasUserEventSenderfor models).adk/chatmodel.goNewEventSenderToolHandler()and converts it viahandlersToToolMiddlewares(), then prepends as outermost — no directcompose.ToolMiddlewareconstruction.config.Handlersfor*eventSenderToolWrappervia type assertion.adk/wrappers_test.goWrapInvokableToolCall83%,WrapStreamableToolCall90%,WrapEnhancedInvokableToolCall81%,WrapEnhancedStreamableToolCall88%,handlersToToolMiddlewares81%.Usage