AppFunctionsToolset

Exposes Android AppFunctions to an agent as ADK BaseTools.

An app discovers and executes the functions it declares itself with no permission, which is the default here. Pass the toolset straight to an LlmAgent's toolsets:

val agent = LlmAgent(name = "notes", model = model, toolsets = listOf(AppFunctionsToolset(context)))

AppFunctions needs Android 16, or Android 14 on a device shipping the AppFunctions extension library; a device without it contributes no tools rather than failing, so an agent can carry this toolset without gating on the version itself. A function is likewise absent for a short while after its app is installed or updated, until the platform has indexed it.

A function that answers with a screen to open rather than data is not offered, since the model cannot read a PendingIntent and nothing here can act on one.

An app may also declare guidance covering its functions as a whole -- how they work together, which to call first -- and that is added to the model's instructions unless injectAppMetadata turns it off.

ADK declares androidx.appfunctions as compileOnly, so an app using this toolset must add that dependency itself.

Constructors

Link copied to clipboard
constructor(context: Context, filteredPackageNames: Set<String>? = setOf(context.packageName), toolFilter: ToolFilter? = null, injectAppMetadata: Boolean = true)

Functions

Link copied to clipboard
open override fun close()

Drops the cached tools, which hold the full metadata of everything last discovered.

Link copied to clipboard
open suspend override fun getTools(readonlyContext: ReadonlyContext? = null): List<BaseTool>

Discovers the app functions on the device and offers each as a tool.

Link copied to clipboard
open suspend override fun processLlmRequest(toolContext: ToolContext, llmRequest: LlmRequest): LlmRequest

Adds each offering app's guidance about its functions as a whole to the model's instructions.