> ## 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.

# Frontend tools

Frontend tools let your AI agent execute actions directly inside your app — initiating a transfer, resetting a password, cancelling an order, etc.

Tools are defined on your AI agent in the Gleap dashboard (**AI agent > Tools > Frontend tool**) — name, description, parameters and execution mode all live there. Your app only registers a handler that executes the tool. Learn how to set up Frontend tools in our [help center article](https://help.gleap.io/en/articles/221-frontend-tools-let-the-ai-run-actions-in-your-app).

## Register a tool handler

Register the handler for a dashboard-defined Frontend tool. Use the tool's runtime name shown in the tool editor.

```swift theme={null}
Gleap.registerAgentTool("send-money") { params, completion in
    let amount = params["amount"]
    let contact = params["contact"]

    // Run your own logic here.

    // Return a string or JSON — the AI waits for this response.
    completion("The transfer was initiated. The user must confirm it in the banking app.")
}
```

**Handler contract**

* The handler is invoked on the main queue with the parameters configured in the dashboard, filled with the values the AI collected.
* Call the completion block exactly once with the result — a string or a JSON object (dictionaries and arrays are stringified). The result is sent back to the AI, which uses it to reply.
* The completion block can be called asynchronously — the AI waits for it.
* Exceptions thrown by the handler are caught and reported to the AI automatically.
* If no handler is registered for a tool, the AI is informed so it can respond accordingly.

## Execution modes

Set per tool in the dashboard:

* `Auto` — the handler runs immediately when the AI calls the tool.
* `Ask before final execution` — the AI adds a confirmation button to its reply; the handler only runs after the user confirms.

## Migrating from `setAiTools`

`Gleap.setAiTools(...)` and the `GleapAiTool` / `GleapAiToolParameter` classes have been removed. Tools defined via `setAiTools` could only return a static response to the AI — Frontend tools execute real code and return live results. Define your tools on the AI agent in the dashboard and register their handlers via `Gleap.registerAgentTool(_:handler:)` instead. The `onToolExecution` delegate method remains available.
