Google Gemini API Tool Calling

Overview

You can use this Snap to provide a conversational interface with the ability to call external tools or services based on your interaction and context. This Snap sends a message that contains the conversation history, a tool definition list, and other query parameters to the Google Gemini API endpoint.


Google Gemini API Tool Calling Overview

Prerequisites

Known issues

None.

Limitations

  • gemini-1.0-pro and gemini-1.5-pro is not supported for the Top K field.

Snap views

View Description Examples of upstream and downstream Snaps
Input This Snap supports exactly one document input view. The input has a message list that contains the conversation history, a tool definition list, and other query parameters to the Google Gemini API.
Output This Snap supports exactly two document output views.
  • The first output displays the full response from the LLM.
  • The second output displays the list of tools called.
Error

Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter when running the pipeline by choosing one of the following options from the When errors occur list under the Views tab. The available options are:

  • Stop Pipeline Execution Stops the current pipeline execution when an error occurs.
  • Discard Error Data and Continue Ignores the error, discards that record, and continues with the remaining records.
  • Route Error Data to Error View Routes the error data to an error view without stopping the Snap execution.

Learn more about Error handling in Pipelines.

Snap settings

Legend:
  • Suggestion icon (): Indicates a list that is dynamically populated based on the configuration.
  • Expression icon (): Indicates whether the value is an expression (if enabled) or a static value (if disabled). Learn more about Using Expressions in SnapLogic.
  • Add icon (Plus Icon): Indicates that you can add fields in the field set.
  • Remove icon (Minus Icon): Indicates that you can remove fields from the field set.
Field / field set Type Description
Label String

Required. Specify a unique name for the Snap. Modify this to be more appropriate, especially if more than one of the same Snaps is in the pipeline.

Default value: Google Gemini API Tool Calling

Example: Weather report
Model name String/Expression

Required. Specify the model name to generate text responses. Learn more about the list of compatible models from Gemini API.

Default value: N/A

Example: models/gemini-1.5-pro
Content payload String/Expression Required. Specify the content payload to send to Google Gemini. The content received from the Google GenAI Prompt Generator Snap is in the correct format.
For example,
[
    {
        "contents": 
            {
                "content": "What day is it today?",
                "sl_role": "USER"
            },
            {
                "content": "Today is Monday.",
                "sl_role": "MODEL"
            },
            {
                "content": "What day is it tomorrow?",
                "sl_role": "USER"
            }
        ]
    }
]

Default value: N/A

Example: $messages
Tool payload String/Expression

Required. Specify the list of tool definitions to send to the model.

Default value: N/A

Example: $tools
Tool configurations

Use this field set to modify the tool calling settings to guide the model responses and optimize the output processing.

Function calling mode Dropdown list/Expression
Required. Choose the preferred tool which the model has to call. Available options include:
  • AUTO - The model decides to predict either a function call or a natural language response.
  • ANY - The model is constrained to always predict a function call. If selected, user could provide a list of allowed_function_names. Otherwise, the model picks from all of the available function declarations.
  • NONE - The model won't predict a function call. In this case, the model behavior is the same as if you don't pass any function declarations.

Default value: AUTO

Example: ANY

Allowed function names String/Expression

Appears when you select the Tool choice as ANY or expression enabled.

Required. Specify the name of the function the model can call.

Default value: N/A

Example: get_weather_info

Model parameters Configure the parameters to tune the model runtime.
Maximum tokens Integer/Expression
Specify the maximum number of tokens to generate in the chat completion. If left blank, the default value of the model is used.
Note: The response may be incomplete if the sum of the prompt tokens and Maximum tokens exceed the allowed token limit for the model.

Minimum value: 1

Maximum value: Unlimited

Default value: N/A

Example: 50

Temperature Decimal/Expression

Specify the sampling temperature to use a decimal value between 0 and 1. If left blank, the default value of the model is used. Learn more about the minimum, maximum, and default values for each model.

Minimum value: 0.0

Maximum value: 2.0

Default value: N/A

Example: 0.2

Top P Decimal/Expression

Specify the nucleus sampling value as a decimal between 0 and 1. This value sets the cumulative probability threshold for selecting tokens, which influences the diversity of the generated content. Lower values may result in more focused and deterministic responses, while higher values can increase content variability. If left blank, the default value of the model is used.

The default values for each model are as follows:
  • gemini-1.5-pro: 0.94
  • gemini-1.0-pro: 1

Minimum value: 0.0

Maximum value: 1.0

Default value: N/A

Example: 0.2

Top K Integer/Expression
Specify a value to limit the number of high-probability tokens considered for each generation step to control the randomness of the output. If left blank, the default value of the model is used.
Note: Models gemini-1.0-pro and gemini-1.5-pro is not supported.

Minimum value: 1

Maximum value: 40

Default value: N/A

Example: 30

Stop sequences String/Expression

Specify a sequence of texts or tokens to stop the model from generating further output. Learn more.

Note:
  • You can configure up to five stop sequences when generating the text. These stop sequences tell the model to halt further text generation if any of the specified sequences are encountered.
  • The returned text does not contain the stop sequence.

Default value: N/A

Example: pay, ["amazing"], ["September", "paycheck"]
Advanced prompt configuration Configure the prompt settings to guide the model responses and optimize output processing.
System Prompt String/Expression

Specify the persona for the model to adopt in the responses. This initial instruction guides the LLM's responses and actions. This prompt prepares for the conversation by defining role, personality, tone, and other relevant details to understand and respond to the user's input.

Note:
  • Supports gemini-1.5-pro and gemini-1.0-pro-002 models too.
  • If you leave this field blank, empty or null, the Snap processes the request without using any system prompt.

Default value: N/A

Example:
  • "You are a helpful assistant."
  • "You are an experienced software developer."
  • "You are a customer service representative for a tech company."
Advanced response configurations Configure the response settings to customize the responses and optimize output processing.
Simplify response Checkbox/Expression Select this checkbox to receive a simplified response format that retains only the most commonly used fields and standardizes the output for compatibility with other models. This option supports only a single choice response. Here's an example of a simplified output format.
{
  "role": <string/null>,
  "content": <string/JSON(for JSON mode)>,
  "tool_calls": <array of tool call information object>, // optional
  "finish_reason": <string>,
  "usage": {
    "prompt_tokens": <integer/null>,
    "output_tokens": <integer/null>,
    "total_tokens": <integer/null>,
  },
  "_sl_responses": <object/array of the raw responses for debug mode> //optional
  "original": {}
}               
Important: This field does not support upstream values.

Default status: Deselected

Snap execution Dropdown list
Select one of the three modes in which the Snap executes. Available options are:
  • Validate & Execute: Performs limited execution of the Snap and generates a data preview during pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during pipeline runtime.
  • Execute only: Performs full execution of the Snap during pipeline execution without generating preview data.
  • Disabled: Disables the Snap and all Snaps that are downstream from it.

Default value: Validate & Execute

Example: Execute only

Additional information

The following table lists the Models and their corresponding minimum, maximum, and default values for the Temperature field:

Model Name Default value Minimum value Maximum value
gemini-1.5-pro 1.0 0.0 2.0
gemini-1.0-pro-002 1.0 0.0 2.0
gemini-1.0-pro-001 0.9 0.0 1.0

Examples