AppFunctionAgentTools

@OptIn(markerClass = [ExperimentalAppFunctionsFeature])
public static class 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 fields

static @NonNull AppFunctionAgentTools

Public methods

static final @NonNull List<@NonNull AgentTool>
discover(@NonNull CoroutineDispatcher coroutineDispatcher)

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

static final @NonNull List<@NonNull AgentTool>
discover(
    @NonNull Context context,
    @NonNull CoroutineDispatcher coroutineDispatcher
)

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

static final @NonNull List<@NonNull AgentTool>
discover(
    @NonNull List<@NonNull String> enabledAppFunctionIds,
    @NonNull 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.

static final @NonNull List<@NonNull AgentTool>
discover(
    @NonNull String functionId,
    @NonNull 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.

static final @NonNull List<@NonNull AgentTool>
discover(
    @NonNull Context context,
    @NonNull List<@NonNull String> enabledAppFunctionIds,
    @NonNull CoroutineDispatcher coroutineDispatcher
)

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

static final @NonNull List<@NonNull AgentTool>
discover(
    @NonNull Context context,
    @NonNull String functionId,
    @NonNull CoroutineDispatcher coroutineDispatcher
)

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

Public fields

INSTANCE

public static @NonNull AppFunctionAgentTools INSTANCE

Public methods

discover

public static final @NonNull List<@NonNull AgentTool> discover(@NonNull CoroutineDispatcher coroutineDispatcher)

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

Parameters
@NonNull CoroutineDispatcher coroutineDispatcher

Dispatcher on which discovery executes. Defaults to Dispatchers.IO.

Returns
@NonNull List<@NonNull AgentTool>

List of discovered AgentTool instances scoped to the calling application's package.

discover

public static final @NonNull List<@NonNull AgentTool> discover(
    @NonNull Context context,
    @NonNull CoroutineDispatcher coroutineDispatcher
)

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

Parameters
@NonNull Context context

The Android context.

@NonNull CoroutineDispatcher coroutineDispatcher

Dispatcher on which discovery executes. Defaults to Dispatchers.IO.

Returns
@NonNull List<@NonNull AgentTool>

List of discovered AgentTool instances scoped to the calling application's package.

discover

public static final @NonNull List<@NonNull AgentTool> discover(
    @NonNull List<@NonNull String> enabledAppFunctionIds,
    @NonNull 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.

Parameters
@NonNull List<@NonNull String> enabledAppFunctionIds

The AppFunction identifiers or method names to discover.

@NonNull CoroutineDispatcher coroutineDispatcher

Dispatcher on which discovery executes. Defaults to Dispatchers.IO.

Returns
@NonNull List<@NonNull AgentTool>

List of discovered AgentTool instances.

discover

public static final @NonNull List<@NonNull AgentTool> discover(
    @NonNull String functionId,
    @NonNull 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.

Parameters
@NonNull String functionId

The AppFunction identifier (e.g., "com.example.MyService#createNote") or method name (e.g., "createNote").

@NonNull CoroutineDispatcher coroutineDispatcher

Dispatcher on which discovery executes. Defaults to Dispatchers.IO.

Returns
@NonNull List<@NonNull AgentTool>

List of discovered AgentTool instances.

discover

public static final @NonNull List<@NonNull AgentTool> discover(
    @NonNull Context context,
    @NonNull List<@NonNull String> enabledAppFunctionIds,
    @NonNull CoroutineDispatcher coroutineDispatcher
)

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

Parameters
@NonNull Context context

The Android context.

@NonNull List<@NonNull String> enabledAppFunctionIds

The AppFunction identifiers or method names to discover.

@NonNull CoroutineDispatcher coroutineDispatcher

Dispatcher on which discovery executes. Defaults to Dispatchers.IO.

Returns
@NonNull List<@NonNull AgentTool>

List of discovered AgentTool instances.

discover

public static final @NonNull List<@NonNull AgentTool> discover(
    @NonNull Context context,
    @NonNull String functionId,
    @NonNull CoroutineDispatcher coroutineDispatcher
)

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

Parameters
@NonNull Context context

The Android context.

@NonNull String functionId

The AppFunction identifier (e.g., "com.example.MyService#createNote") or method name (e.g., "createNote").

@NonNull CoroutineDispatcher coroutineDispatcher

Dispatcher on which discovery executes. Defaults to Dispatchers.IO.

Returns
@NonNull List<@NonNull AgentTool>

List of discovered AgentTool instances.