Skip to content

Conversation

@glaforge
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @glaforge, 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 significant enhancement by adding a GoogleMapsTool to the system. This new tool allows Large Language Models, specifically Gemini 2 models, to incorporate real-world geographical data from Google Maps into their response generation process. The primary goal is to provide more accurate and contextually relevant answers by grounding LLM outputs with location-specific information, thereby expanding the capabilities of the LLM agent for location-aware applications.

Highlights

  • New GoogleMapsTool: Introduced a new GoogleMapsTool class designed to integrate Google Maps functionality directly into LLM agents.
  • Location-Based Grounding: This tool enables Gemini 2 models to ground their responses based on location data retrieved from Google Maps, enhancing contextual relevance.
  • Internal Operation: The GoogleMapsTool is a built-in tool that operates internally within the model, requiring no local code execution.
  • Model Compatibility: The tool includes a check to ensure it is only used with Gemini 2 models and explicitly throws an IllegalArgumentException if a gemini-1 model is detected.
  • Configuration: Usage examples demonstrate how to add the tool to an LlmAgent and how to pass specific latitude and longitude coordinates via generateContentConfig.
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 a new GoogleMapsTool. My review focuses on improving the implementation of processLlmRequest for better safety and efficiency by handling an unsafe Optional access and reducing redundant object builds. I've also corrected an inaccurate code example in the Javadoc to ensure it reflects the correct API usage.

Comment on lines 57 to 77

GenerateContentConfig.Builder configBuilder =
llmRequestBuilder
.build()
.config()
.map(GenerateContentConfig::toBuilder)
.orElse(GenerateContentConfig.builder());

List<Tool> existingTools = configBuilder.build().tools().orElse(ImmutableList.of());
ImmutableList.Builder<Tool> updatedToolsBuilder = ImmutableList.builder();
updatedToolsBuilder.addAll(existingTools);

String model = llmRequestBuilder.build().model().get();
if (model != null && !model.startsWith("gemini-1")) {
updatedToolsBuilder.add(Tool.builder().googleMaps(GoogleMaps.builder().build()).build());
configBuilder.tools(updatedToolsBuilder.build());
} else {
return Completable.error(
new IllegalArgumentException("Google Maps tool is not supported for model " + model));
}

llmRequestBuilder.config(configBuilder.build());
return Completable.complete();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The implementation of processLlmRequest can be improved for safety, efficiency, and readability.

  1. Unsafe Optional.get(): On line 69, llmRequestBuilder.build().model().get() is unsafe and will throw a NoSuchElementException if the model is not set in the request. It's better to use orElse(null) and handle the null case.
  2. Inefficient build() calls: llmRequestBuilder.build() is called multiple times (lines 60, 69). This is inefficient. The request should be built once and stored in a local variable.
  3. Verbose logic: The logic for updating the tools list can be simplified to be more concise and readable.

Here is a suggested refactoring that addresses these points by replacing the method body:

    LlmRequest llmRequest = llmRequestBuilder.build();
    String model = llmRequest.model().orElse(null);

    if (model == null || model.startsWith("gemini-1")) {
      return Completable.error(
          new IllegalArgumentException("Google Maps tool is not supported for model " + model));
    }

    GenerateContentConfig originalConfig =
        llmRequest.config().orElseGet(() -> GenerateContentConfig.builder().build());

    ImmutableList<Tool> updatedTools =
        ImmutableList.<Tool>builder()
            .addAll(originalConfig.tools().orElse(ImmutableList.of()))
            .add(Tool.builder().googleMaps(GoogleMaps.builder().build()).build())
            .build();

    llmRequestBuilder.config(originalConfig.toBuilder().tools(updatedTools).build());
    return Completable.complete();

ImmutableList.Builder<Tool> updatedToolsBuilder = ImmutableList.builder();
updatedToolsBuilder.addAll(existingTools);

String model = llmRequestBuilder.build().model().get();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say have the model().orElse(null) here if you're going to null check in the conditional anyways

@glaforge glaforge force-pushed the main branch 2 times, most recently from 8963038 to b18e19f Compare October 21, 2025 20:38
@copybara-service copybara-service bot merged commit 9c1ef4f into google:main Oct 21, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants