-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Add code snippets for Agent Engine #13735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Here is the summary of possible violations 😱 DetailsThere are 5 possible violations for not having product prefix.
The end of the violation section. All the stuff below is FYI purposes only. Here is the summary of changes. You are about to add 5 region tags.
This comment is generated by snippet-bot.
|
Summary of ChangesHello @yeesian, 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 comprehensive new Python code sample designed to guide users through the process of building and deploying agents using the Vertex AI Agent Engine and Agent Development Kit (ADK). The sample provides an end-to-end demonstration, covering the definition of a custom tool for an agent, agent initialization, local and remote testing, and deployment to Vertex AI, ultimately addressing issue #13734. It aims to simplify the understanding and implementation of custom agent functionalities within the Google Cloud ecosystem. Highlights
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.
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 adds a new quickstart example for the Agent Engine using the ADK. The new code contains several critical issues that will prevent it from running, including a SyntaxError due to using async for in a synchronous function, an IndentationError, and a NameError from an incorrect type hint. I've also pointed out some areas for improvement regarding error handling, type hints, and code style consistency. Addressing these issues will make the sample code correct and robust.
| return response.json() | ||
| # [END agentengine_quickstart_adk_tool] | ||
|
|
||
| def quickstart_adk_example(staging_bucket: str) -> reasoning_engines.ReasoningEngine: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function signature has two critical issues that will prevent the code from running:
- It uses
async forloops (on lines 41 and 60), which is only valid inside anasyncfunction. The function must be defined withasync def. - The return type hint
-> reasoning_engines.ReasoningEngineis incorrect. The namereasoning_enginesis not defined, and the function actually returnsevents, which is alist. This will cause aNameError.
| def quickstart_adk_example(staging_bucket: str) -> reasoning_engines.ReasoningEngine: | |
| async def quickstart_adk_example(staging_bucket: str) -> list: |
| # [END agentengine_quickstart_adk_testremotely] | ||
| events.append(event) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of code contains an IndentationError on line 66 due to an unexpected indent. It appears the intention is to append each event to the events list within the loop. To fix this, events.append(event) should be inside the loop, and the [END ...] region tag should be placed after it.
| # [END agentengine_quickstart_adk_testremotely] | |
| events.append(event) | |
| events.append(event) | |
| # [END agentengine_quickstart_adk_testremotely] |
| def get_exchange_rate( | ||
| currency_from: str = "USD", | ||
| currency_to: str = "EUR", | ||
| currency_date: str = "latest", | ||
| ): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is missing a return type hint. Based on the response.json() call, it should return a dict. Adding type hints improves code clarity and allows static analysis tools to catch potential bugs. The project configuration (noxfile_config.py) also specifies enforce_type_hints: True.
| def get_exchange_rate( | |
| currency_from: str = "USD", | |
| currency_to: str = "EUR", | |
| currency_date: str = "latest", | |
| ): | |
| def get_exchange_rate( | |
| currency_from: str = "USD", | |
| currency_to: str = "EUR", | |
| currency_date: str = "latest", | |
| ) -> dict: |
| f"https://api.frankfurter.app/{currency_date}", | ||
| params={"from": currency_from, "to": currency_to}, | ||
| ) | ||
| return response.json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HTTP request to the Frankfurter API does not handle potential errors, such as network issues or non-200 status codes. This could lead to unexpected behavior or crashes if the API is unavailable or returns an error. It's good practice to check for a successful response by adding response.raise_for_status() before this line.
|
|
||
| agent = Agent( | ||
| model="gemini-2.0-flash", | ||
| name='currency_exchange_agent', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string literal for the agent name uses single quotes, while other strings in this file (e.g., for the model name) use double quotes. To maintain a consistent coding style, it's recommended to use double quotes for all strings, following PEP 8 recommendations for consistency.
| name='currency_exchange_agent', | |
| name="currency_exchange_agent", |
Description
Fixes #13734
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
nox -s py-3.9(see Test Environment Setup)nox -s lint(see Test Environment Setup)