AppFunctionAgentTools

@OptIn(markerClass = [ExperimentalAppFunctionsFeature])
object AppFunctionAgentTools


Utility for discovering in-app Android AppFunctions and exposing them as AgentTools.

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:

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 AgentTools.

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 AgentTools.

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 AgentTools.

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 AgentTools.

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 AgentTools.

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 AgentTools.

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 AgentTools.

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 AgentTools.

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 AgentTools.

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 AgentTools.

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 AgentTools.

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 AgentTools.

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.