> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gleap.io/llms.txt
> Use this file to discover all available pages before exploring further.

# AI tools

## What are AI tools?

AI tools allow you to create deep integrations between your app / website and Kai (our AI bot). A few use-cases might include:

* A banking app allowing to initiate transactions
* Performing a password reset directly in the messenger
* Canceling orders
* ...

The possibilities are almost endless. The following example shows how to add a new AI tool allowing users to initiate bank transactions directly inside Kai.

<img src="https://mintcdn.com/gleap-1d346ffa/b8_EVsZHbtxdB2pN/images/aitools.png?fit=max&auto=format&n=b8_EVsZHbtxdB2pN&q=85&s=74c2d435323893f41caf38670f204ec6" alt="Ticket custom data" width="2700" height="1680" data-path="images/aitools.png" />

## Specify AI tools

```java theme={null}
// Creating parameters
GleapAiToolParameter amountParameter = new GleapAiToolParameter(
        "amount",
        "The amount of money to send. Must be positive and provided by the user.",
        "string",
        true
);

String[] possibleEnumValues = {"Alice", "Bob"};

GleapAiToolParameter contactParameter = new GleapAiToolParameter(
        "contact",
        "The contact to send money to.",
        "string",
        true,
        possibleEnumValues
);

GleapAiToolParameter[] params = {amountParameter, contactParameter};

// Creating the AI tool with the parameters
GleapAiTool transactionTool = new GleapAiTool(
        "send-money",
        "Send money to a given contact.",
        "The transfer got initiated but not completed yet. The user must confirm the transfer in the banking app.",
        "button",
        params
);

GleapAiTool[] tools = {transactionTool};

// Set the available tools using the static method
Gleap.getInstance().setAiTools(tools);
```

### Execution type

`auto`: The tool will be executed automatically.

`button`: Kai adds a button to it's reply, that allows the user to execute the tool. The tool will not be executed automatically

<img src="https://mintcdn.com/gleap-1d346ffa/b8_EVsZHbtxdB2pN/images/buttontool.png?fit=max&auto=format&n=b8_EVsZHbtxdB2pN&q=85&s=cd4a6a90cf4630b3781348de70705d53" alt="Ticket custom data" width="2542" height="1594" data-path="images/buttontool.png" />

## Perform actions

Implement the `setAiToolExecutedCallback` callback to get notified when a tool should be executed.

```java theme={null}
Gleap.getInstance().setAiToolExecutedCallback(new AiToolExecutedCallback() {
    @Override
    public void aiToolExecuted(JSONObject jsonObject) {
        try {
            String toolName = jsonObject.getString("name");
            JSONObject params = jsonObject.getJSONObject("params");

            System.out.println(jsonObject.toString());
            // {"name":"send-money","params":{"amount":"20","contact":"alice"}}
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }
});
```
