Skip to content

Conversation

@johnnyjclin
Copy link

  • lack of params for ChatVertexAI
  • task id error in send_message function

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 #304 🦕

- lack of params for ChatVertexAI
- task id error in send_message function(referred to a2aproject#304)
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @johnnylin9708, 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 addresses critical issues within the airbnb_planner_multiagent sample, specifically focusing on the correct initialization of the ChatVertexAI model with necessary parameters and refining the logic for handling task_id within the send_message function. These changes ensure the sample operates as intended, improving its robustness and functionality.

Highlights

  • ChatVertexAI Initialization: The ChatVertexAI model in airbnb_agent.py now correctly initializes with project and location parameters, retrieved from environment variables, addressing a previous lack of these parameters.
  • Task ID Handling Refinement: The send_message function in routing_agent.py has been updated to properly handle the task_id. It now explicitly checks if task_id exists in the state and is not None, otherwise, it sets task_id to None instead of generating a new UUID, fixing a task ID error.
  • Code Readability Improvements: Minor refactoring of import statements in both modified files has been performed to improve code readability and conciseness.
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 fixes for initializing ChatVertexAI and handling task_id in send_message. The changes are correct and address the described issues. I've included a couple of suggestions to enhance robustness by adding environment variable validation and to improve code conciseness by simplifying dictionary access.

Comment on lines 63 to +65
if os.getenv('GOOGLE_GENAI_USE_VERTEXAI') == 'TRUE':
# If not using Vertex AI, initialize with Google Generative AI
logger.info('ChatVertexAI model initialized successfully.')
self.model = ChatVertexAI(model=model)
self.model = ChatVertexAI(
model=model,
project=os.getenv('GOOGLE_CLOUD_PROJECT'),
location=os.getenv('GOOGLE_CLOUD_LOCATION'),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For improved robustness, it's a good practice to explicitly check for the existence of GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION environment variables when GOOGLE_GENAI_USE_VERTEXAI is enabled. This ensures the application fails fast with a clear error message if the required configuration is missing, similar to the existing check for GOOGLE_GENAI_MODEL.

            if os.getenv('GOOGLE_GENAI_USE_VERTEXAI') == 'TRUE':
                # If not using Vertex AI, initialize with Google Generative AI
                logger.info('ChatVertexAI model initialized successfully.')
                project = os.getenv('GOOGLE_CLOUD_PROJECT')
                if not project:
                    raise ValueError(
                        'GOOGLE_CLOUD_PROJECT environment variable must be set when using Vertex AI'
                    )
                location = os.getenv('GOOGLE_CLOUD_LOCATION')
                if not location:
                    raise ValueError(
                        'GOOGLE_CLOUD_LOCATION environment variable must be set when using Vertex AI'
                    )
                self.model = ChatVertexAI(
                    model=model,
                    project=project,
                    location=location,
                )

Comment on lines +218 to +222
# task_id = state['task_id'] if 'task_id' in state else str(uuid.uuid4())
if 'task_id' in state and state['task_id'] is not None:
task_id = state['task_id']
else:
task_id = None
Copy link
Contributor

Choose a reason for hiding this comment

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

low

The logic for retrieving task_id can be simplified. Using the .get() dictionary method is a more concise and Pythonic way to fetch the value, as it returns None by default if the key is not found. This single line can replace the if/else block and the commented-out code.

Suggested change
# task_id = state['task_id'] if 'task_id' in state else str(uuid.uuid4())
if 'task_id' in state and state['task_id'] is not None:
task_id = state['task_id']
else:
task_id = None
task_id = state.get('task_id')

…sues

- Initialize `ChatVertexAI` with explicit `project` and `location` parameters to ensure correct GCP context.
- Update `routing_agent.py` to omit `taskId` on initial requests, allowing sub-agents to generate it. This resolves the "Task does not exist" error (Issue a2aproject#304).
- Format code with Ruff and sort imports to comply with linting standards.
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.

Remote Agent Task Error: "Task was specified but does not exist"

1 participant