Skip to content

feat(utils): default Vertex project and location from GCP metadata - #6703

Open
a2105z wants to merge 1 commit into
google:mainfrom
a2105z:feat/gcp-metadata-defaults
Open

feat(utils): default Vertex project and location from GCP metadata#6703
a2105z wants to merge 1 commit into
google:mainfrom
a2105z:feat/gcp-metadata-defaults

Conversation

@a2105z

@a2105z a2105z commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Summary

When ADK runs on Google Cloud (Agent Engine / Cloud Run / GCE) without an explicit .env, fill unset:

  • GOOGLE_CLOUD_PROJECT
  • GOOGLE_CLOUD_LOCATION
  • GOOGLE_GENAI_USE_ENTERPRISE (enterprise/Vertex mode)

from the instance metadata server.

Behavior:

  • Explicit shell / .env values always win
  • Does not force enterprise mode when an API key is present
  • Off-GCP / local runs are unchanged (soft-fail metadata probe, cached)
  • Applied after dotenv load, before GenAI client construction, and when checking enterprise mode

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.
uv run pytest tests/unittests/utils/test_gcp_metadata.py tests/unittests/utils/test_env_utils.py -q
.......................                                                  [100%]
23 passed

Manual End-to-End (E2E) Tests:

  • Local: leave project/location unset → no metadata defaults applied
  • On GCP: omit .env Vertex identity vars → ADK picks project/region and enables enterprise mode

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Additional context

cc @xuanyang15 @steren @klateefa @yeesian @wuliang229 @llalitkumarrr @GWeale — ready for review when you have a chance.

When ADK runs on Google Cloud without an explicit .env, fill unset
GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION, and enterprise/Vertex mode
from the instance metadata server so Agent Engine deploys do not need
those values baked in. Explicit shell and .env values still win, and
API-key auth is left alone.

Fixes google#2685
@a2105z

a2105z commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

@xuanyang15 @steren @klateefa @yeesian @wuliang229 @llalitkumarrr @GWeale — this implements #2685 (GCP metadata defaults for project/location/enterprise). Happy to iterate on review feedback.

@a2105z

a2105z commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

@xuanyang15 — this PR is ready for your review whenever you have a chance. Thanks!

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

Labels

auth [Component] This issue is related to authorization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drop the .env, it's cleaner (ADK should pick up project and location from GCP metadata server)

3 participants