The Shift to On-Device Intelligence

Mobile AI is moving beyond simple chat completions. With models like Gemini Nano now available on over 140 million devices, there's a growing opportunity to build intelligent apps that are private, responsive, and cost-effective. However, orchestrating complex AI workflows—especially those that need to balance cloud reasoning with on-device data—has been a significant engineering challenge.

Google's answer is the Agent Development Kit (ADK) for Kotlin. This new open-source framework (version 0.1.0) is designed to simplify the creation of AI agents that can run directly on Android hardware. The key innovation is its hybrid nature: you can build a single agent system that leverages a powerful cloud model for reasoning, while delegating tasks that require access to sensitive local data to on-device subagents.

This guide will walk you through the core concepts and code needed to start building your own hybrid agents. We'll cover setup, tool creation, and orchestration, providing you with a practical foundation for your next project.

Developer building an AI agent on a smartphone using ADK for Android with Gemini Nano Algorithm Concept Visual

Setting Up Your Project

To get started, you'll need to add the ADK for Android dependency to your app's build.gradle.kts file. This library includes all the core components for building and running agents on-device.

// build.gradle.kts
implementation("com.google.adk:google-adk-kotlin-core-android:0.1.0")

Now, let's explore how to build a simple agent. The following example creates an orchestrator agent that uses a cloud model to understand a user's travel needs and then delegates document verification to an on-device subagent for privacy.

import com.google.adk.agents.LlmAgent
import com.google.adk.models.Gemini

// Assume this tool retrieves trip details from a local database
class GetTripDetailsTool(private val tripId: String) {
    fun execute(): String {
        // Simulate fetching details
        return "Flight at 10:00 AM, Hotel: Grand Plaza"
    }
}

suspend fun main() {
    val apiKey = "YOUR_GEMINI_API_KEY"
    val MODEL_NAME = "gemini-2.5-flash"

    // 1. Define a subagent that runs on-device (e.g., using Gemini Nano)
    val onDeviceVerifier = LlmAgent(
        name = "DocumentVerifier",
        description = "Verifies booking confirmations using local documents.",
        model = Gemini(apiKey = apiKey, name = "gemini-nano"), // On-device model
        instruction = Instruction(
            """
            You are a verification agent. You have access to the user's local documents.
            When asked to verify a booking, extract the confirmation code and return it.
            """.trimIndent()
        ),
        tools = listOf(LocalDocumentSearchTool()) // Hypothetical tool
    )

    // 2. Define the main cloud orchestrator
    val orchestrator = LlmAgent(
        name = "TravelAssistant",
        model = Gemini(apiKey = apiKey, name = MODEL_NAME),
        instruction = Instruction(
            """
            You are a helpful travel assistant. 
            First, use `get_trip_details` to understand the user's itinerary.
            If the user needs to verify a booking, transfer the task to `DocumentVerifier`.
            """.trimIndent()
        ),
        tools = listOf(GetTripDetailsTool("trip-123")), // Example tool
        subAgents = listOf(onDeviceVerifier)
    )

    // 3. Run a query
    val response = orchestrator.execute("I need to verify my hotel booking for tonight.")
    println(response)
}

This code demonstrates the core pattern: a cloud-based agent (TravelAssistant) manages the conversation, but for a specific task (verification), it hands off control to an on-device subagent (DocumentVerifier). This keeps sensitive data like booking confirmations on the device.

Kotlin code editor showing ADK agent configuration with cloud and on-device model orchestration Development Concept Image

Defining Tools with Annotations

ADK for Kotlin simplifies tool creation with a clean annotation-based approach. You can turn any Kotlin class into a set of tools for your agent by using the @Tool and @Param annotations, which provide the LLM with the necessary metadata to invoke your functions.

Here’s an example inspired by The Hitchhiker's Guide to the Galaxy:

import com.google.adk.tools.Tool
import com.google.adk.tools.Param

class ImprobabilityDriveService {
    /** Calculates the improbability of a given event. */
    @Tool
    fun calculateImprobability(
        @Param("The event to calculate the improbability for, e.g., 'A cup of tea materializing'")
        event: String
    ): String {
        return "The improbability of '$event' is approximately 42 to 1 against."
    }
}

// In your agent setup:
val heartOfGoldAgent = LlmAgent(
    name = "HeartOfGold",
    model = Gemini(apiKey = apiKey, name = "gemini-2.5-flash"),
    instruction = Instruction("You are the ship computer. Be witty and helpful."),
    tools = ImprobabilityDriveService().generatedTools() // Generates tool definitions
)

This approach keeps your code clean and type-safe. The generatedTools() function automatically converts your annotated methods into a format the LLM can understand and call.

Hybrid AI architecture diagram showing cloud orchestrator connecting to on-device subagents on Android System Abstract Visual

Conclusion: The Future of In-App AI

The ADK for Kotlin is a significant step forward for Android developers. It abstracts away the complex orchestration, context management, and error handling required for building robust agentic systems. By enabling seamless communication between cloud and on-device models, it allows you to create experiences that are both intelligent and private.

Key Takeaways & Limitations:

  • Privacy: The hybrid model is a game-changer for apps handling sensitive data. You can keep personal information on-device while still leveraging cloud reasoning.
  • Experimental: As a 0.1.0 release, this is an experimental API. Expect changes and potential breaking updates as the library evolves.
  • Model Availability: The performance of on-device agents depends on the hardware and the specific model (e.g., Gemini Nano) availability on the target user's device.

Next Steps for Learning:

  1. Explore the Demos: Check out the official ADK for Android demos on GitHub to see more complex agent setups, including multi-agent routing and tool integrations.
  2. Deepen Your Agent Knowledge: For a broader look at building production-grade agents, explore how advanced models are pushing performance boundaries. This analysis of a hybrid SSM model offers insights into maximizing throughput.
  3. Optimize Your Stack: Efficient agents often rely on smart data and model choices. Learn from other engineering teams, like how Meta uses Bayesian optimization for complex design tasks, to inspire your own problem-solving.

Start experimenting with ADK for Kotlin today. The ability to build powerful, private, and responsive AI agents is now in your hands.

This content was drafted using AI tools based on reliable sources, and has been reviewed by our editorial team before publication. It is not intended to replace professional advice.