# AgentTool


```
public abstract class AgentTool
```

<br />

*** ** * ** ***

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

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

Developers can subclass `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentTool` using `https://developers.google.com/android/reference/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/com/google/mlkit/genai/agent/AgentTool#AgentTool(com.google.mlkit.genai.agent.AgentTool,kotlin.String,kotlin.String)( @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentTool delegate, @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html name, @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html description )` Constructs a decorating `https://developers.google.com/android/reference/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 methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/Object.html>` | `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentTool#execute(kotlin.collections.Map)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html, @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/Object.html> args)` Executes the tool logic with the arguments supplied by the model. |
| `final https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentTool` | `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentTool#getDelegate()()` The underlying `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentTool` wrapped by this decorator, or `null` if this is a root AppFunction tool. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentTool#getDescription()()` Human-readable summary of what the tool does. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentTool#getName()()` The unique identifier of the tool. |

## Public constructors

### AgentTool

```
public AgentTool(
    @NonNull AgentTool delegate,
    @NonNull String name,
    @NonNull String description
)
```

Constructs a decorating `https://developers.google.com/android/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentTool delegate` | The underlying `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentTool` to wrap. Must be an AppFunction tool discovered via `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlinx.coroutines.CoroutineDispatcher)` (or another decorator wrapping one). |
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html name` | Optional override for the tool's name; defaults to `delegate.name`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html 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/com/google/mlkit/genai/agent/AgentTool#<init>(com.google.mlkit.genai.agent.AgentTool,kotlin.String,kotlin.String)` does not wrap an AppFunction tool. |

## Public methods

### execute

```
public abstract @NonNull Map<@NonNull String, Object> execute(@NonNull Map<@NonNull String, @NonNull Object> args)
```

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/com/google/mlkit/genai/agent/AgentTool#execute(kotlin.collections.Map)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html, @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/Object.html> args` | Map of argument names to non-null argument values. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/Object.html>` | Execution results to be returned to the model. |

### getDelegate

```
public final AgentTool getDelegate()
```

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

### getDescription

```
public final @NonNull String getDescription()
```

Human-readable summary of what the tool does.

### getName

```
public final @NonNull String getName()
```

The unique identifier of the tool.