Sponsored byOutsenseAI that finds your next clients
SponsorGROUOutbound, LinkedIn content and leads for B2B teamsSponsorOutsenseAI that finds your next clientsAd+Your tool hereSeen by people installing AI tools@Weekly picksThe best new tools, one email a week

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.

  • Score 93
  • 11k stars
  • Apache-2.0
  • Updated
Works withClaude CodeClaude apps Antigravity CLI

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-api

Run in your terminal. Claude Code loads skills from ~/.claude/skills automatically.

Step-by-step: install mlkit-agent-api in Claude Code

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

A

No 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 →

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.

mlkit-agent-api Install

Add to stack

Loading.