Gemini Function Calling

Enable Gemini models to interact with external tools and APIs by defining custom functions the model can call, allowing it to retrieve real-time information or perform actions.

When to use

When your application needs to perform actions outside the LLM's knowledge base or access up-to-date information from external systems.

How to apply

  1. Define the schema of your functions using a tools parameter in your API request, including the function name, a description, and parameters.

  2. In your prompt, instruct the model to use these functions to achieve a goal.

  3. When the model suggests a function call, execute the function in your application.

  4. Pass the function's output back to the model to continue the conversation or generate a final response.

Glossary

Function Calling
A capability of large language models to identify when an external tool or API should be used to fulfill a user's request, and to output a structured call to that tool.
Schema
A formal description of the structure of data, in this case, defining the name, description, and parameters of a function.
Tools Parameter
An argument in the API request where you provide the definitions of the functions the model can call.