ML Kit's agentic workflows (com.google.mlkit:genai-agent, Alpha)
let you build autonomous, multi-turn on-device conversational experiences
powered by Gemini Nano and the Android AICore system service.
Built on top of the GenerativeModel class (direct model access),
the AgentRunner class automates complete, goal-driven agentic loops
directly within your app: observing context, reasoning over user inputs, acting
through typed Kotlin tools, and evaluating feedback until a
termination condition is met.
Common agentic patterns
On-device agentic workflows are optimized for focused, deterministic reasoning loops where user intent is translated into structured app actions. Common patterns include:
Pattern |
Example |
In-app action execution and shortcuts |
Translating natural language requests into specific app commands, such as applying photo adjustments on an editing canvas, modifying playback settings, or toggling app preferences. |
Structured lookup and local calculation |
Fetching a specific record by ID (such as an order status or account balance) and performing multi-step mathematical calculations (such as loan amortizations or fitness metrics). |
Conversational filtering and curation |
Interactively querying and refining local app items, such as searching through a local task list, filtering a playlist, or sorting catalog items based on user criteria. |
Guided multi-step input |
Guiding users through structured data entry step-by-step, validating intermediate inputs with local tools before final submission. |
On-device performance and privacy
Agentic workflows run on Android AICore to deliver private, responsive execution directly on the user's device:
- Local reasoning and prompt privacy: The model reasoning and planning loop executes entirely on-device with zero network latency. User prompt data remains private to the device. However, individual tools implemented in your app can still make network calls or query cloud APIs if your use case requires external data.
- Managed multi-turn sessions: The
AgentSessioninterface maintains in-memory conversation history across turns so you don't have to manage transcripts manually. You can reclaim memory at any time using thesession.close(),deleteSession(sessionId), orclearAllSessions()methods. - Execution guardrails: Agent configurations enforce a maximum turn limit
(the
maxTurnslimit, defaulting to 10) as a resource termination condition to prevent runaway execution loops, conserve battery, and protect device responsiveness.
Choose between custom generation, agents, and task-specific APIs
ML Kit organizes on-device GenAI capabilities by how much customization and orchestration your feature needs:
- Custom generation and agents: Work directly with the Gemini Nano
foundation model when your feature requires custom instructions or
domain-specific logic. Choose agentic workflows (using the
AgentRunnerclass, built on top of theGenerativeModelclass) when you want managed multi-turn sessions and automated tool-calling loops, or choose direct model access (using theGenerativeModelclass) for custom prompting, typed structured output, or client-managed multi-turn history. - Speech and audio: Use dedicated speech and GenAI models (such as Speech recognition) to transcribe spoken audio to text.
- Text and image tasks: Use pre-configured, task-specific feature types and fine-tuned LoRA adapters on top of the shared base model (such as Image description, Summarization, Proofreading, and Rewriting) for turnkey vision and writing use cases without prompt engineering.
The following table outlines how these approaches compare:
Consideration |
Agentic workflows ( |
Direct model access ( |
Text and image task APIs |
Architecture |
High-level orchestration layer built on top of
|
Direct interface to the Gemini Nano foundation model for custom prompts. |
Task-specific feature types backed by fine-tuned LoRA adapters on top of the shared base model. |
Multi-turn context |
Managed multi-turn sessions ( |
Client-managed multi-turn context.
|
Stateless, single-input task calls. |
Tool calling and actions |
Automated tool-calling loop. Discovers registered Android AppFunctions, executes model-selected calls, and feeds results back into the model automatically. |
Client-managed tool declarations.
|
Not applicable (fixed task pipeline). |
When to use |
Use when you want automated orchestration for multi-step tool execution and managed in-memory multi-turn sessions. |
Use for custom prompting, multimodal image
understanding, typed structured output ( |
Use when your feature matches a standard writing or vision task and you want out-of-the-box quality from fine-tuned LoRAs with minimal setup. |
Next steps
- To set up your project and build your first agent, see Get started with agentic workflows.
- To learn how to expose in-app functions to the agent, see Define tools.
- To manage multi-turn sessions and memory across Android lifecycles, see Manage sessions and lifecycle.
- To collect streaming responses and update your UI, see Stream events and UI integration.