feat(adk): Add SendEvent API for emitting custom events from middleware#791
Merged
feat(adk): Add SendEvent API for emitting custom events from middleware#791
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #791 +/- ##
==========================================
+ Coverage 80.40% 80.41% +0.01%
==========================================
Files 129 129
Lines 13026 13047 +21
==========================================
+ Hits 10473 10492 +19
+ Misses 1753 1752 -1
- Partials 800 803 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
This PR introduces the
SendEventAPI that enablesChatModelAgentMiddlewareimplementations to emit customAgentEvents to the event stream during agent execution.Motivation
When implementing custom middleware for
ChatModelAgent, there was previously no way to inject custom events into the agent's event stream. This limitation prevented middleware from communicating progress, status updates, or custom payloads to the caller iterating over the event stream.Changes
Core Implementation
SendEvent(ctx context.Context, event *AgentEvent) error: A new public API that sends a custom event to the agent's event stream. Returns an error if called outside of an agent execution context.chatModelAgentExecCtx: An internal execution context struct that carries the async generator reference, enabling event emission from anywhere within the middleware chain.Context injection: The execution context is now properly injected in both:
Test Coverage
Added comprehensive test cases covering:
BeforeChatModelmiddleware)withChatModelAgentExecCtx/getChatModelAgentExecCtx)sendmethodUsage Example
Testing
adkpackage passgolangci-lintreports no issues