mlkit-agent-api
하는 일
이 스킬은 Gemini Nano에서 실행되며 스스로 앱 함수를 호출할 수 있는 Android 에이전트를 만드는 방법을 안내합니다. 휴대폰에서 채팅 어시스턴트나 일회성 에이전트 작업을 만들려는 Android 개발자를 위한 스킬입니다. AICore Developer Preview를 대상으로 합니다.
사용하는 경우
- ✓기기 안에서 실행되는 여러 차례 대화형 채팅 어시스턴트를 Android 앱에 넣고 싶을 때.
- ✓기기 내 에이전트가 AppFunctions를 통해 앱 함수를 호출하게 하고 싶을 때.
- ✓대화 기록을 남기지 않고 에이전트가 한 번의 요청을 처리하게 해야 할 때.
스킬 링크
https://github.com/android/skills/blob/main/device-ai/mlkit-agent-api/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“내 Android 앱 안에 앱 함수를 호출할 수 있는 기기 내 채팅 어시스턴트를 만들어 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
이 스킬은 지시문과 러너를 갖춘 에이전트를 설정하고, ViewModel에서 채팅 세션을 유지하거나 일회성 요청을 실행합니다. 앱 함수는 에이전트가 호출할 수 있는 도구로 선언합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Targeting AICore Developer Preview. This skill provides authoritative execution patterns and failure-prevention rules for on-device agentic workflows in Android apps.
1. Prerequisites and setup
Gradle dependencies
// app/build.gradle.kts
dependencies {
// Core ML Kit GenAI Agent API
implementation("com.google.mlkit:genai-agent:1.0.0-alpha1")
// Android AppFunctions dependency for on-device tool declarations
implementation("androidx.appfunctions:appfunctions:1.0.0-alpha13")
}
[!IMPORTANT] Always use official SDK interfaces from
com.google.mlkit.genai.agent.*,androidx.appfunctions.*,com.google.mlkit.genai.prompt.*, andcom.google.mlkit.genai.common.*. Never declare local placeholder interfaces or fallback mocks.
2. Minimal agent and runner initialization
Configure an Agent with Agent.builder and wrap execution in AgentRunner:
import com.google.mlkit.genai.agent.Agent
import com.google.mlkit.genai.agent.AgentRunner
val agent = Agent.builder()
.setName("OnDeviceAssistant")
.setInstructions("You are a helpful on-device assistant.")
.build()
val runner = AgentRunner(agent)
Agent.builderdefaults tomaxTurns = 10automatically to prevent infinite tool loops.AgentRunnerdefaults to greedy decoding (temperature = 0.0f) for deterministic tool selection and schema compliance.AgentRunner(agent)automatically resolves application context usingMlKitContextfor AppFunction execution in Android apps. An explicitAgentRunner(context, agent)overload is available for headless tests or custom context scopes.
3. Multi-turn chat and lifecycle (ViewModel)
AgentSession preserves conversational history in memory and is not
Parcelable . To preserve dialogue history across Android configuration
changes (such as screen rotation), retain session inside an AndroidX
ViewModel.
When executing single-turn ephemeral queries, managing concurrent multi-sessions, or requiring explicit RAM cleanup, you must follow the guidelines in Session lifecycle.
package com.example.app
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.mlkit.genai.agent.Agent
import com.google.mlkit.genai.agent.AgentRunner
import com.google.mlkit.genai.agent.AgentSession
import com.google.mlkit.genai.agent.textTokens
import com.google.mlkit.genai.common.GenAiException
import com.google.mlkit.genai.prompt.Content
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
class ChatViewModel : ViewModel() {
private val agent = Agent.builder()
.setInstructions("You are a helpful on-device assistant.")
.build()
private val runner = AgentRunner(agent)
private val session: AgentSession =
runner.getOrCreateSession("chat_session")
private val _uiState = MutableStateFlow<ChatUiState>(ChatUiState.Idle)
val uiState: StateFlow<ChatUiState> = _uiState.asStateFlow()
fun sendMessage(prompt: String) {
viewModelScope.launch {
_uiState.value = ChatUiState.Loading("")
try {
// Content.builder() required; runAsync takes Content
val content = Content.builder().text(prompt).build()
var fullResponse = ""
session.runAsync(content)
// Extension function requiring textTokens import
.textTokens()
.collect { token ->
fullResponse += token
_uiState.value = ChatUiState.Loading(fullResponse)
}
_uiState.value = ChatUiState.Success(fullResponse)
} catch (e: GenAiException) {
// Catch GenAiException to prevent app crashes on AI errors
val err = e.localizedMessage ?: "AI error (${e.errorCode})"
_uiState.value = ChatUiState.Error(err)
}
}
}
override fun onCleared() {
super.onCleared()
// Evict conversation session from RAM when ViewModel
자주 묻는 질문
실서비스에 쓸 수 있나요?
이 스킬은 AICore Developer Preview를 대상으로 하므로, API가 미리 보기 버전일 수 있습니다.
무한 도구 호출 루프는 어떻게 막나요?
에이전트의 기본 설정은 턴 수를 10으로 제한해 무한 도구 루프를 막습니다.
어떤 라이브러리가 필요한가요?
ML Kit genai-agent 라이브러리와 AppFunctions 라이브러리를 사용합니다.
상세 정보
작성자의 원본 설명
Builds autonomous on-device agentic workflows in Android apps using the ML Kit GenAI Agent API powered by Gemini Nano and AICore. Use this skill when implementing conversational agents, multi-turn chat with AgentSession in a ViewModel, autonomous tool calling using Android AppFunctions (@AppFunctionDeclaration and AppFunctionAgentTools.discover), ephemeral single-turn execution with runner.runSingleTurnAsync, or handling GenAiException error resilience. It solves the problem of orchestrating local reasoning loops, typed tool dispatch, and session persistence on-device with zero cloud latency a
repo: android/skills
인기도
- GitHub 스타
- 10k
- 순위
- #11914
- 라이선스
- Apache-2.0
- 업데이트
- 2026. 10. 29.
댓글
- …
이 저장소의 다른 스킬
agp-9-upgrade
10k에이전트가 Android 앱을 Android Gradle Plugin 9로 업그레이드하고 호환되지 않는 변경 사항을 처리하도록 돕습니다. 멀티플랫폼 프로젝트는 대상이 아닙니다.
camerax
10k에이전트가 CameraX로 동영상 녹화, 하드웨어 제어, ML Kit와 Media3 효과를 포함한 Android 카메라 기능을 만들도록 돕습니다.
android-for-cars-parked-apps
10k에이전트가 Android 동영상, 게임 또는 브라우저 앱을 Android Auto와 Android Automotive의 주차 중 앱으로 실행되도록 맞추는 것을 돕습니다.
appfunctions
10k에이전트가 Android 앱의 핵심 작업 흐름을 찾아, AI 에이전트와 음성 명령이 실행할 수 있는 AppFunctions로 노출하도록 돕습니다.
비슷한 스킬
add-model-provider
394k에이전트가 안전한 설정 명령으로 새 AI 모델 제공자를 OpenClaw에 연결하고, API 키를 평문으로 두지 않으며, 실시간 테스트를 실행하도록 돕습니다.
acp-router
394k에이전트가 OpenClaw를 통해 Claude Code나 Cursor 같은 코딩 도우미에 작업을 전달해, 작업이 그 도구에서 실행되도록 돕습니다.
browser-automation
394k에이전트가 로그인, 탭, 페이지 응답이 멈췄을 때의 복구를 포함해 웹 페이지를 단계별로 조작하도록 가르칩니다.