Appfunctions
Android (Google)OfficialCreated by Google LLCDistributed by Android (Google)
- Skill
- Tool integration
- Software development
- Apache-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The appfunctions skill provides a structured approach to exposing Android app workflows as AppFunctions. It covers the full development lifecycle, including feature discovery, Kotlin implementation using the androidx.appfunctions library, KDoc optimization for AI agents, and local testing via ADB. It ensures developers can build modular, secure, and discoverable tools that allow AI agents, voice commands, and system shortcuts to interact with app functionality without requiring the user to open the app UI.
What it does
- Analyzes Android codebases to identify workflows suitable for AppFunctions.
- Generates Kotlin code using the androidx.appfunctions library and KSP.
- Refines KDoc and app metadata to improve AI agent understanding and tool selection.
- Provides ADB commands for listing, executing, and managing AppFunction states.
- Supports migration from legacy AppFunction APIs to the modern Service Entry Point architecture.
- Enforces security constraints to ensure only safe, non-destructive tasks are exposed.
When to use it
- When you need to expose app features to AI agents or system-level voice commands.
- When implementing or upgrading to the latest androidx.appfunctions library.
- When you need to optimize existing function descriptions for better LLM or MCP compatibility.
- When testing or debugging AppFunction registration and execution on a local device or emulator.
- When migrating legacy AppFunction implementations to the current service entry point pattern.
Advantages
- Enables seamless, UI-less interaction between AI agents and Android applications.
- Standardizes the implementation process through clear, step-by-step development workflows.
- Improves discoverability and reliability of app tools for AI models.
- Provides robust testing capabilities via direct ADB command integration.
- Ensures backward compatibility through the use of Jetpack libraries.
Usage examples
- “Analyze my app to find features that should be exposed as AppFunctions.”
- The agent will perform a feature discovery analysis, identifying key user workflows and recommending which should be implemented as AppFunctions.
- “How do I implement a 'send message' AppFunction in my Kotlin project?”
- The agent will guide you through generating the necessary Kotlin code, configuring the service entry point, and adding the required annotations.
- “Optimize my AppFunction KDocs so an AI agent knows how to use them.”
- The agent will review your existing KDoc and app metadata, providing refinements to ensure clear, intent-based descriptions for AI models.
- “List all registered AppFunctions on my device for package com.example.app.”
- The agent will provide the specific ADB command to query and display the registered functions for your application.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/android/appfunctions/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip appfunctions.zip -d .agents/skills
Documentation by Google LLC
Analyzes Android apps to identify key user workflows to expose as AppFunctions, such as creating a note, playing media, or sending a message, for AI agents, voice commands, and system shortcuts to run without opening the app UI.
Generates Kotlin code to expose these workflows to the Android system, allowing agents to discover and execute them on-device.
Also refines KDoc documentation and the app description so AI agents correctly understand and use the provided functionality.
Prerequisites
The app must targetSdk 36 or newer and use compileSdk 37 or newer as
AppFunctions, part of the Android platform API, are available from Android 16
onwards.
Always use the Jetpack library because it handles backward compatibility.
Use androidx.appfunctions:appfunctions and the KSP compiler
androidx.appfunctions:appfunctions-compiler, version 1.0.0-beta01 or later.
Workflows
This skill enables the caller to discover features that will be provided to system agents, implement these with AppFunctions, improve function description for agents, and use ADB commands for local evaluation and testing.
The full AppFunction development flow consists of these four steps:
Step 1: Discovery: Analyze Android codebases to identify and recommend potential AppFunctions. Use this step when a user asks to "discover AppFunctions," "find features for AI," or "analyze my app for agentic tools."
Step 2: Implementation and configuration: Generate Kotlin implementations of AppFunctions, manage system-wide configuration, and configure build dependencies. Use this step when a user asks to "implement AppFunctions," "set up the AppFunctions framework," or "configure Hilt for AppFunctions."
Step 3: KDoc refinement: Optimize AppFunction KDoc and the app description for AI agents and Model Context Protocol. If a user asks to "write KDoc", "optimize for MCP", or "refactor tool descriptions for LLMs", use this step.
Step 4: Testing and debugging: Provide commands to interact with AppFunctions using ADB for testing and debugging. If a user wants to "list app functions", "invoke an app function", or "verify app function registration" on a device, use this step.
When the user asks for a subset of the steps, run those steps and any step that the critical constraints require. Then list the skipped steps and ask whether to run them.
If they apply, you must load the following references:
Context and terminology: Defines the ubiquitous language, architecture definitions, and design patterns across the AppFunctions skill suite. Load when you need to understand core architecture terminology or check the distinctions between modern and legacy AppFunctions APIs.
Migration to service entry point : Migrates apps on AppFunctions 1.0.0-alpha09 or lower to the
AppFunctionServiceEntryPointarchitecture from 1.0.0-alpha10, and upgrades apps to 1.0.0-beta01. Load it when a user asks to migrate or upgrade existing AppFunctions code. When you find legacyAppFunctionConfiguration.Providerimplementations,@AppFunctionannotations, orappfn:descriptionattributes, load it and ask the user before you migrate.
Critical constraints
Modular consistency: You must refine KDocs immediately after you generate AppFunction implementations.
Security: Expose only safe, non-destructive tasks that the app's UI already offers on that form factor. Never give agents wide-ranging access to user data or system resources. Never require or return passwords, financial details, private keys, or other highly sensitive personal information.
Descriptions: Describe what each function does, never how an agent must behave. Put call order across functions in the app description, not in function KDoc.
Troubleshooting
If you encounter build-time errors such as Kotlin Symbol Processing (KSP) issues, see Implementation and configuration.
If you encounter runtime errors such as missing services or execution failures, see Testing and debugging.
If you need architecture definitions and vocabulary, see Context and terminology.
If you encounter issues when upgrading AppFunctions, such as errors on
@AppFunction, which is no longer an annotation, see Migration to service entry point.
Files
- ATTRIBUTION.mdAdded by AutoGineer953 B
- LICENSELicence file added by AutoGineer11.1 KiB
- SKILL.md5.6 KiB
- references/adb-interaction-testing.md4.1 KiB
- references/context.md1.6 KiB
- references/feature-discovery-analysis.md3.2 KiB
- references/implementation-configuration.md13.2 KiB
- references/kdoc-refinement-optimization.md4.7 KiB
- references/migrate-to-service-entry-point.md11.6 KiB
references/implementation-configuration.md
Specialized instructions for generating Kotlin implementations of AppFunctions, handling system-wide configuration, and managing build dependencies.
Instructions
Step 1: Configure Gradle dependencies and KSP
Add the following to build.gradle.kts. App Functions requires the KSP (Kotlin
Symbol Processing) plugin.
Version check : Use library version
1.0.0-beta01or later from maven.google.com.Version catalog : The following snippet uses version catalog aliases for
androidx.appfunctions:appfunctionsandandroidx.appfunctions:appfunctions-compiler. Add both tolibs.versions.toml. Without a version catalog, declare the coordinates and version directly.
implementation(libs.androidx.appfunctions)
ksp(libs.androidx.appfunctions.compiler)<br />
<br />
<br />
Step 2: Set up app metadata XML
Describe the app's capabilities to the LLM by defining
res/xml/app_metadata.xml. Write the app description in the
appfn:instructions attribute, as described in the KDoc refinement step.
Before 1.0.0-beta01, this attribute was appfn:description. The optional
appfn:displayDescription attribute references a string resource with a
short, user-visible summary of what the app's functions let agents do.
Define that resource, or omit the attribute.
<AppFunctionAppMetadata xmlns:appfn="http://schemas.android.com/apk/androidx.appfunctions"
appfn:description="This app manages user tasks and reminders.
Operational Patterns:
- Use 'createTask' to add new tasks or reminders with titles and content.
Constraints:
- Title or content must be non-null when creating a task."
appfn:displayDescription="@string/user_visible_description" /><br />
Register the service and reference the app metadata in AndroidManifest.xml
within the <application> tag:
<service
android:name="com.example.snippets.ai.TaskAppFunctionService"
android:permission="android.permission.BIND_APP_FUNCTION_SERVICE"
android:exported="true"
tools:targetApi="36">
<property
android:name="android.app.appfunctions.schema"
android:value="app_functions_schema.xsd" />
<property
android:name="android.app.appfunctions.v2"
android:value="task_app_function_service.xml" />
<intent-filter>
<action android:name="android.app.appfunctions.AppFunctionService" />
</intent-filter>
</service>
<property
android:name="android.app.appfunctions.app_metadata"
android:resource="@xml/app_metadata" /><br />
Set android:name to the class that KSP generates from the serviceName of
the @AppFunctionServiceEntryPoint class in Step 4, in that class's package.
Set the android.app.appfunctions.v2 value to its appFunctionXmlFileName
plus .xml.
Step 3: Implement functions
When generating Kotlin code for AppFunctions, you MUST adhere to these rules:
Annotations :
Annotate the function with
@AppFunctionDeclaration(isDescribedByKDoc = true). Before 1.0.0-alpha13, this annotation was@AppFunction.Annotate associated data classes with
@AppFunctionSerializable(isDescribedByKDoc = true).Always set
isDescribedByKDocexplicitly. Since 1.0.0-beta01, it has no default value.
Naming and parameters :
Function names : Give each function a human-readable name that identifies its purpose, such as
createTask. Never use a name that misstates what the code does or resembles another tool or service.Specificity: Keep parameters specific. State objects must be unambiguous.
Necessity: Define parameters only for data that the function uses.
Naming : Name parameters after the expected input, such as
taskId,searchQuery, orrecipientEmail. Never use names such asfull_contextorconversation_history. These ambiguous names risk agents passing unneeded user data to the function.Optionality: If a parameter isn't essential, make it optional with a default value.
Updates : For functions that update existing items, distinguish "set to null" from "don't change". Declare each updatable parameter as a nullable
@AppFunctionSerializablewrapper class that the app defines, such asSetField<T>. Anullwrapper means "don't change", and a wrapper that holdsnullmeans "set to null". Never unwrap a nullable field with?:, which turns "set to null" into "don't change".
Execution and threading :
Use
suspendfunctions.To avoid blocking the Android UI thread, always run AppFunction implementations on a background dispatcher, such as
withContext(Dispatchers.IO).
Supported types :
Primitives :
Int,Long,Float,Double,BooleanArrays :
IntArray,LongArray,FloatArray,DoubleArray,BooleanArrayNative types :
String,PendingIntent,Uri,LocalTime,LocalDate,LocalDateTime,Instant,ZoneId. Prefer usingLocalDateTimeorInstantfor date and time fields.Custom objects : Classes annotated with
@AppFunctionSerializable.Collections :
Listof any supported non-primitive typeUse these types instead of defining custom date, time, or link classes. The library represents them the same way in every app.
Default values :
Optional parameters MUST be nullable, primitive, list, or array types.
Declare defaults that match the type's empty state, such as
0forInt,nullfor nullable objects, andemptyList()forList.When the agent omits a parameter, the library passes this empty value, not the declared default. Resolve meaningful defaults in the function body.
Error handling :
Throw the
androidx.appfunctions.AppFunctionExceptionsubclass that matches the cause, with a plain-language message. For example, throwAppFunctionInvalidArgumentExceptionfor an invalid argument, orAppFunctionElementNotFoundExceptionfor a missing item.Never let other exceptions escape. The agent receives them as
AppFunctionAppUnknownException, which doesn't identify the failure.
Security :
Expose only safe, non-destructive tasks that the app's UI already offers on that form factor.
Never give agents wide-ranging access to user data or system resources.
Never require or return passwords, financial details, private keys, or other highly sensitive personal information. Share other personal or confidential data only when the user explicitly consents to share it for the requested action.
Never perform actions that the user didn't request. Actions that the user scheduled, such as sending a message later, are allowed.
Opening screens :
To let the agent open a screen in the app, return a
PendingIntent. Create it from an explicit intent withFLAG_IMMUTABLE, which locks where it leads.
Step 4: Set up dependency injection and service entry points
In version 1.0.0-alpha10 and later, App Functions use the compile-time
@AppFunctionServiceEntryPoint architecture. Create an abstract class extending
AppFunctionService annotated with @AppFunctionServiceEntryPoint. KSP
generates the concrete service class and XML schema. Declare only one entry
point class: before Build.VERSION_CODES.CINNAMON_BUN, Android allows only
one service per app to handle the
android.app.appfunctions.AppFunctionService action.
Recommended approach with Hilt
Annotate your service with @AndroidEntryPoint and inject your data
repositories or use cases using standard @Inject internal lateinit var:
@RequiresApi(36)
@AndroidEntryPoint
@AppFunctionServiceEntryPoint(
serviceName = "ConfigAppFunctionServiceHeader",
appFunctionXmlFileName = "config_app_function_service_header",
)
abstract class BaseAppFunctionServiceHeader : AppFunctionService() {
@Inject internal lateinit var messageRepository: MessageRepository
@AppFunction(isDescribedByKDoc = true)
internal suspend fun send(
name: String,
endpointValue: String,
messageBody: String,
): MessageResult {
return messageRepository.send(name, endpointValue, messageBody)
}
}<br />
Framework-agnostic approach with alternative dependency injection or service locators
While Hilt is recommended, many Android applications implement AppFunctions with
alternative dependency injection frameworks (like Koin, Anvil, or manual Service
Locators). Because AppFunctionService inherits from Android
android.app.Service (and therefore Context), you are able access your
application's DI container directly through applicationContext in property
getters or during service lifecycle execution:
@RequiresApi(36)
@AppFunctionServiceEntryPoint(
serviceName = "ServiceLocatorConfigAppFunctionService",
appFunctionXmlFileName = "service_locator_config_app_function_service",
)
abstract class BaseAppFunctionServiceLocator : AppFunctionService() {
// Example using a manual Service Locator / Application container
private val messageRepository by lazy {
(applicationContext as AppFunctionApplication).appContainer.messageRepository
}
// Or with Koin / alternative DI locators:
// private val messageRepository: MessageRepository by inject()
@AppFunction(isDescribedByKDoc = true)
internal suspend fun send(
name: String,
endpointValue: String,
messageBody: String,
): MessageResult {
return messageRepository.send(name, endpointValue, messageBody)
}
}<br />
Step 5: Architectural cleanliness
Don't attempt to make an AppFunction class or method OS-agnostic---AppFunctions
are inherently part of the Android platform integration in
androidx.appfunctions. For architectural cleanliness, use existing
application functionality (such as existing repositories, use cases, or domain
orchestrators) to execute the behavior within the @AppFunctionDeclaration
methods rather than creating redundant abstraction layers around the OS service.
<br />
Critical constraints
KSP compliance for serializables
Critical constraints : For @AppFunctionSerializable data classes, KSP
only extracts documentation if it's written as inline KDoc directly for each
property definition. Don't use class-level @param or @property tags.
Declare every primary constructor parameter as a val property, and keep the
primary constructor public. Other constructor parameters cause a compiler
error.
Package integrity
The @AppFunctionDeclaration annotation, AppFunctionService, and
AppFunctionName are located in androidx.appfunctions. Before 1.0.0-beta01,
AppFunctionName was in androidx.appfunctions.metadata.
Examples
Example: Serializable with inline KDoc
/** The parameter to create the task. */
@AppFunctionSerializable(isDescribedByKDoc = true)
data class CreateTaskParams(
/** The title of the task. */
val title: String?,
/** The content of the task. */
val content: String?,
)
/** The user-created task. */
@AppFunctionSerializable(isDescribedByKDoc = true)
data class Task(
/** The ID of the task. */
val id: String,
/** The title of the task. */
val title: String,
/** The content of the task. */
val content: String,
)<br />
<br />
Example: Implementation detail
@RequiresApi(36)
@AndroidEntryPoint
@AppFunctionServiceEntryPoint(
serviceName = "TaskAppFunctionService",
appFunctionXmlFileName = "task_app_function_service",
)
abstract class BaseTaskAppFunctionService : AppFunctionService() {
@Inject internal lateinit var taskRepository: TaskRepository
/**
* Creates a task based on [createTaskParams].
*
* @param createTaskParams The parameter to describe how to create the task.
*/
@AppFunction(isDescribedByKDoc = true)
suspend fun createTask(
createTaskParams: CreateTaskParams,
): Task = withContext(Dispatchers.IO) {
// Developers can use predefined exceptions to let the agent know
// why it failed.
if (createTaskParams.title == null && createTaskParams.content == null) {
throw AppFunctionInvalidArgumentException("Title or content should be non-null")
}
val id = taskRepository.createTask(
createTaskParams.title,
createTaskParams.content
)
return@withContext taskRepository
.getTask(id)
?.toTask()
?: throw AppFunctionElementNotFoundException("Task not found for ID = $id")
}
// Maps internal TaskEntity
private fun TaskEntity.toTask() = Task(id = id, title = title, content = description)
}<br />
<br />
Troubleshooting
Error: Build fails after adding or upgrading the library
Cause : An annotation omits isDescribedByKDoc, which has no default value
since 1.0.0-beta01, or the module's compileSdk is lower than 37.
Solution : Set isDescribedByKDoc = true on every @AppFunctionDeclaration
and @AppFunctionSerializable, and set compileSdk to 37 or higher.
Error: "AppFunction unavailable" or "Metadata missing"
Cause: The AppSearch indexing failed to extract the schema correctly.
Solution:
Verify
@AppFunctionSerializableclasses use inline KDoc comments, not class-level@paramtags.Check that the
assets/<appFunctionXmlFileName>.xmlfile exists in the APK.Confirm the
ksp("androidx.appfunctions:appfunctions-compiler")dependency is correctly applied.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Google LLC
- Publisher
- Android (Google) (Official)
- Distributed by
- Android (Google)
- Source
- android/skills · device-ai/appfunctions · commit bf68e2d
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.txt)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Google LLC or Android (Google).
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download appfunctions.zip