# AgentTool

# AgentTool


```
public abstract class AgentTool
```

<br />

*** ** * ** ***

Base class for tools that the `Agent` can invoke automatically.

All tools used with `Agent` must originate from Android AppFunctions (either registered via `Agent.Builder.enableAppFunctions` / `Agent.Builder.addAppFunctionIds` or discovered via `AppFunctionAgentTools.discover`).

Developers can subclass `AgentTool` using `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 |
|---|
| `AgentTool( @NonNull AgentTool delegate, @NonNull String name, @NonNull String description )` Constructs a decorating `AgentTool` that wraps an underlying AppFunction tool (for example, to add human-in-the-loop confirmation before calling `delegate.execute(args)`). |

| ### Public methods |
|---|---|
| `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. |
| `final AgentTool` | `getDelegate()` The underlying `AgentTool` wrapped by this decorator, or `null` if this is a root AppFunction tool. |
| `final @NonNull String` | `getDescription()` Human-readable summary of what the tool does. |
| `final @NonNull String` | `getName()` The unique identifier of the tool. |

## Public constructors

### AgentTool

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

Constructs a decorating `AgentTool` that wraps an underlying AppFunction tool (for example, to add human-in-the-loop confirmation before calling `delegate.execute(args)`).

| Parameters |
|---|---|
| `@NonNull AgentTool delegate` | The underlying `AgentTool` to wrap. Must be an AppFunction tool discovered via `AppFunctionAgentTools.discover` (or another decorator wrapping one). |
| `@NonNull String name` | Optional override for the tool's name; defaults to `delegate.name`. |
| `@NonNull String description` | Optional override for the tool's description; defaults to `delegate.description`. |

| Throws |
|---|---|
| `IllegalArgumentException` | if `delegate` 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 `args`.

| Parameters |
|---|---|
| `@NonNull Map<@NonNull String, @NonNull Object> args` | Map of argument names to non-null argument values. |

| Returns |
|---|---|
| `@NonNull Map<@NonNull String, Object>` | Execution results to be returned to the model. |

### getDelegate

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

The underlying `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.