fix(adk): return modified message from AfterChatModel #717#792
Merged
fix(adk): return modified message from AfterChatModel #717#792
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #792 +/- ##
==========================================
- Coverage 80.47% 80.44% -0.04%
==========================================
Files 129 129
Lines 13047 13047
==========================================
- Hits 10500 10496 -4
- Misses 1745 1748 +3
- Partials 802 803 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
22dd885 to
293d9fd
Compare
293d9fd to
88cf943
Compare
meguminnnnnnnnn
approved these changes
Feb 14, 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
Enable
AfterChatModelmiddleware modifications to affect the ReAct Agent processing flow, while keeping AgentEvent consistent with ChatModel's original output.Problem
In ReAct Agent scenario, when
AfterChatModelcallback modifiesstate.Messages(e.g., adding/removing ToolCalls), it should affect the subsequent processing flow (like whether to call tools), but the AgentEvent should still reflect the original ChatModel output.Solution
NoTools Scenario (chatmodel.go)
StatePostHandlerreturnsst.Messages[len(st.Messages)-1](the potentially modified message)ReAct Scenario (react.go)
StatePostHandlerreturnsst.Messages[len(st.Messages)-1](the potentially modified message)SendEventmethodChanges
react.go
modelPostHandlereturn value frominputtost.Messages[len(st.Messages)-1]chatmodel.go
StatePostHandlerreturns originalin(no change to output)chatmodel_test.go
Added test cases:
AfterChatModel_NoTools_ModifyDoesNotAffectEvent: Verifies NoTools scenario returns original ChatModel outputAfterChatModel_ReAct_ModifyAffectsFlow: Verifies removing ToolCalls in AfterChatModel stops tool executionAfterChatModel_ReAct_AppendToolCall_AffectsFlow: Verifies adding ToolCalls in AfterChatModel triggers tool executionTesting
All tests pass: