mlkit-agent-api
Skill by android
Builds on-device agentic workflows in Android apps using the ML Kit GenAI Agent API with Gemini Nano and AICore. It covers multi-turn chat with AgentSession, tool calling through AppFunctions, and GenAiException handling. It is for Android developers targeting the AICore Developer Preview.
Install mlkit-agent-api
Built from the published package, never by AI.
git clone --depth 1 https://github.com/android/skills /tmp/skills && mkdir -p ~/.claude/skills && cp -r /tmp/skills/device-ai/mlkit-agent-api ~/.claude/skills/mlkit-agent-apiRun in your terminal. Claude Code loads skills from ~/.claude/skills automatically.
git clone --depth 1 https://github.com/android/skills /tmp/skills && mkdir -p ~/.gemini/antigravity-cli/skills && cp -r /tmp/skills/device-ai/mlkit-agent-api ~/.gemini/antigravity-cli/skills/mlkit-agent-apiAntigravity CLI loads skills from ~/.gemini/antigravity-cli/skills, or .agents/skills for one project.
Skills can run scripts on your machine. Some need an API key: check the README.
About
This skill gives an AI coding assistant execution patterns for building on-device agentic workflows in Android apps with the ML Kit GenAI Agent API, powered by Gemini Nano and AICore. It covers setting up an Agent and AgentRunner. Agent.builder defaults to maxTurns of 10, and AgentRunner defaults to greedy decoding. It also covers multi-turn chat held in an AgentSession inside a ViewModel, and ephemeral single-turn runs with runSingleTurnAsync.
Tools are defined as Android AppFunctions using @AppFunctionDeclaration. They can be registered declaratively or through AppFunctionAgentTools.discover. The skill also shows human-in-the-loop confirmation wrappers and handling of GenAiException. It is for Android developers building conversational agents that run on-device. The source says it does not cover cloud Gemini models, Vertex AI, or single-turn generation without agent loops.
Written from the project's SKILL.md and checked against it.
What it can do
- Agent setupConfigures an Agent and AgentRunner with instructions, a default turn limit and greedy decoding.
- Multi-turn chatKeeps conversation history in an AgentSession retained inside a ViewModel.
- Tool calling with AppFunctionsDeclares tools with @AppFunctionDeclaration and enables them on the Agent builder.
- Tool discoveryDiscovers AppFunctions with AppFunctionAgentTools.discover, optionally filtered by function ID.
- Human-in-the-loop wrappersWraps sensitive tools in an AgentTool decorator that asks the user to confirm first.
- Single-turn runsRuns one ephemeral request with runner.runSingleTurnAsync.
- Event handlingMatches AgentEvent values for text messages, function calls and function responses.
- Error handlingCatches GenAiException so AI errors do not crash the app.
What you need
- An Android app project using Gradle
- AICore Developer Preview
- Acceptance of the ML Kit GenAI API Additional Terms of Service
Try asking
- Add a multi-turn on-device chat screen to my Android app using AgentSession in a ViewModel.
- Expose my calendar functions as AppFunctions so an on-device agent can call them.
- Show me how to handle GenAiException in my ML Kit agent code.
Good to know
- Targets the AICore Developer Preview.
- AgentSession is not Parcelable, so it must be retained in a ViewModel to survive configuration changes.
- AppFunction returns must be primitives or @AppFunctionSerializable data classes. Map<String, Any?> is not supported.
- Declarative and advanced AppFunction configuration are mutually exclusive.
Security check
ANo download-and-run commands, hidden instructions or signs of sending keys out were found.
Checked automatically: device-ai/mlkit-agent-api/SKILL.md. This looks for known risky patterns and is not a full audit. How grades work
Inside the skill
-
SKILL.md14 KB -
references/session_lifecycle.md3 KB -
references/tools_and_functions.md12 KB
Alternatives to mlkit-agent-api
All alternatives →Aligns a Qwen Code feature with a Codex or Claude Code reference agent. It runs both under the same scenario, captures HTTP and terminal traces, and compares them until behavior matches.
Searches, views, creates, updates, and deletes the user's Google Contacts from an AI assistant. It is for people who want to manage their address book through conversation. A one-time Google connect is required before it returns data.
Guides an AI assistant on error handling choices. It covers when to use Result, Option, ? propagation, unwrap, expect and panic, plus anyhow and thiserror.
Caveman is an agent skill that makes an AI assistant reply in a terse style. It cuts filler and keeps technical facts, code, commands and errors exact. It is built for users who want shorter, cheaper replies.
docs-sync audits or updates English SDK documentation against the requested implementation scope. It is for maintainers who want docs to match main branch features, configuration options, and defaults.
Guides an AI assistant through setting up and running monorepos with pnpm workspaces, Turborepo and Nx. Aimed at developers who need faster builds, shared code and managed dependencies across multiple packages.
Compare with agent-reproduce-align, google_contacts or m06-error-handling
mlkit-agent-api: common questions
Does this skill work with cloud Gemini models?
No. The source says not to use it for cloud-based Gemini models or Vertex AI.
Why should AgentSession be kept in a ViewModel?
AgentSession is not Parcelable and keeps history in memory. Retaining it in a ViewModel preserves the dialogue across configuration changes such as screen rotation.
Can I combine declarative and advanced AppFunction setup?
No. The source says the declarative path and the advanced discovery path are mutually exclusive.
How do I install mlkit-agent-api?
Run the command above to copy the skill into ~/.claude/skills/. Claude Code picks it up automatically.
Is mlkit-agent-api free?
The code is published under the Apache-2.0 licence. The service it connects to may have its own pricing.
Is mlkit-agent-api safe to use?
It scores 93 of 100. Grades: maintenance A, licence A, quality A. Security check: grade A, no risky patterns found in the files checked. Review the code before you install. How grades work.
What are alternatives to mlkit-agent-api?
Similar skills: agent-reproduce-align, google_contacts, m06-error-handling, caveman.
