# AppFunctionAgentTools


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

<br />

*** ** * ** ***

Utility for discovering in-app Android AppFunctions and exposing them as `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/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 `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent`.

Example:

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

## Summary

| ### Public functions |
|---|---|
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<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/AppFunctionAgentTools#discover(kotlinx.coroutines.CoroutineDispatcher)(coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html)` Discovers all in-app functions declared with `@androidx.appfunctions.AppFunction` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s. |
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<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/AppFunctionAgentTools#discover(android.content.Context,kotlinx.coroutines.CoroutineDispatcher)(context: https://developer.android.com/reference/android/content/Context.html, coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html)` Discovers all in-app functions declared with `@androidx.appfunctions.AppFunction` for the given `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(android.content.Context,kotlinx.coroutines.CoroutineDispatcher)` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s. |
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<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/AppFunctionAgentTools#discover(kotlin.collections.List,kotlinx.coroutines.CoroutineDispatcher)( enabledAppFunctionIds: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>, coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html )` Discovers in-app functions declared with `@androidx.appfunctions.AppFunction` matching `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlin.collections.List,kotlinx.coroutines.CoroutineDispatcher)` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s. |
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<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/AppFunctionAgentTools#discover(kotlin.String,kotlinx.coroutines.CoroutineDispatcher)(functionId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html)` Discovers in-app functions declared with `@androidx.appfunctions.AppFunction` matching `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlin.String,kotlinx.coroutines.CoroutineDispatcher)` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s. |
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<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/AppFunctionAgentTools#discover(android.content.Context,kotlin.collections.List,kotlinx.coroutines.CoroutineDispatcher)( context: https://developer.android.com/reference/android/content/Context.html, enabledAppFunctionIds: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>, coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html )` Discovers functions declared with `@androidx.appfunctions.AppFunction` matching `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(android.content.Context,kotlin.collections.List,kotlinx.coroutines.CoroutineDispatcher)` for the given `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(android.content.Context,kotlin.collections.List,kotlinx.coroutines.CoroutineDispatcher)` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s. |
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<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/AppFunctionAgentTools#discover(android.content.Context,kotlin.String,kotlinx.coroutines.CoroutineDispatcher)( context: https://developer.android.com/reference/android/content/Context.html, functionId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html )` Discovers functions declared with `@androidx.appfunctions.AppFunction` matching `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(android.content.Context,kotlin.String,kotlinx.coroutines.CoroutineDispatcher)` for the given `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(android.content.Context,kotlin.String,kotlinx.coroutines.CoroutineDispatcher)` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/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 `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s.

| Parameters |
|---|---|
| `coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool>` | List of discovered `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/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 `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(android.content.Context,kotlinx.coroutines.CoroutineDispatcher)` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The Android context. |
| `coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool>` | List of discovered `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/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 `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlin.collections.List,kotlinx.coroutines.CoroutineDispatcher)` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s.

| Parameters |
|---|---|
| `enabledAppFunctionIds: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>` | The AppFunction identifiers or method names to discover. |
| `coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool>` | List of discovered `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` instances. |

### discover

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

Discovers in-app functions declared with `@androidx.appfunctions.AppFunction` matching `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlin.String,kotlinx.coroutines.CoroutineDispatcher)` using `MlKitContext.getInstance().applicationContext` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s.

| Parameters |
|---|---|
| `functionId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | The AppFunction identifier (e.g., `"com.example.MyService#createNote"`) or method name (e.g., `"createNote"`). |
| `coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool>` | List of discovered `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/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 `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(android.content.Context,kotlin.collections.List,kotlinx.coroutines.CoroutineDispatcher)` for the given `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(android.content.Context,kotlin.collections.List,kotlinx.coroutines.CoroutineDispatcher)` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The Android context. |
| `enabledAppFunctionIds: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>` | The AppFunction identifiers or method names to discover. |
| `coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool>` | List of discovered `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` instances. |

### discover

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

Discovers functions declared with `@androidx.appfunctions.AppFunction` matching `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(android.content.Context,kotlin.String,kotlinx.coroutines.CoroutineDispatcher)` for the given `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(android.content.Context,kotlin.String,kotlinx.coroutines.CoroutineDispatcher)` and converts them into a list of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`s.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The Android context. |
| `functionId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | The AppFunction identifier (e.g., `"com.example.MyService#createNote"`) or method name (e.g., `"createNote"`). |
| `coroutineDispatcher: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html = Dispatchers.IO` | Dispatcher on which discovery executes. Defaults to `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool>` | List of discovered `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` instances. |