应用程序(App)函数Toolset

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)

函数

Link copied to clipboard
open override fun close()

删除那些缓存工具;这些工具中保存了上次发现的所有内容的完整元数据。

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

该功能会检测设备上的应用程序功能,并将这些功能分别作为独立的工具提供给用户使用。

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

将每个应用程序关于其整体功能的说明添加到模型的使用指南中。