Skip to content

Guide · Agent skill

How to use the ML Kit On-Device Agent API agent skill

Updated · written with AI from the project's own documentation and checked against our catalogue data

The mlkit-agent-api skill teaches an AI coding agent how to build Android apps that run an autonomous AI agent entirely on the device, using Google's ML Kit GenAI Agent API with Gemini Nano through AICore. This guide explains what the skill does, how to install it, how to ask for it in plain language, and what to check before using it. By the end you will know how the agent will structure a multi-turn chat, typed tool calling and error handling in your Android project.

ML Kit On-Device Agent APIandroid/skills · Apache-2.0

Quick start

  1. 1Download the skill. Download the ZIP of mlkit-agent-api from this page and unzip it.
  2. 2Place or upload it. Copy the folder to ~/.claude/skills/ for personal use or to .claude/skills/ in your project. In the Claude apps, upload it under Settings, then Capabilities, then Skills.
  3. 3Check your project. Confirm your app uses Gradle with the Kotlin DSL and that your target device supports AICore and Gemini Nano.
  4. 4Ask for the feature. Describe the on-device chat or tool-calling feature you want, mentioning Android and on-device AI.
  5. 5Review the generated code. Check the Agent, AgentRunner, ViewModel and session handling the agent writes against the skill's patterns.
  6. 6Test the error paths. Confirm that GenAiException is caught and shown to the user, so an AI failure does not crash the app.

What the skill makes the agent do

An agent skill is a folder of instructions and reference files that an AI coding agent loads when a task matches its description. This one covers on-device agentic workflows in Android apps. Once it is loaded, the agent writes Android code that follows its patterns instead of guessing at APIs.

The skill covers four areas: setting up the Gradle dependencies, creating an Agent and an AgentRunner, keeping multi-turn chat sessions alive in a ViewModel, and letting the model call typed app functions declared with AppFunctions. It also covers handling GenAiException errors so the app does not crash on AI failures.

  • Gradle setup for the ML Kit GenAI Agent API and the AndroidX AppFunctions library
  • Agent and AgentRunner initialization
  • Multi-turn AgentSession kept in a ViewModel
  • Tool calling with @AppFunctionDeclaration and AppFunctionAgentTools.discover
  • Ephemeral single-turn runs with runner.runSingleTurnAsync
  • Session cleanup and GenAiException handling

How to install the mlkit-agent-api skill

Download the ZIP of the skill from this page and unzip it. You can install it for yourself across all projects, or only for one project.

For a personal install, place the unzipped skill folder in ~/.claude/skills/. For a project-only install, place it in the .claude/skills/ folder inside your Android project.

If you use the Claude apps, you can instead upload the skill under Settings, then Capabilities, then Skills.

  • Personal install: ~/.claude/skills/
  • Project install: .claude/skills/ inside your project folder
  • Claude apps: Settings → Capabilities → Skills, then upload the ZIP

What your Android project needs

The skill assumes an Android app project that uses Gradle with the Kotlin DSL. Your app needs the ML Kit GenAI Agent API library and the AndroidX AppFunctions library. The skill targets the AICore Developer Preview, so the device must support AICore and Gemini Nano.

The skill is not for every project. It targets Android only, and it is built for the preview libraries, so APIs may change.

  • Android app project using Gradle (Kotlin DSL)
  • Library: com.google.mlkit:genai-agent
  • Library: androidx.appfunctions:appfunctions
  • A device that supports AICore and Gemini Nano
// app/build.gradle.kts dependencies { implementation("com.google.mlkit:genai-agent:1.0.0-alpha1") implementation("androidx.appfunctions:appfunctions:1.0.0-alpha13") }

How to trigger the skill with natural requests

You do not need to name the skill. The agent loads it when your request matches its description. Describe the feature you want in plain terms and mention Android or on-device AI so the match is clear.

The skill is designed for agents with multi-turn chat, tool calling and session handling. For a one-off text generation with no agent loop, the skill itself suggests using the Prompt API instead.

  • Add an on-device chat assistant to my Android app that keeps history across screen rotation.
  • Let my on-device Gemini Nano agent call my app's calendar functions using AppFunctions.
  • Write a single-turn ephemeral query with runSingleTurnAsync and handle GenAiException errors.
  • Set up an Agent and AgentRunner in Kotlin and release the session when the ViewModel is cleared.

How sessions and memory are handled

AgentSession keeps conversation history in memory and is not Parcelable. To keep dialogue history across configuration changes such as screen rotation, the skill has the agent keep the session inside an AndroidX ViewModel. The session ID can be stored in SavedStateHandle so the same conversation thread continues.

The skill also asks the agent to close the session in onCleared(), which frees the conversation memory and cancels pending tasks. Agent.builder defaults to a maximum of 10 turns to prevent endless tool loops, and AgentRunner defaults to greedy decoding for more predictable tool selection.

  • Keep the session in a ViewModel to survive rotation
  • Store the session ID in SavedStateHandle
  • Call session.close() in onCleared()
  • Always include an else branch when matching AgentEvent, because it is non-exhaustive
override fun onCleared() { super.onCleared() session.close() }

Safety notes: scripts and network

The skill does not run scripts, and it does not use the network. Its files are reference documents that the agent reads while it writes your code. The agent's work happens in your project, and the model runs on the device.

The skill excludes cloud-hosted Gemini and Vertex AI projects. Review any code the agent writes before you ship it, especially the tool functions, since those are the actions the model is allowed to trigger in your app.

  • Runs scripts: no
  • Uses network: no
  • Excludes cloud Gemini and Vertex AI
  • Review tool functions the model can call before release

What people use it for

  • Adding a private, on-device chat assistant to an Android app that keeps conversation history across screen rotation
  • Letting a local model call typed app functions, such as reading calendar events, through AppFunctions
  • Building a single-turn query with runSingleTurnAsync where no conversation history is needed
  • Adding human-in-the-loop confirmation to discovered app functions, using the skill's tools reference

Frequently asked questions

How do I install the mlkit-agent-api skill?

Download the ZIP from this page and unzip it. Put the folder in ~/.claude/skills/ for personal use, or in .claude/skills/ inside your Android project for a project-only install. In the Claude apps you can upload the ZIP under Settings, then Capabilities, then Skills.

What does the mlkit-agent-api skill require?

It needs an Android app project using Gradle with the Kotlin DSL, the ML Kit GenAI Agent API library, the AndroidX AppFunctions library, and a device that supports AICore and Gemini Nano. The skill targets the AICore Developer Preview.

Is the mlkit-agent-api skill free to use?

The skill is licensed under Apache-2.0, and its complete terms are in the LICENSE.txt file included with it. This page does not state any pricing for the ML Kit libraries, so check their own terms before you build on them.

Does the skill work for iOS or web apps?

No. The skill covers Android only. It does not cover iOS, web, or cloud-hosted Gemini and Vertex AI projects.

What should I use instead for simple text generation?

For single-turn text generation with no agent loop, the skill suggests the Prompt API from ML Kit instead. Use the agent API when you need multi-turn chat or tool calling.

Why does my ML Kit agent code fail or crash?

Catch GenAiException in your ViewModel and show the error message to the user, so AI errors do not crash the app. Also check that the device supports AICore and Gemini Nano, and that you are using the library versions the skill targets, since the preview APIs may change.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

This skill suits Android developers who want a private, on-device chat or assistant feature with typed tool calling through AppFunctions, and who are comfortable with preview libraries. Pick something else if you need cloud-hosted Gemini or Vertex AI, iOS or web support, or only simple one-shot text generation, where the Prompt API is the better fit.

Download the skill