feat: add Enteprise AI chat solution#2620
feat: add Enteprise AI chat solution#2620PierrickVoulet merged 3 commits intogoogleworkspace:mainfrom
Conversation
Summary of ChangesHello @PierrickVoulet, 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 introduces a new Enterprise AI chat solution, providing a robust and secure AI assistant built on Gemini Enterprise. The solution integrates with Vertex AI Search for data querying and Google Chat for direct messaging, featuring dynamic authentication and configuration to ensure seamless operation within an enterprise environment. It aims to enhance user interaction with internal data and communication platforms. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new Enterprise AI agent solution. The implementation is a good start, but there are several critical areas that need improvement for robustness and correctness. Specifically, the agent has non-deterministic behavior when multiple discovery engines or authentication tokens are present. Error handling can be improved by using specific exception types instead of generic Exception. Additionally, there's a typo in the README.md that makes the provided example non-functional. I've added specific comments with suggestions to address these issues.
I am having trouble creating individual review comments. Click here to see my feedback.
solutions/enterprise-ai-agent/enterprise-ai/agent.py (61-63)
This logic is not robust. It will pick the first matching key if multiple exist, which can be non-deterministic. Also, state_dict.get(...) can return None, which violates the function's return type hint str and will cause errors in downstream code. The code should validate that exactly one key is found and that its value is a non-empty string.
if len(matching_keys) == 1:
token = state_dict.get(matching_keys[0])
if isinstance(token, str) and token:
return token
raise ValueError(f"Expected 1 valid bearer token, but found {len(matching_keys)} matching keys.")
solutions/enterprise-ai-agent/README.md (13)
There is a typo in the example authentication token and the regex pattern. enteprise-ai should be enterprise-ai. This will cause the regex to fail matching the token key, as it is defined as enterprise-ai in agent.py, making the example non-functional.
When deployed as a Bring-Your-Own (BYO) model via Gemini Enterprise, the session state dynamically passes an authentication token (e.g., `enterprise-ai_12345`). This agent intercepts the `ToolContext` state and extracts the token at runtime using regex pattern matching (`^enterprise-ai_\d+$`) to securely execute calls using a Bearer token.
solutions/enterprise-ai-agent/enterprise-ai/agent.py (41)
Using the generic Exception is not a good practice as it can catch unexpected errors and makes specific error handling by callers difficult. Please use a more specific exception, like ValueError or RuntimeError.
raise ValueError(f"Failed to resolve GCP Project ID from environment.")
solutions/enterprise-ai-agent/enterprise-ai/agent.py (49-51)
The loop iterates over engines and returns the first one it finds. If there are multiple discovery engines in the project, this will arbitrarily pick one, which could be the wrong one, as the API doesn't guarantee order. This can lead to non-deterministic behavior. The code should deterministically select the correct engine, or raise an error if more than one is found when only one is expected.
engines_list = list(engines)
if len(engines_list) != 1:
raise RuntimeError(f"Expected 1 discovery engine, but found {len(engines_list)}.")
return f"{engines_list[0].name}/servingConfigs/default_serving_config"
solutions/enterprise-ai-agent/enterprise-ai/agent.py (52)
Using the generic Exception is not a good practice as it can catch unexpected errors and makes specific error handling by callers difficult. Please use a more specific exception, like ValueError or RuntimeError.
raise ValueError(f"No Discovery Engines found in project {project_id}")
Add Enteprise AI chat solution