ADK for Kotlin 为你的后端项目带来了智能体工作流,而 ADK for Android 则提供了专门的设备端优化能力。
继近期 ADK for Java 和 Go 的 1.0.0 版本,以及 ADK for Python 2.0 的测试版发布之后,我们激动地宣布推出 Kotlin 版智能体开发套件(ADK)0.1.0 版本!此外,我们还推出了一款名为 ADK for Android 的专用库。ADK 是一个用于开发和运行 AI 智能体的灵活开源框架,现在已支持 Kotlin。借助 Android 版本,你可以创建能够在设备端直接运行的 AI 智能体,利用本地设备端大语言模型在你的应用中工作,从而增强隐私保护,同时也能灵活地与云端模型进行桥接。
为什么选择 ADK for Kotlin?
自 Gemini Nano 作为 Android 端模型推出以来,AI 生态系统正经历着向边缘端的大规模迁移,该模型现已覆盖超过 1.4 亿台设备。随着开发者寻求构建更快、更具成本效益且更能保护隐私的应用,直接在移动硬件上运行 AI 模型(如 Gemini Nano 这类模型)的能力变得前所未有的重要。然而,构建智能体系统可能非常复杂,尤其是在协调云端与边缘端之间的任务时。ADK 通过为你管理所有复杂的编排、上下文处理和错误处理,消除了这一障碍。
只需几行 Kotlin 代码,你就可以:
- 根据需求轻松切换模型
- 在多智能体系统的不同部分,灵活选择各种设备端和云端模型
- 在多个智能体之间无缝共享会话状态
- 直接在 Android 设备上运行智能体
功能亮点
- 混合编排:你可以使用云端模型作为主编排器,然后将特定任务卸载给完全在设备端运行的子智能体。ADK 库负责将通用的智能体实现适配到正确的云端或设备端 API。
- 设备端顺序智能体:你可以将子智能体定义为顺序智能体,这非常适合需要依次运行的多个任务。
- 本地检索:通过利用 Gemini Nano 等设备端模型,你可以创建能够访问和解析本地文档的检索智能体,从而确保数据无需离开硬件。
- 灵活的工具集成:你可以为智能体配备特定工具,并提供顶层指令,使其确切了解应如何行动以及何时将任务委派给子智能体。
实际案例:旅行助手
在我们的 I/O 大会环节中,我们展示了 ADK for Kotlin 如何为应用内旅行助手提供支持。
当用户在旅途中遇到问题时,云端编排器会与用户交互以了解问题。然而,当需要核实预订确认信息时,它会将任务委派给设备端的子智能体。多个检索智能体利用设备端的 Gemini Nano 模型,从用户本地存储的文档中提取数据。最后,一个验证智能体会对这些分析得出的数据进行比对。这样既能将私有数据保持在离线状态,又能充分利用云端编排器的推理能力。
ADK for Android 入门
要将 ADK 添加到你的 Android 应用中,请在 `build.gradle.kts` 文件中添加以下依赖:
implementation("com.google.adk:google-adk-kotlin-core-android:0.1.0") Kotlin
然后,你就可以轻松构建你的 ADK 智能体:
val orchestrator = LlmAgent(
name = "genius_orchestrator",
model = Gemini(apiKey = apiKey, name = MODEL_NAME),
instruction = Instruction("""
You are a travel genius assistant.
First, use `get_trip_details` to get the full itinerary of the trip and
understand what events are scheduled.
Then, respond with a welcome message tailored to the trip state.
""".trimIndent()),
tools = listOf(GetTripDetailsTool(tripId)),
subAgents = listOf(carRentalPipeline, hotelPipeline),
disallowTransferToPeers = true,
disallowTransferToParent = true,
) Kotlin
如需更复杂的智能体配置,请查看 ADK for Android 演示示例。
ADK for Kotlin 入门
在你的 `build.gradle.kts` 文件中,添加以下依赖:
dependencies {
// Implementation dependency for ADK Core
implementation("com.google.adk:google-adk-kotlin-core:0.1.0")
// KSP processor for generating @AdkTools
ksp("com.google.adk:google-adk-kotlin-processor:0.1.0")
} Kotlin
ADK for Kotlin 允许你定义工具,为大语言模型赋予额外能力。让我们创建一个虚构的“无限非概率驱动”服务,灵感来自《银河系漫游指南》:
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."
}
} Kotlin
请注意使用 `@Tool` 和 `@Param` 注解来向大语言模型描述该工具。
现在,我们可以创建第一个智能体,它将成为我们稍后定义的主智能体的子智能体。`HeartOfGold` 智能体代表飞船的计算机:
val heartOfGoldAgent =
LlmAgent(
name = "HeartOfGold",
description = "The Heart of Gold ship computer. Handles improbability drive queries.",
model = Gemini(apiKey = apiKey, name = "gemini-2.5-flash"),
instruction =
Instruction(
"""
You are the ship computer of the Heart of Gold. You are cheerful, helpful, and slightly annoying.
You have access to the Infinite Improbability Drive.
Use real facts about yourself if asked, but keep it funny.
"""
.trimIndent()
),
tools = ImprobabilityDriveService().generatedTools()
) Kotlin
现在,我们可以在根智能体中使用这个子智能体:
val rootAgent =
LlmAgent(
name = "MissionControl",
description = "The central router for space queries. Routes to HeartOfGold.",
subAgents = listOf(heartOfGoldAgent),
model = Gemini(apiKey = apiKey, name = "gemini-2.5-flash"),
instruction =
Instruction(
"""
You are Mission Control. You are the central hub for all communications.
Your main job is to route the user's query to the most appropriate agent.
- If the query is about improbability, the Infinite Improbability Drive, or the Heart of Gold, transfer to `HeartOfGold`.
- Otherwise, respond directly with a professional but stressed persona.
"""
.trimIndent()
)
) Kotlin
`heartOfGoldAgent` 在此主智能体的智能体配置中被定义为一个子智能体。
当用户询问某个奇怪事件发生的可能性时,主智能体会将任务委派给 `heartOfGoldAgent`,后者会调用本地函数工具来计算概率,然后回复用户。
这是一个简单示例,展示了如何在 ADK for Kotlin 中定义工具和子智能体。
ADK 功能集
ADK for Kotlin 和 ADK for Android 0.1.0 版本包含了在 Android 及更广泛平台上构建 AI 智能体所需的基础功能集,包括对智能体执行的高级控制、全面的工具支持以及用于状态管理的基本服务。
智能体
- 基于大语言模型、基于工作流、自定义智能体
- 多智能体系统
工具与集成
- 函数工具
- 长时间运行的函数工具
- MCP 工具
- A2A
- 插件
运行时与可观测性
- 用于短期记忆的会话状态
- 用于长期记忆的记忆服务
- 遥测(OpenTelemetry)
开发者体验
- 用于开发和实验的 Web 界面
Android 模型
- ML Kit GenAI,通过 AICore 访问设备端 Gemini Nano
- Firebase AI Logic,用于访问云端运行的 Gemini 模型
- Google GenAI,用于快速原型开发
下一步计划?
这个 0.1 版本是我们对该库的第一个实验性版本,目前提供了针对 ML Kit GenAI API 的默认智能体,以及到云端 Gemini 的直接连接。但这仅仅是个开始!
我们对应用内 AI 的未来感到无比兴奋,并迫不及待地想看到你们构建的智能体验。请务必在 GitHub 上查看该项目!
- 移动端
- AI
- 云
- 公告
- 学习
- 探索
ADK for Kotlin brings agentic workflows to your backend projects, while ADK for Android provides specialized on-device optimizations
Following the recent 1.0.0 releases of ADK for Java and Go, as well as the beta of ADK for Python 2.0, we are thrilled to announce the launch of version 0.1.0 of Agent Development Kit (ADK) for Kotlin! In addition, we're also launching an additional specialized library called ADK for Android. ADK is a flexible and open-source framework for developing and running AI agents, and is now available in Kotlin. With the Android version you can create AI agents that can operate on-device directly within your apps with local on-device LLMs, enhancing privacy, but with the flexibility to bridge the gap with cloud-based models.
Why ADK for Kotlin?
The AI ecosystem is experiencing a massive shift toward the edge, since the introduction of Gemini Nano as a model on Android, it has become available on over 140 million devices. As developers look to build faster, more cost-effective, and privacy-enhancing applications, the ability to run AI models directly on mobile hardware (models like Gemini Nano) has never been more critical. However, building agentic systems can be complex, especially when coordinating tasks between the cloud and the edge. ADK removes that friction by managing all the complex orchestration, context handling, and error handling for you.
With just a few lines of Kotlin, you can:
- Easily swap out models depending on your needs
- Choose between various on-device and cloud models for different parts of your multi-agent system
- Seamlessly share session state between multiple agents
- Run agents directly on Android devices
Feature Highlights
- Hybrid Orchestration: You can use a cloud model as your main orchestrator, which can then offload specific tasks to sub-agents that run fully on-device. The ADK library takes care of adapting generic agent implementations to the correct cloud or on-device APIs.
- On-Device Sequential Agents: You can define sub-agents as sequential agents, perfect for multiple tasks that need to run one after the other.
- Local Retrieval: By utilizing on-device models like Gemini Nano, you can create retrieval agents that access and parse documents locally, ensuring data never has to leave the hardware.
- Flexible Tooling: You can equip your agents with specific tools and provide top-level instructions so they know exactly how to behave and when to delegate to subagents.
Real-World Example: The Trip Assistant
During our I/O session, we showcased how ADK for Kotlin powers an in-app trip assistant.
If a user encounters an issue while traveling, the cloud-based orchestrator interacts with the user to understand the problem. However, when it needs to verify a booking confirmation, it delegates the task to an on-device subagent. Various retrieval agents use the on-device Gemini Nano model to extract data from the user's locally stored documents. Finally, a validation agent compares the data coming from these analyses. This keeps private data offline while leveraging the reasoning capabilities of the cloud orchestrator.
Getting started with ADK for Android
To add ADK to your Android app, add the following dependency to your build.gradle.kts file:
implementation("com.google.adk:google-adk-kotlin-core-android:0.1.0") Kotlin
You can then easily build your ADK agents:
val orchestrator = LlmAgent(
name = "genius_orchestrator",
model = Gemini(apiKey = apiKey, name = MODEL_NAME),
instruction = Instruction("""
You are a travel genius assistant.
First, use `get_trip_details` to get the full itinerary of the trip and
understand what events are scheduled.
Then, respond with a welcome message tailored to the trip state.
""".trimIndent()),
tools = listOf(GetTripDetailsTool(tripId)),
subAgents = listOf(carRentalPipeline, hotelPipeline),
disallowTransferToPeers = true,
disallowTransferToParent = true,
) Kotlin
For more extended agent setups, check out the ADK for Android demos.
Getting Started with ADK for Kotlin
In your build.gradle.kts file, add the following dependencies:
dependencies {
// Implementation dependency for ADK Core
implementation("com.google.adk:google-adk-kotlin-core:0.1.0")
// KSP processor for generating @AdkTools
ksp("com.google.adk:google-adk-kotlin-processor:0.1.0")
} Kotlin
ADK for Kotlin lets you define tools to equip the LLM with extra powers. Let’s create an imagined “improbability drive” service, inspired from the Hitchhiker’s Guide to the Galaxy:
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."
}
} Kotlin
Notice the use of the @Tool and @Param annotations to describe the tool to the LLM.
Now, we can create a first agent, which will be the sub-agent of a main agent we’ll define later on. The HeartOfGold agent represents the spaceship’s computer:
val heartOfGoldAgent =
LlmAgent(
name = "HeartOfGold",
description = "The Heart of Gold ship computer. Handles improbability drive queries.",
model = Gemini(apiKey = apiKey, name = "gemini-2.5-flash"),
instruction =
Instruction(
"""
You are the ship computer of the Heart of Gold. You are cheerful, helpful, and slightly annoying.
You have access to the Infinite Improbability Drive.
Use real facts about yourself if asked, but keep it funny.
"""
.trimIndent()
),
tools = ImprobabilityDriveService().generatedTools()
) Kotlin
Now we can use this sub-agent in our root agent:
val rootAgent =
LlmAgent(
name = "MissionControl",
description = "The central router for space queries. Routes to HeartOfGold.",
subAgents = listOf(heartOfGoldAgent),
model = Gemini(apiKey = apiKey, name = "gemini-2.5-flash"),
instruction =
Instruction(
"""
You are Mission Control. You are the central hub for all communications.
Your main job is to route the user's query to the most appropriate agent.
- If the query is about improbability, the Infinite Improbability Drive, or the Heart of Gold, transfer to `HeartOfGold`.
- Otherwise, respond directly with a professional but stressed persona.
"""
.trimIndent()
)
) Kotlin
The heartOfGoldAgent is defined as a subagent in the agent configuration of this main agent.
When the user asks questions about the improbability of an odd event to happen, the main agent delegates the task to the heartOfGoldAgent, which in turn will call the local function tool to calculate the probability, before replying to the user.
This is a simple example of how you can define tools and sub agents in ADK for Kotlin.
ADK feature set
The ADK for Kotlin & ADK for Android 0.1.0 releases contain the foundational feature set required for building AI agents on Android and beyond, including advanced control over agent execution, comprehensive tooling, and essential services for state management.
Agents
Tooling & Integrations
Runtime & Observability
- Session state for short-term memory,
- Memory service for long-term memory
- Telemetry (OpenTelemetry)
Developer Experience
- Web interface for development and experimentation
Android Models
- ML Kit GenAI to access on-device Gemini Nano via AICore
- Firebase AI Logic to access Gemini models running in the cloud
- Google GenAI for quick prototyping
What's Next?
This 0.1 release is our first experimental version of the library, currently featuring default agents for the ML Kit GenAI APIs and direct connections to Gemini in the Cloud. But we are just getting started!
We are incredibly excited about the future of in-app AI and can’t wait to see the intelligent experiences you build. Be sure to check out the project on GitHub!