Tool

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

Public companion functions

Tool

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

Tool

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

Tool
googleSearch(googleSearch: GoogleSearch)

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

Tool

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

Public companion functions

codeExecution

fun codeExecution(): Tool

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

functionDeclarations

fun functionDeclarations(functionDeclarations: List<FunctionDeclaration>): Tool

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

Parameters
functionDeclarations: List<FunctionDeclaration>

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

googleSearch

fun googleSearch(googleSearch: GoogleSearch = GoogleSearch()): Tool

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
googleSearch: GoogleSearch = GoogleSearch()

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

Returns
Tool

ATool configured for Google Search.

urlContext

@PublicPreviewAPI
fun urlContext(urlContext: UrlContext = UrlContext()): Tool

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
urlContext: UrlContext = UrlContext()

Specifies the URL context configuration.

Returns
Tool

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 2025-10-09 UTC.