FunctionDeclaration

classFunctionDeclaration


Defines a function that the model can use as a tool.

When generating responses, the model might need external information or require the application to perform an action.FunctionDeclaration provides the necessary information for the model to create aFunctionCallPart, which instructs the client to execute the corresponding function. The client then sends the result back to the model as aFunctionResponsePart.

For example

valgetExchangeRate=FunctionDeclaration(
name="getExchangeRate",
description="Get the exchange rate for currencies between countries.",
parameters=mapOf(
"currencyFrom"toSchema.str("The currency to convert from."),
"currencyTo"toSchema.str("The currency to convert to.")
)
)

See theUse the Gemini API for function calling guide for more information on function calling.

See also
Schema

Summary

Public constructors

FunctionDeclaration(
    name: String,
    description: String,
    parameters: Map<StringSchema>,
    optionalParameters: List<String>
)

Public constructors

FunctionDeclaration

FunctionDeclaration(
    name: String,
    description: String,
    parameters: Map<StringSchema>,
    optionalParameters: List<String> = emptyList()
)
Parameters
name: String

The name of the function.

description: String

The description of what the function does and its output. To improve the effectiveness of the model, the description should be clear and detailed.

parameters: Map<StringSchema>

The map of parameters names to theirSchema the function accepts as arguments.

optionalParameters: List<String> = emptyList()

The list of parameter names that the model can omit when invoking this function.

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-07-21 UTC.