Skip to content

Conversation

@rickj1ang
Copy link
Contributor

@rickj1ang rickj1ang commented Sep 18, 2025

  • Add optional Vertex AI authentication via GOOGLE_GENAI_USE_VERTEXAI environment variable
  • Update run.sh to check for either GOOGLE_API_KEY or GOOGLE_GENAI_USE_VERTEXAI=true
  • Fix PaymentDetailsModifier schema type from Optional[Any] to Optional[dict[str, Any]] for Vertex AI compatibility
  • Update README.md

This enables users to authenticate using either:

  1. GOOGLE_API_KEY (existing method)
  2. GOOGLE_GENAI_USE_VERTEXAI=true with GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION (new Vertex AI method)

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

Fixes #47 🦕

- Add optional Vertex AI authentication via GOOGLE_GENAI_USE_VERTEXAI environment variable
- Update BaseServerExecutor to support both Google API key and Vertex AI ADC authentication
- Add system_utils functions for Vertex AI environment validation
- Update run.sh to check for either GOOGLE_API_KEY or GOOGLE_GENAI_USE_VERTEXAI=true
- Fix catalog_agent to use same authentication logic as BaseServerExecutor
- Fix PaymentDetailsModifier schema type from Optional[Any] to Optional[dict[str, Any]] for Vertex AI compatibility

This enables users to authenticate using either:
1. GOOGLE_API_KEY (existing method)
2. GOOGLE_GENAI_USE_VERTEXAI=true with GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION (new Vertex AI method)

Closes google-agentic-commerce#47
@rickj1ang rickj1ang requested a review from a team as a code owner September 18, 2025 12:17
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @rickj1ang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the application's authentication flexibility by integrating support for Vertex AI's Application Default Credentials (ADC) alongside the existing Google API key method. This allows users to choose their preferred authentication mechanism, streamlining deployment in various Google Cloud environments. The changes involve updating core server execution logic, adding environment validation utilities, and adjusting the startup script to accommodate both authentication flows, ensuring robust and adaptable access to Google's generative AI services.

Highlights

  • Vertex AI Authentication: Introduced optional Vertex AI authentication using GOOGLE_GENAI_USE_VERTEXAI=true along with GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION environment variables, providing an alternative to the existing GOOGLE_API_KEY method.
  • Flexible Authentication Logic: Updated BaseServerExecutor and catalog_agent to dynamically select between Google API key and Vertex AI ADC authentication based on environment variable availability.
  • Environment Validation Utilities: Added new utility functions in system_utils.py to validate the presence and values of Vertex AI-related environment variables.
  • run.sh Script Update: Modified the run.sh script to check for either GOOGLE_API_KEY or the new Vertex AI environment variable, ensuring the application can start with either authentication method.
  • Schema Type Correction: Corrected the PaymentDetailsModifier schema in payment_request.py by changing the data field type from Optional[Any] to Optional[dict[str, Any]] for improved Vertex AI compatibility.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Vertex AI authentication as an alternative to Google API keys, which is a great feature. The changes span shell scripts, Python utility functions, and agent implementations to accommodate this new authentication method. While the intent is clear and the changes are in the right direction, I've identified some critical issues in the authentication logic that could lead to application crashes or undefined behavior. Specifically, the fallback mechanism from API key to Vertex AI doesn't correctly handle all failure scenarios. I've provided detailed comments and code suggestions to fix these bugs and improve the robustness of the implementation. I've also suggested some improvements to the new utility functions for better validation and consistency. Addressing these points will make the new authentication feature much more reliable.

- Create create_genai_client() factory function to centralize authentication logic
- Fix critical authentication flaws that could cause UnboundLocalError or unhandled exceptions
- Remove code duplication between BaseServerExecutor and catalog_agent
- Ensure proper error handling for all authentication scenarios
- Fix shell script formatting and indentation issues
- Remove unused imports (pathlib.Path, os in catalog_agent)
- Fix shell syntax warning about A && B || C pattern

The authentication factory function now properly handles:
1. Google API key authentication (primary)
2. Vertex AI ADC authentication (fallback)
3. Clear error messages when no valid authentication is found
4. Proper exception chaining for debugging

This resolves the linting issues and makes the authentication more robust.
- Document both Google API Key and Vertex AI authentication options
- Provide clear setup instructions for both methods
- Explain when to use each authentication method (dev vs production)
- Include examples for environment variables and .env file setup
- Add guidance for ADC configuration with gcloud CLI and service accounts

This completes the Vertex AI authentication feature by providing
comprehensive documentation for users.
…cutor and catalog_agent

- Remove unused 'os' import from base_server_executor.py
- Remove unused 'google.genai' imports from both files
- These imports are no longer needed since we use system_utils.create_genai_client()
- Remove redundant environment variable checks since genai SDK handles validation automatically
- Simplify create_genai_client() to just check for GOOGLE_API_KEY and fallback to Vertex AI
- Remove check_vertex_ai_enabled() and check_vertex_ai_env() functions
- Simplify run.sh script to remove complex case conversion logic
- Let the genai SDK handle all authentication validation and error messages
The vertexai=True parameter was accidentally removed, breaking Vertex AI authentication.
This restores the correct fallback behavior.
…t/add-vertext-ai-auth

Resolved conflicts in:
- samples/python/scenarios/a2a/human-present/cards/run.sh
- samples/python/src/common/system_utils.py

Changes include:
- Added Vertex AI authentication support
- Updated terminology from VC to VDC (Verifiable Digital Credentials)
- Improved error handling and logging in run scripts
- Removed deprecated check_google_api_key function
@rickj1ang
Copy link
Contributor Author

I simplified some helper functions in system_utils.py since we now use self._client = genai.Client() for auto-initialization. This is my first time contributing to an open-source repo, so please forgive me if I’ve missed anything in the PR process. Thanks for your patience!

@holtskinner holtskinner merged commit f3b4ab9 into google-agentic-commerce:main Sep 19, 2025
4 checks passed
@rickj1ang rickj1ang deleted the feat/add-vertext-ai-auth branch September 22, 2025 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat]: Add Vertex AI auth in the sample

4 participants