# AppFunctionAgentTools

# AppFunctionAgentTools


```
@OptIn(markerClass = [ExperimentalAppFunctionsFeature])
object AppFunctionAgentTools
```

<br />

*** ** * ** ***

Utility for discovering in-app Android AppFunctions and exposing them as `AgentTool`s.

This enables advanced use cases such as inspecting available functions, filtering them, or decorating them with confirmation / Human-in-the-Loop (HITL) callbacks before registering them with an `Agent`.

Example:

```kotlin
val tools = AppFunctionAgentTools.discover()
val agent = Agent.builder()
    .addTools(tools)
    .build()
```

## Summary

| ### Public functions |
|---|---|
| `suspend List<AgentTool>` | `discover(coroutineDispatcher: CoroutineDispatcher)` Discovers all in-app functions declared with `@androidx.appfunctions.AppFunction` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `AgentTool`s. |
| `suspend List<AgentTool>` | `discover(context: Context, coroutineDispatcher: CoroutineDispatcher)` Discovers all in-app functions declared with `@androidx.appfunctions.AppFunction` for the given `context` and converts them into a list of `AgentTool`s. |
| `suspend List<AgentTool>` | `discover( enabledAppFunctionIds: List<String>, coroutineDispatcher: CoroutineDispatcher )` Discovers in-app functions declared with `@androidx.appfunctions.AppFunction` matching `enabledAppFunctionIds` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `AgentTool`s. |
| `suspend List<AgentTool>` | `discover(functionId: String, coroutineDispatcher: CoroutineDispatcher)` Discovers in-app functions declared with `@androidx.appfunctions.AppFunction` matching `functionId` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `AgentTool`s. |
| `suspend List<AgentTool>` | `discover( context: Context, enabledAppFunctionIds: List<String>, coroutineDispatcher: CoroutineDispatcher )` Discovers functions declared with `@androidx.appfunctions.AppFunction` matching `enabledAppFunctionIds` for the given `context` and converts them into a list of `AgentTool`s. |
| `suspend List<AgentTool>` | `discover( context: Context, functionId: String, coroutineDispatcher: CoroutineDispatcher )` Discovers functions declared with `@androidx.appfunctions.AppFunction` matching `functionId` for the given `context` and converts them into a list of `AgentTool`s. |

## Public functions

### discover

```
suspend fun discover(coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO): List<AgentTool>
```

Discovers all in-app functions declared with `@androidx.appfunctions.AppFunction` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `AgentTool`s.

| Parameters |
|---|---|
| `coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `Dispatchers.IO`. |

| Returns |
|---|---|
| `List<AgentTool>` | List of discovered `AgentTool` instances scoped to the calling application's package. |

### discover

```
suspend fun discover(
    context: Context,
    coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO
): List<AgentTool>
```

Discovers all in-app functions declared with `@androidx.appfunctions.AppFunction` for the given `context` and converts them into a list of `AgentTool`s.

| Parameters |
|---|---|
| `context: Context` | The Android context. |
| `coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `Dispatchers.IO`. |

| Returns |
|---|---|
| `List<AgentTool>` | List of discovered `AgentTool` instances scoped to the calling application's package. |

### discover

```
suspend fun discover(
    enabledAppFunctionIds: List<String>,
    coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO
): List<AgentTool>
```

Discovers in-app functions declared with `@androidx.appfunctions.AppFunction` matching `enabledAppFunctionIds` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `AgentTool`s.

| Parameters |
|---|---|
| `enabledAppFunctionIds: List<String>` | The AppFunction identifiers or method names to discover. |
| `coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `Dispatchers.IO`. |

| Returns |
|---|---|
| `List<AgentTool>` | List of discovered `AgentTool` instances. |

### discover

```
suspend fun discover(
    functionId: String,
    coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO
): List<AgentTool>
```

Discovers in-app functions declared with `@androidx.appfunctions.AppFunction` matching `functionId` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `AgentTool`s.

| Parameters |
|---|---|
| `functionId: String` | The AppFunction identifier (e.g., `"com.example.MyService#createNote"`) or method name (e.g., `"createNote"`). |
| `coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `Dispatchers.IO`. |

| Returns |
|---|---|
| `List<AgentTool>` | List of discovered `AgentTool` instances. |

### discover

```
suspend fun discover(
    context: Context,
    enabledAppFunctionIds: List<String>,
    coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO
): List<AgentTool>
```

Discovers functions declared with `@androidx.appfunctions.AppFunction` matching `enabledAppFunctionIds` for the given `context` and converts them into a list of `AgentTool`s.

| Parameters |
|---|---|
| `context: Context` | The Android context. |
| `enabledAppFunctionIds: List<String>` | The AppFunction identifiers or method names to discover. |
| `coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `Dispatchers.IO`. |

| Returns |
|---|---|
| `List<AgentTool>` | List of discovered `AgentTool` instances. |

### discover

```
suspend fun discover(
    context: Context,
    functionId: String,
    coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO
): List<AgentTool>
```

Discovers functions declared with `@androidx.appfunctions.AppFunction` matching `functionId` for the given `context` and converts them into a list of `AgentTool`s.

| Parameters |
|---|---|
| `context: Context` | The Android context. |
| `functionId: String` | The AppFunction identifier (e.g., `"com.example.MyService#createNote"`) or method name (e.g., `"createNote"`). |
| `coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `Dispatchers.IO`. |

| Returns |
|---|---|
| `List<AgentTool>` | List of discovered `AgentTool` instances. |