Skip to content

feat: support authorizations field in async_stream_query - #7034

Open
neville-m-exa wants to merge 1 commit into
googleapis:mainfrom
neville-m-exa:feat/async-stream-query-authorizations
Open

feat: support authorizations field in async_stream_query#7034
neville-m-exa wants to merge 1 commit into
googleapis:mainfrom
neville-m-exa:feat/async-stream-query-authorizations

Conversation

@neville-m-exa

Copy link
Copy Markdown

Summary

Add authorizations support to async_stream_query, matching the existing behavior in streaming_agent_run_with_events.

Problem

When authorizations is included in the input payload of an async_stream_query call to Agent Engine, it flows through **kwargs to Runner.run_async() which doesn't accept it:

TypeError: Runner.run_async() got an unexpected keyword argument 'authorizations'

The authorizations field currently only works via streaming_agent_run_with_events (which parses a request_json string into _StreamRunRequest). However, streaming_agent_run_with_events is 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

  • Add authorizations as a named parameter to async_stream_query
  • Convert each authorization's access_token into a state_delta entry (same logic as streaming_agent_run_with_events uses via _StreamRunRequest)
  • Pass state_delta to Runner.run_async() (which already supports it)

This is a minimal, backward-compatible change — callers that don't pass authorizations see no difference (state_delta=None is 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 from session.state and uses it as a Bearer token.

Test Plan

  • Added test_async_stream_query_with_authorizations — verifies no error when authorizations is passed
  • Added test_async_stream_query_authorizations_passed_as_state_delta — verifies tokens are converted to state_delta
  • Added test_async_stream_query_no_authorizations_passes_none_state_delta — verifies no-op when absent

🤖 Generated with Claude Code

@neville-m-exa
neville-m-exa requested a review from a team as a code owner July 29, 2026 18:20
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. api: vertex-ai Issues related to the googleapis/python-aiplatform API. labels Jul 29, 2026
@google-cla

google-cla Bot commented Jul 29, 2026

Copy link
Copy Markdown

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
neville-m-exa force-pushed the feat/async-stream-query-authorizations branch from b171290 to f1e9d11 Compare July 31, 2026 18:06
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
neville-m-exa force-pushed the feat/async-stream-query-authorizations branch from f1e9d11 to 8536acf Compare July 31, 2026 18:08
@neville-m-exa

Copy link
Copy Markdown
Author

@yeesian , @Tongzhou-Jiang can you please review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: vertex-ai Issues related to the googleapis/python-aiplatform API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant