# AgentTool


```
abstract class AgentTool
```

<br />

*** ** * ** ***

Base class for tools that the `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent` can invoke automatically.

All tools used with `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent` must originate from Android AppFunctions (either registered via `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#enableAppFunctions(kotlin.Boolean)` / `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addAppFunctionIds(kotlin.collections.List)` or discovered via `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlinx.coroutines.CoroutineDispatcher)`).

Developers can subclass `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` using `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` `(delegate, ...)` to wrap an existing AppFunction tool (for example, to add human-in-the-loop confirmation before delegating to `delegate.execute(args)`).

## Summary

| ### Public constructors |
|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool#AgentTool(com.google.mlkit.genai.agent.AgentTool,kotlin.String,kotlin.String)(delegate: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool, name: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, description: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Constructs a decorating `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` that wraps an underlying AppFunction tool (for example, to add human-in-the-loop confirmation before calling `delegate.execute(args)`). |

| ### Public functions |
|---|---|
| `abstract suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?>` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool#execute(kotlin.collections.Map)(args: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html>)` Executes the tool logic with the arguments supplied by the model. |

| ### Public properties |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool?` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool#delegate()` The underlying `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` wrapped by this decorator, or `null` if this is a root AppFunction tool. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool#description()` Human-readable summary of what the tool does. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool#name()` The unique identifier of the tool. |

## Public constructors

### AgentTool

```
AgentTool(
    delegate: AgentTool,
    name: String = delegate.name,
    description: String = delegate.description
)
```

Constructs a decorating `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` that wraps an underlying AppFunction tool (for example, to add human-in-the-loop confirmation before calling `delegate.execute(args)`).

| Parameters |
|---|---|
| `delegate: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` | The underlying `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` to wrap. Must be an AppFunction tool discovered via `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlinx.coroutines.CoroutineDispatcher)` (or another decorator wrapping one). |
| `name: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html = delegate.name` | Optional override for the tool's name; defaults to `delegate.name`. |
| `description: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html = delegate.description` | Optional override for the tool's description; defaults to `delegate.description`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool#<init>(com.google.mlkit.genai.agent.AgentTool,kotlin.String,kotlin.String)` does not wrap an AppFunction tool. |

## Public functions

### execute

```
abstract suspend fun execute(args: Map<String, Any>): Map<String, Any?>
```

Executes the tool logic with the arguments supplied by the model.

Optional schema arguments that evaluate to null are omitted from `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool#execute(kotlin.collections.Map)`.

| Parameters |
|---|---|
| `args: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html>` | Map of argument names to non-null argument values. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?>` | Execution results to be returned to the model. |

## Public properties

### delegate

```
val delegate: AgentTool?
```

The underlying `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` wrapped by this decorator, or `null` if this is a root AppFunction tool.

### description

```
val description: String
```

Human-readable summary of what the tool does.

### name

```
val name: String
```

The unique identifier of the tool.