feat: pass A2A request context metadata as invocation state#1854
Merged
mkmeral merged 1 commit intostrands-agents:mainfrom Mar 12, 2026
Merged
feat: pass A2A request context metadata as invocation state#1854mkmeral merged 1 commit intostrands-agents:mainfrom
mkmeral merged 1 commit intostrands-agents:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
mehtarac
approved these changes
Mar 12, 2026
There was a problem hiding this comment.
Assessment: Request Changes
This PR introduces a clean, well-tested feature that leverages the existing invocation_state mechanism to expose A2A request context to tools and hooks. The implementation is minimal and follows established patterns.
Review Summary
- Documentation: The PR description states "Documentation PR: None" without justification. Since this adds a new public API pattern (
a2a_request_contextkey) that tool/hook developers will rely on, please either link to a documentation PR or add a justification explaining why documentation updates are not needed. - Implementation: Clean 4-line change that correctly passes the
RequestContextthrough the existinginvocation_stateparameter. - Testing: Comprehensive test coverage (5 new tests) covering various scenarios including with/without task, A2A compliant streaming mode, and access patterns.
- API Design: Good choice to pass the full
RequestContextobject rather than individual fields, providing forward compatibility as the A2A SDK evolves.
Please update the "Documentation PR" section with either a link to a docs PR or a brief justification for why docs aren't needed.
It is right that we need documentation. But I'm not going to block this PR on it
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.
Description
When the A2A executor handles an incoming request, downstream tools and hooks have no way to access A2A-specific context — metadata the caller attached, the task being processed, the request configuration, or related tasks. This forces tool authors to work around the limitation by tracking state externally or simply going without.
The
stream_asyncmethod already accepts aninvocation_stateparameter that flows through the entire execution pipeline (event loop → hook events →ToolContext.invocation_state), but the A2A executor wasn't using it.This change passes the full
RequestContextobject throughinvocation_stateunder thea2a_request_contextkey, giving tools and hooks access to all A2A request context —metadata,current_task,task_id,context_id,configuration,call_context,related_tasks, andrequested_extensions— without decomposing it into individual fields that would need updating every time the A2A SDK adds a new property.Related Issues
None
Documentation PR
None
Type of Change
New feature
Public API Changes
Tools and hooks receiving requests through the A2A server can now access the full A2A
RequestContextviainvocation_state:Hook providers can access it identically:
The
a2a_request_contextkey is only present when the agent is invoked through the A2A server. Non-A2A invocations are unaffected.Testing
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.