Wiring AppFunctions to on-device LLM agents
Meta description: Learn how to expose your Android app as a first-party agentic tool using AppFunctions 1.0 — covering FunctionDescriptor schema design, intent routing, and Gemini Nano’s capability budget.
Tags: android kotlin architecture mobile api
TL;DR
AppFunctions 1.0 is the first stable, system-sanctioned way to make your Android app a callable tool for on-device AI agents. Done right, it delivers sub-200ms agentic action latency with zero cloud round-trips. Done wrong, it blows past Gemini Nano’s context budget and falls back silently. This post covers schema design, intent routing, and the memory/latency envelope you need to stay within.
Why AppFunctions changes the on-device AI story
In my experience building production systems on Android, app capabilities have always been exposed reactively — through deep links, Intents, or voice shortcuts. The agent invokes, the app responds, end of story.
AppFunctions 1.0 flips this model. Your app advertises structured, semantically typed function schemas to the Android AI layer, which can then reason over them, sequence them, and invoke them on behalf of the user — all locally, using Gemini Nano via AICore. No cloud. No latency cliff. No PII leaving the device.
The numbers matter. Cloud-routed tool calls through a hosted LLM average 800–2,000ms round-trip under typical mobile network conditions. A locally-resolved AppFunction invocation, with Gemini Nano handling routing, sits under 150–200ms on Pixel 9-class hardware. For agentic UX, that’s the difference between a feature users discover and one they abandon.
Designing the FunctionDescriptor schema
What most teams get wrong: they model their FunctionDescriptor around their internal domain objects, not around the semantic intent of an AI agent.
Gemini Nano must fit your entire function catalog — along with the user’s current intent and conversation state — inside a constrained context window. Verbose, nested schemas kill your capability budget fast.
A few principles that actually matter:
- Flat parameter structures win. Avoid nested objects; prefer primitive types with descriptive names.
- Use semantic names, not technical ones.
searchNearbyRestaurantsbeatsQueryPOIEntity. - Be disciplined about mandatory vs. optional. Every required parameter the model must infer adds token pressure.
@AppFunctionSerializable
data class SearchParams(
val query: String,
val radiusMeters: Int = 1000,
val maxResults: Int = 5
)
class MyAppFunctionService : AppFunctionService() {
@AppFunction(
description = "Search for items near the user's current location"
)
suspend fun searchNearby(
context: AppFunctionContext,
params: SearchParams
): SearchResult {
// execute locally, return structured result
}
}
Keep your total schema token footprint — across all advertised functions — under ~400 tokens. That leaves sufficient budget for the system prompt, user query, and response generation inside Nano’s window.
Intent routing: from the AI layer to your service
The Android AI layer performs semantic matching between the user’s expressed intent and your registered FunctionDescriptor entries. The architecture:
User utterance → Gemini Nano (AICore)
│
Intent classification
│
AppFunctionManager.executeAppFunction()
│
Your AppFunctionService
│
Local execution → Result
The system doesn’t expose routing confidence scores directly to your service. What you do control is the precision of your function descriptions. A/B testing with internal users across vague vs. specific descriptions consistently shows that specificity reduces misrouting by 30–50%; unsurprising given how embedding-based retrieval works, but worth measuring explicitly in your own catalog.
The capability budget: fitting inside Gemini Nano
| Resource | Gemini Nano constraint | Practical guideline |
|---|---|---|
| Context window | ~1,024–2,048 tokens (model-dependent) | Reserve ≤400 tokens for all function schemas |
| RAM headroom | ~1.5–2 GB for model weights | Avoid heavy operations during inference |
| Inference latency | 50–150ms on Pixel 9-class | Async-first; never block the main thread |
| Function response payload | Keep under ~512 tokens | Return structured summaries, not raw data dumps |
AICore manages model loading and lifecycle. Your AppFunctionService runs in a separate process and must be non-blocking. Any synchronous I/O or heavy computation in the execution path will degrade perceived agent responsiveness even if Nano itself is fast.
Capability negotiation at runtime
Not all devices run Gemini Nano. Use AppFunctionManager.isSupported() and check AICore availability before advertising functions. For unsupported devices, degrade gracefully to your existing deep link or shortcut surface — don’t leave a no-op registration in place.
val manager = getSystemService(AppFunctionManager::class.java)
if (manager.isAppFunctionSupported(this)) {
// register and advertise capabilities
}
What to actually remember
-
Schema budget is your first constraint. Design
FunctionDescriptorentries token-first, not domain-model-first. Audit total token footprint before shipping. -
Measure routing precision, not just invocation success. Instrument which functions are invoked and whether they match user intent. Misrouting is silent and costly.
-
Gate on AICore availability. AppFunctions without on-device AI support is dead code. Implement runtime capability negotiation and maintain a fallback surface for non-Nano devices.