Appearance
- 官网: https://google.github.io/adk-docs
- GitHub: https://github.com/google/adk-java
- 最新版本: v1.0.0(2026年3月30日)
- 开源方: Google
- 开源协议: Apache 2.0
- JDK 要求: 17+
- 支持语言: Python、Java、Go、TypeScript
知识点清单
- [ ] Google ADK 是什么?与其他 AI Agent 框架的区别?
- [ ] Agent 的基本概念:Agent / Tool / Session / Memory
- [ ] 内置工具(GoogleMapsTool / UrlContextTool / ComputerUseTool 等)
- [ ] App & Plugin 架构
- [ ] Session 与 Memory 服务(多种持久化选择)
- [ ] Human-in-the-Loop(人工审批流程)
- [ ] A2A(Agent-to-Agent)协议支持
- [ ] 与 LangChain4j 的集成
- [ ] 事件压缩(Event Compaction)机制
- [ ] 开发 UI 工具
笔记
一、定位
Google ADK(Agent Development Kit)是 Google 开源的 多语言 AI Agent 开发框架,最初为 Python 设计,后扩展至 Java、Go、TypeScript。Java 版于 2026年3月30日 发布 v1.0.0 正式版。
核心设计理念:将 LLM 与工具、状态管理、外部数据源结合,构建可观测、可控制的 AI Agent。
二、核心概念
| 概念 | 说明 |
|---|---|
| Agent | 智能体,核心执行单元,LLM + 工具 + 状态 |
| Tool | 工具函数,Agent 可调用的外部能力 |
| Session | 会话管理,保存对话历史和状态 |
| Memory | 长期记忆,跨会话持久化信息 |
| Artifact | 文件产物,Agent 生成的文件管理 |
三、内置工具(v1.0 新增)
| 工具 | 说明 |
|---|---|
| GoogleMapsTool | 地理位置查询、路线规划 |
| UrlContextTool | 抓取网页内容作为上下文 |
| ContainerCodeExecutor | 在容器中安全执行代码 |
| VertexAiCodeExecutor | 基于 Vertex AI 的代码执行 |
| ComputerUseTool | 通过 Playwright 操控浏览器 |
四、App & Plugin 架构(v1.0 新增)
v1.0 引入了全新的应用架构:
- App 容器管理全局配置和插件注册
- Plugin 机制支持扩展:内置
LoggingPlugin、ContextFilterPlugin、GlobalInstructionPlugin - 开发者可自定义插件实现横切关注点
java
App app = App.builder()
.name("MyAgentApp")
.plugin(new LoggingPlugin())
.plugin(new GlobalInstructionPlugin("始终用中文回答"))
.build();
Agent agent = app.createAgent(/* agent config */);五、Session 与 Memory 服务
ADK 提供多种持久化选择,适应不同部署环境:
| 服务 | 说明 |
|---|---|
| InMemorySessionService | 内存存储,适合开发测试 |
| VertexAiSessionService | 基于 Vertex AI 的云端存储 |
| FirestoreSessionService | 基于 Firestore 的持久化 |
| FirestoreMemoryService | 长期记忆的 Firestore 实现 |
| GcsArtifactService | 文件产物的 Google Cloud Storage 存储 |
六、Human-in-the-Loop
Agent 可在执行过程中暂停,等待人工审批:
Agent 执行 → 触发 ToolConfirmation → 暂停等待 → 人工审批 → 继续执行适用于敏感操作(如发送邮件、执行数据库变更)需人工确认的场景。
七、事件压缩(Event Compaction)
管理 LLM 上下文窗口的关键机制:
- 摘要压缩:对历史对话自动生成摘要,替换原始内容
- 滑动窗口:保留最近 N 轮对话,丢弃旧内容
- 防止超出 token 上限导致对话失败
八、A2A 协议支持
原生支持 A2A(Agent-to-Agent)协议,通过官方 A2A Java SDK Client 和 JSON-RPC REST 端点实现跨框架 Agent 协作。不同团队、不同技术栈的 Agent 可以互相发现和调用。
九、与 LangChain4j 集成
v0.2.0 起集成 LangChain4j,开发者可在 ADK 中通过 LangChain4j 接入第三方模型:
- Ollama
- Docker Model Runner
- 其他 LangChain4j 支持的模型提供商
参见 框架 LangChain4j。
- 框架 AI框架选型对比 — 各框架差异与选型指南
十、快速开始
xml
<dependency>
<groupId>com.google.adk</groupId>
<artifactId>google-adk</artifactId>
<version>1.0.0</version>
</dependency>java
// 设置 Gemini API Key(环境变量)
// export GOOGLE_API_KEY=your_key
Agent agent = Agent.builder()
.model("gemini-2.5-flash")
.instruction("你是一个有帮助的 AI 助手。")
.build();
String response = agent.run("介绍一下 Google ADK");内置开发 UI 工具,可本地启动用于测试和调试 Agent:
bash
adk web十一、注意事项
- 默认使用 Google Gemini 模型(需要
GOOGLE_API_KEY) - 通过 LangChain4j 集成可扩展至其他模型提供商
- Google 在 Java 生态的长期维护投入尚待观察(社区有顾虑)
- Python 版本功能最全,Java 版正在快速追赶