Tool

public final class Tool


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 class Tool.Companion

Public methods

static final @NonNull Tool

Creates a Tool instance that allows the model to use code execution.

static final @NonNull Tool
functionDeclarations(
    @NonNull List<@NonNull FunctionDeclaration> functionDeclarations
)

Creates a Tool instance that provides the model with access to the functionDeclarations.

static final @NonNull Tool
functionDeclarations(
    List<@NonNull FunctionDeclaration> functionDeclarations,
    List<@NonNull AutoFunctionDeclaration<@NonNull ?, @NonNull ?>> autoFunctionDeclarations
)

Creates a Tool instance that provides the model with access to the functionDeclarations.

static final @NonNull Tool

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

static final @NonNull Tool

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

Public methods

codeExecution

public static final @NonNull Tool codeExecution()

Creates a Tool instance that allows the model to use code execution.

functionDeclarations

public static final @NonNull Tool functionDeclarations(
    @NonNull List<@NonNull FunctionDeclaration> functionDeclarations
)

Creates a Tool instance that provides the model with access to the functionDeclarations.

Parameters
@NonNull List<@NonNull FunctionDeclaration> functionDeclarations

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

functionDeclarations

public static final @NonNull Tool functionDeclarations(
    List<@NonNull FunctionDeclaration> functionDeclarations,
    List<@NonNull AutoFunctionDeclaration<@NonNull ?, @NonNull ?>> autoFunctionDeclarations
)

Creates a Tool instance that provides the model with access to the functionDeclarations.

Parameters
List<@NonNull FunctionDeclaration> functionDeclarations

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

List<@NonNull AutoFunctionDeclaration<@NonNull ?, @NonNull ?>> autoFunctionDeclarations

The list of functions that this tool has access to which should be executed automatically

googleSearch

public static final @NonNull Tool googleSearch(@NonNull GoogleSearch googleSearch)

Creates a Tool 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 (see Service Terms section within the Service Specific Terms).

Parameters
@NonNull GoogleSearch googleSearch

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

Returns
@NonNull Tool

A Tool configured for Google Search.

urlContext

public static final @NonNull Tool urlContext(@NonNull UrlContext urlContext)

Creates a Tool 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
@NonNull UrlContext urlContext

Specifies the URL context configuration.

Returns
@NonNull Tool

A Tool configured for URL context.