Tool

public final classTool


Contains a set of tools (like function declarations) that the model has access to. These tools can be used to gather information or complete tasks.

Summary

Nested types

public static classTool.Companion

Public methods

static final @NonNullTool

Creates aTool instance that allows the model to use code execution.

static final @NonNullTool

Creates aTool instance that provides the model with access to thefunctionDeclarations.

static final @NonNullTool

Creates aTool instance that allows the model to use grounding with Google Search.

static final @NonNullTool

Creates aTool instance that allows you to provide additional context to the models in the form of public web URLs.

Public methods

codeExecution

public static final @NonNullTool codeExecution()

Creates aTool instance that allows the model to use code execution.

functionDeclarations

public static final @NonNullTool functionDeclarations(
    @NonNullList<@NonNullFunctionDeclaration> functionDeclarations
)

Creates aTool instance that provides the model with access to thefunctionDeclarations.

Parameters
@NonNullList<@NonNullFunctionDeclaration> functionDeclarations

The list of functions that this tool allows the model access to.

googleSearch

public static final @NonNullTool googleSearch(@NonNullGoogleSearch googleSearch)

Creates aTool instance that allows the model to use grounding with Google Search.

Grounding with Google Search can be used to allow the model to connect to Google Search to access and incorporate up-to-date information from the web into it's responses.

When using this feature, you are required to comply with the "grounding with Google Search" usage requirements for your chosen API provider:Gemini Developer API or Vertex AI Gemini API (seeService Terms section within the Service Specific Terms).

Parameters
@NonNullGoogleSearch googleSearch

An emptyGoogleSearch object. The presence of this object in the list of tools enables the model to use Google Search.

Returns
@NonNullTool

ATool configured for Google Search.

urlContext

public static final @NonNullTool urlContext(@NonNullUrlContext urlContext)

Creates aTool instance that allows you to provide additional context to the models in the form of public web URLs. By including URLs in your request, the Gemini model will access the content from those pages to inform and enhance its response.

Parameters
@NonNullUrlContext urlContext

Specifies the URL context configuration.

Returns
@NonNullTool

ATool configured for URL context.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-06 UTC.