Announcing ADK for Kotlin 1.0: Building Production-Ready AI Agents in Kotlin, Android, and Beyond
TL;DR · AI 摘要
ADK for Kotlin 1.0发布,提供生产级AI代理开发工具,集成Android原生功能与VertexAI企业平台。
核心要点
- ADK 1.0支持Android原生功能,包括LiteRT-LM、ML Kit(beta)和Firebase AI Logic。
- 新版本实现与ADK Python/Java核心功能完全一致,支持多代理系统和上下文压缩。
- 集成VertexAI平台,支持企业级AI代理开发,提供VertexAiSessionService等服务。
结构提纲
按章节快速跳转。
思维导图
用一张图看清主题之间的关系。
查看大纲文本(无障碍 / 无 JS 友好)
- ADK for Kotlin 1.0
- 核心功能
- 多代理系统
- 上下文压缩
- 人机协作流程
- Android扩展
- LiteRT-LM
- ML Kit (beta)
- Firebase AI Logic
- VertexAI集成
- VertexAiSessionService
- VertexAiRagMemoryService
金句 / Highlights
值得收藏与分享的关键句。
ADK for Kotlin 1.0 delivers complete alignment with ADK Python and Java, bringing advanced multi-agent coordination patterns to idiomatic Kotlin.
LiteRT-LM and ML Kit (beta) enable fast, private on-device agents, while Firebase AI Logic orchestrates hybrid cloud workflows.
Enterprise Agent Platform (VertexAI) integration provides VertexAiSessionService, VertexAiRagMemoryService, and VertexAiMemoryBankService.
宣布 Kotlin 的 ADK 1.0 版本:使用 Kotlin、Android 及其他平台构建生产就绪的 AI 代理 - Google 开发者博客
Google Tag Manager (noscript)
结束 Google Tag Manager (noscript)
HTML
宣布 Kotlin 的 ADK 1.0 版本:使用 Kotlin、Android 及其他平台构建生产就绪的 AI 代理
2026 年 9 月 9 日
Guillaume Laforge
开发者倡导者
分享
- 邮件
今天,我们非常高兴地宣布 Kotlin 代理开发工具包(ADK)1.0 版本正式发布!立即查看 GitHub 仓库,深入代码并构建你的第一个代理,同时探索相关文档。
当我们最初推出 Kotlin 的 ADK 0.1.0 版本时,我们的目标是为 Kotlin、Java 和 Android 开发者提供符合语言习惯、轻量且可组合的 AI 代理开发方式。在过去几个月中,我们致力于将该框架发展为一个适用于生产环境的工具包。
随着 1.0 版本的发布,Kotlin 的 ADK 在功能上与 ADK 1.0 核心完全一致,同时提供了丰富的面向 Android 的设备端扩展功能。无论你是希望使用 LiteRT-LM 和 ML Kit(测试版)运行快速且私密的设备端代理,还是通过 Firebase AI Logic 协调混合云工作流,或使用 Room 和 AppSearch 在进程重启后持久化代理状态,Kotlin 的 ADK 1.0 都能为你提供所需的一切。
尽管 Kotlin 的 ADK 主要面向 Android,但后端 Kotlin 开发者也可以使用符合语言习惯的 Kotlin 代码创建企业级代理和智能应用。
🚀 Kotlin 的 ADK 1.0 新增功能
Kotlin 的 ADK 基于 Kotlin 多平台(KMP)核心构建,该核心完全独立于特定模型后端、会话提供者或内存系统。1.0 版本结合了本地和云端场景的完整多代理编排功能,以及面向移动设备开发者的即插即用 Android 扩展。
与 ADK 1.0 核心功能完全一致
Kotlin 的 ADK 1.0 与 ADK Python 和 Java 完全对齐,为符合语言习惯的 Kotlin 带来了高级多代理协调模式:
- 分层多代理系统:将代理串联并委派任务给专门的子代理。
- 上下文压缩与多轮对话:通过总结历史记录来管理上下文,以保持在令牌限制范围内。
- 人机协作(HITL)与确认流程:暂停执行,请求用户对敏感操作进行确认,然后恢复执行。
- 长期运行与基于注解的工具:使用 @Tool 和 @Param 注解自动为 Kotlin 编写的工具生成模式。
- 会话可恢复性:在用户会话之间暂停、序列化并恢复活动代理交互。
- 与 Java 的原生互操作性:直接从现有 Java 应用程序调用 Kotlin 的 ADK 代理。
- 企业代理平台(VertexAI)集成:VertexAiSessionService、VertexAiRagMemoryService、VertexAiMemoryBankService。
⛑️ 数据库事件响应代理示例
让我们试用 Kotlin 的 ADK 1.0,构建一个用于调查生产数据库警报的事件分类与诊断代理。我们的代理将利用 ADK 的函数调用和代理技能功能:
- 工具(@Tool):可执行的、类型安全的功能(调用 API、查询指标、执行操作)。
- 技能(SkillToolset):通过渐进式披露(SKILL.md、检查表、模板)动态加载的按需过程知识和领域操作手册。
ADK 利用 KSP(Kotlin 符号处理)在编译时生成函数调用定义,为您提供类型安全的模式、对挂起函数的支持,以及零运行时反射。
您使用常规的 Kotlin 数据类来定义服务:
data class ServiceMetrics(
val serviceName: String,
val cpuUsagePercent: Double,
val connectionPoolUsagePercent: Double,
val activeConnections: Int,
val maxConnections: Int,
val p99LatencyMs: Int,
val errorRatePercent: Double,
)
data class DeploymentInfo(
val deploymentId: String,
val serviceName: String,
val gitCommit: String,
val author: String,
val deployedMinutesAgo: Int,
val description: String,
)Kotlin
已复制
以及使用 @Tool 和 @Param 注解的函数:
class InfrastructureDiagnosticsService {
@Tool
suspend fun getServiceMetrics(
@Param("Target service or database cluster") serviceName: String,
@Param("Time window in minutes") windowMinutes: Int? = 15,
): ServiceMetrics {
// Query monitoring backends (Datadog, Prometheus, Cloud Monitoring)
return ServiceMetrics(
serviceName = serviceName,
cpuUsagePercent = 91.4,
connectionPoolUsagePercent = 98.5,
activeConnections = 492,
maxConnections = 500,
p99LatencyMs = 2450,
errorRatePercent = 4.2,
)
}
@Tool
fun fetchRecentDeployments(
@Param("Target service identifier") serviceName: String
): List<DeploymentInfo> {
return listOf(
DeploymentInfo(
deploymentId = "deploy-9842",
serviceName = serviceName,
gitCommit = "a1b2c3d",
author = "[email protected]",
deployedMinutesAgo = 25,
description = "Add unindexed batch query to user profile sync job",
)
)
}
@Tool
fun notifyOnCall(
@Param("Channel to notify, e.g. '#production-alerts'") channel: String,
@Param("Diagnostic summary message") message: String,
@Param("Severity: INFO, WARNING, CRITICAL") severity: String? = "WARNING",
): String {
println(">>> [CHAT-OPS] Broadcasting [$severity] to $channel: $message")
return "Notification posted successfully."
}
}在构建时,KSP 会自动生成扩展函数 InfrastructureDiagnosticsService().generatedTools() 。
不要在代码中硬编码应急处理指南,而是将标准操作流程放在 src/main/resources/skills/database-incident-triage/SKILL.md 中:
---
name: database-incident-triage
description: Standard operating procedure for diagnosing database latency spikes and connection pool saturation.
allowed-tools: [getServiceMetrics, fetchRecentDeployments, notifyOnCall]
---
# Database Incident Triage SOP
1. **Telemetry**: Call `getServiceMetrics` to inspect CPU, latency, and pool saturation.
2. **Correlation**: Call `fetchRecentDeployments` to check for recent code/schema changes.
3. **Safety Rules**: Inspect `assets/mitigation_rules.txt` with `load_skill_resource` before taking action. Never restart primary nodes during peak hours.
4. **Notify**: Broadcast root-cause diagnosis to `#production-alerts` with `notifyOnCall`.纯文本
技能可以捆绑辅助资产(例如 assets/mitigation_rules.txt),模型仅在需要时才会获取这些资产,从而将令牌使用量降至最低——这被称为渐进式披露机制。
现在,让我们以声明式方式为代理配备工具和技能:
object IncidentTriageDemoAgent {
val rootAgent = LlmAgent(
name = "incident_triage_agent",
model = Gemini(name = "gemini-3.8-flash"),
instruction = Instruction(
"""
你是一个SRE值班诊断助手。
当收到警报时:
1. 发现可用的故障排除方案并使用 `load_skill` 加载匹配的标准操作流程(SOP)。
2. 严格遵循方案步骤,必要时加载技能资源。
3. 使用诊断工具检查遥测数据并通知团队。
""".trimIndent()
),
// 1. 编译时生成的函数工具(零反射)
tools = InfrastructureDiagnosticsService().generatedTools(),
// 2. 动态技能工具集(提供 list_skills, load_skill, load_skill_resource)
toolsets = listOf(SkillToolset(NewFileSystemSource(resolveSkillsDir()))),
)
}准备好代理后,让我们使用 Kotlin 协程和 InMemoryRunner 来执行它:
fun main() = runBlocking {
val runner = InMemoryRunner(
agent = IncidentTriageDemoAgent.rootAgent,
appName = "IncidentTriageApp"
)
val alert = "ALERT [P1]: 在 'users-postgres-cluster' 上检测到数据库延迟激增! "
+ "活动连接激增且查询超时。"
val events = runner.runAsync(
userId = "oncall-sre",
sessionId = UUID.randomUUID().toString(),
newMessage = Content.fromText(Role.USER, alert)
).toList()
for (event in events) {
event.content?.parts?.firstOrNull()?.text?.let { println("Agent: $it") }
}
}当警报触发时,代理会以结构化的方式自主执行:
- 发现并加载数据库-事件-故障排除技能及其安全防护措施。
- 调用 getServiceMetrics() → 识别出 98.5% 的连接池饱和度。
- 调用 fetchRecentDeployments() → 确定 deploy-9842("添加未索引的批量查询..." 25 分钟前)为根本原因。
- 在 #production-alerts 频道发布更新,并提供后续故障排除报告,建议立即回滚。
📱 以 Android 为先的设备端扩展
在完成这个服务器端生产代理后,让我们回到 ADK for Kotlin 的移动功能。现代移动 AI 需要平衡云端推理能力和设备端隐私、速度和离线可靠性。ADK for Kotlin 1.0 为标准 Android 架构组件引入了模块化实现:
表 1:ADK for Kotlin 1.0 的 Android 优先和设备端扩展。
💻 Android 示例:财务助手
让我们看看 ADK for Kotlin 如何集成到生产 Android 应用中。在以下示例中,我们构建了一个由 Gemini 3.8 Flash 驱动的财务助手,通过 Firebase AI 实现。它使用 KSP 生成的函数调用来处理需要用户明确批准的敏感交易,同时充分利用 Android 的一流持久化服务,如将聊天会话存储在 Room 中,在 AppSearch 中进行索引内存,并将文件直接存储在 Android 存储中:
首先定义需要人工确认的银行转账工具:
// 1. 需要人工确认的敏感工具
class BankTransferTools {
@Tool(
name = "transferFunds",
description = "向其他账户转账。需要用户明确授权",
requireConfirmation = true
)
fun transferFunds(
@Param("收款账户ID") recipientId: String,
@Param("金额(美元)") amount: Double
): String {
println(">>> [BANKING CORE] 正在执行向 $recipientId 转账 \$${amount}...")
return "已成功安排向 $recipientId 转账 \$${amount}。参考号:TX-${System.currentTimeMillis()}"
}
}以下是使用 Firebase AI 的 Gemini 3.8 Flash 配置代理,并配置我们刚刚定义的工具的方式:
// 2. 使用 Firebase AI(Gemini 3.8 Flash)定义代理
fun createFinancialAgent(): LlmAgent {
val firebaseAi = FirebaseAI.getInstance(FirebaseApp.getInstance())
return LlmAgent(
name = "FinancialAgent",
description = "处理银行查询和资金转账安排",
model = Firebase.create("gemini-3.8-flash", firebaseAi),
instruction = Instruction(
"你是一个安全的银行助手。帮助用户管理账户并进行资金转账"
),
tools = BankTransferTools().generatedTools()
)
}我们使用 Room 作为会话服务后端,使用 AppSearch 作为内存服务,配置 InMemoryRunner:
// 3. 使用持久化安卓存储服务配置 Runner
fun createAndroidRunner(applicationContext: Context, agent: LlmAgent): InMemoryRunner {
return InMemoryRunner(
agent = agent,
appName = "AndroidFinancialApp",
// 使用 SQLite 持久化存储跨重启/进程终止的聊天记录
sessionService = RoomSessionService.fromContext(applicationContext),
// 使用 AndroidX AppSearch 进行设备端全文索引的内存服务
memoryService = AppSearchMemoryService.fromContext(applicationContext),
// 用于生成的声明/收据的私有文件存储
artifactService = FileArtifactService.fromExternalFilesDir(applicationContext)
)
}现在运行代理,进行两次交互:第一次请求转账,第二次通过人工确认完成转账:
// 4. 多轮人机协作执行
suspend fun runFinancialDemo(runner: InMemoryRunner) {
val userId = "user-123"
val sessionId = "session-${UUID.randomUUID()}"
suspend fun sendTurn(message: Content): List<Event> {
val events = runner.runAsync(userId = userId, sessionId = sessionId, newMessage = message).toList()
for (event in events) {
event.content?.parts?.firstOrNull()?.text?.let { println("Agent: $it") }
}
return events
}
// --- 第1轮:用户请求转账(智能体暂停执行)
println("User: 请将50美元转入账户ACCT-9876。\n")
val turn1Events = sendTurn(
Content.fromText(Role.USER, "Please transfer $50 to account ACCT-9876."))
// 拦截ADK发出的合成确认请求
val confirmationRequestId = turn1Events
.flatMap { it.functionCalls() }
.firstOrNull { it.name == FunctionCall.REQUEST_CONFIRMATION_FUNCTION_CALL_NAME }
?.id ?: return
println("\n[UI]: 检测到敏感操作。用户点击了[确认转账]。\n")
// --- 第2轮:用户在安卓UI中确认(恢复并执行转账)
val approvalMessage = Content(
role = Role.USER,
parts = listOf(
Part(
functionResponse = FunctionResponse(
name = FunctionCall.REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
id = confirmationRequestId,
response = mapOf(ToolConfirmation.CONFIRMED_KEY to true)
)
)
)
)
sendTurn(approvalMessage)
}Note: 本示例仅用于演示目的,未设计满足任何合规要求。
📊 ADK for Kotlin特性对比 — 核心与安卓
表2: ADK for Kotlin特性在核心(服务器)与安卓平台的对比。
📦 入门指南
要开始使用ADK for Kotlin 1.0,请将必要的依赖项添加到模块的build.gradle.kts文件中:
dependencies {
// ADK Kotlin核心引擎 + KSP处理器
implementation("com.google.adk:google-adk-kotlin-core:1.0.0")
ksp("com.google.adk:google-adk-kotlin-processor:1.0.0")
// 可选安卓优先扩展:
implementation("com.google.adk:google-adk-kotlin-mlkit-android:1.0.0-beta")
implementation("com.google.adk:google-adk-kotlin-litertlm:1.0.0")
implementation("com.google.adk:google-adk-kotlin-firebase-android:1.0.0")
}🔗 资源与文档
探索仓库,查看示例应用,开始构建您的多智能体体验:
- 🎬 ADK文档和入门指南:adk.dev
- 📖 GitHub仓库:github.com/google/adk-kotlin
- 🧩 模块化架构指南:ADK Kotlin模块文档
- 📱 本地设备与云端指南:使用ADK构建安卓智能体
- 🛠️ 特性展示:所有Kotlin示例
- ☕ Java互操作示例:ADK Kotlin Java示例
无论您是在JVM服务器端还是安卓移动设备上开发智能体,我们都期待看到您如何利用ADK for Kotlin!请收藏该仓库,尝试示例代码,并与我们分享您的反馈!
发布于:
- 移动端
- AI
- 云端
- 公告
- 解决方案
上一篇
下一篇
相关文章
列表
AI
公告
学习
为什么客户端SDK生成应该开源
2026年9月17日
移动端
网页端
案例研究
社区
弥合领域鸿沟:基于Antigravity和Gemini构建的AI赛跑教练
2026年7月8日
解决方案
介绍Credentio:Google推出的用于C2PA内容凭证的开源C++库
2026年8月13日
云服务
代理异常检测现已在Gemini企业代理平台推出私有预览版
2026年9月16日
导航点