feat: support authorizations field in async_stream_query - #7034
Open
neville-m-exa wants to merge 1 commit into
Open
feat: support authorizations field in async_stream_query#7034neville-m-exa wants to merge 1 commit into
neville-m-exa wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
neville-m-exa
force-pushed
the
feat/async-stream-query-authorizations
branch
from
July 31, 2026 18:06
b171290 to
f1e9d11
Compare
Currently, the `authorizations` field (for forwarding user credentials to agent tools via session state) is only supported by `streaming_agent_run_with_events`. When passed to `async_stream_query`, it flows through **kwargs to `Runner.run_async()` which rejects it: TypeError: Runner.run_async() got an unexpected keyword argument 'authorizations' This change adds explicit `authorizations` handling to `async_stream_query` — matching the behavior of `streaming_agent_run_with_events`: 1. Accept `authorizations` as a named parameter (Dict[str, Any]) 2. Convert each authorization's access_token into a state_delta entry 3. Pass state_delta to Runner.run_async() (which already supports it) This allows standard API callers to forward user credentials without switching to the AgentSpace-oriented method and its different request/response format.
neville-m-exa
force-pushed
the
feat/async-stream-query-authorizations
branch
from
July 31, 2026 18:08
f1e9d11 to
8536acf
Compare
Author
|
@yeesian , @Tongzhou-Jiang can you please review. |
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
Add
authorizationssupport toasync_stream_query, matching the existing behavior instreaming_agent_run_with_events.Problem
When
authorizationsis included in the input payload of anasync_stream_querycall to Agent Engine, it flows through**kwargstoRunner.run_async()which doesn't accept it:The
authorizationsfield currently only works viastreaming_agent_run_with_events(which parses arequest_jsonstring into_StreamRunRequest). However,streaming_agent_run_with_eventsis documented as "primarily meant for invocation from AgentSpace" and has a different input/output contract, making it unsuitable for standard API callers that need to forward user credentials to agent tools.Solution
authorizationsas a named parameter toasync_stream_queryaccess_tokeninto astate_deltaentry (same logic asstreaming_agent_run_with_eventsuses via_StreamRunRequest)state_deltatoRunner.run_async()(which already supports it)This is a minimal, backward-compatible change — callers that don't pass
authorizationssee no difference (state_delta=Noneis a no-op).Use Case
Agents deployed on Agent Engine that need to call authenticated external APIs on behalf of the user. The caller (e.g., a gateway service) extracts the user's JWT and forwards it via
authorizations. The agent reads it fromsession.stateand uses it as a Bearer token.Test Plan
test_async_stream_query_with_authorizations— verifies no error when authorizations is passedtest_async_stream_query_authorizations_passed_as_state_delta— verifies tokens are converted to state_deltatest_async_stream_query_no_authorizations_passes_none_state_delta— verifies no-op when absent🤖 Generated with Claude Code