
ML Kit On-Device Agent API
Build on-device Android agents with Gemini Nano, multi-turn sessions and tool calling via AppFunctions
- Repository
- android/skills
- Stars
- 10,278
- Licence
- Apache-2.0
- Files
- 3 files
What it does
This skill gives an AI coding agent detailed, authoritative patterns for building Android apps that run an autonomous AI agent entirely on the device using Google's ML Kit GenAI Agent API (powered by Gemini Nano through AICore). It tells the agent how to set up the Gradle dependencies, create an Agent and AgentRunner, keep multi-turn chat sessions alive in a ViewModel, let the model call typed app functions declared with AppFunctions, and handle GenAiException errors. Once installed, the agent writes Android code that follows these rules rather than guessing at APIs.
Great for
- Android developers adding a local, privacy-preserving chat or assistant feature to an app
- Teams experimenting with on-device tool calling through AppFunctions
- Developers who need guidance on session lifecycle and cleaning up model memory
Skip it if
- Cloud-hosted Gemini or Vertex AI projects, which this skill explicitly excludes
- Simple one-shot text generation with no agent loop; the skill itself suggests the Prompt API instead
- Non-Android platforms such as iOS or web, or apps relying on an unreleased SDK: the skill targets the AICore Developer Preview and alpha library versions, so APIs may change
Try asking
- “Add a multi-turn chat screen to my Android app that uses on-device Gemini Nano and keeps history across rotation”
- “Let the on-device model call my app's functions to book reminders, using AppFunctions tool discovery”
- “Write a ChatViewModel that streams tokens into a Compose UI and handles GenAiException gracefully”
- “Run a single ephemeral query with runner.runSingleTurnAsync and free the session afterward”
Install in 3 steps
- 1
Download the skill
The ZIP contains the 3 original files, the Apache-2.0 licence and an attribution note.
mlkit-agent-api.zip - 2
Add it to your agent
Claude Code (all projects)
mkdir -p ~/.claude/skills && unzip mlkit-agent-api.zip -d ~/.claude/skills/Claude Code / Agent SDK (this project only)
mkdir -p .claude/skills && unzip mlkit-agent-api.zip -d .claude/skills/Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.
- 3
Ask for the task
No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.
Get better results
- Pin the exact alpha library versions listed in the skill and check them against current ML Kit and AppFunctions release notes, since the skill targets preview APIs.
- Ask the agent to follow the lifecycle rules: keep the session in a ViewModel and call session.close() in onCleared to free RAM.
- Review generated code yourself and test on a supported physical device, because on-device model availability varies by hardware.
What's inside
- references/session_lifecycle.md
- references/tools_and_functions.md
- SKILL.md
Redistributed unmodified from android/skills under the Apache-2.0 licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.