Communitygithub.com

Google ADK Python AI 智能体构建技能

使用 Google ADK (Agent Development Kit) Python 构建 AI 智能体。适用于多智能体系统、工作流智能体(顺序/并行/循环)、Vertex AI 部署、工具集成和人机协作场景。

Google ADK Python AI 智能体构建技能 是什么?

该技能旨在指导开发者利用 Google 的开源、代码优先的 Agent Development Kit (ADK) Python 版本,从头开始构建、评估和部署 AI 智能体。它涵盖了从简单的单智能体工具集成到复杂的多智能体分层协调和可预测工作流(顺序、并行、循环)的广泛场景。技能详细介绍了核心 LlmAgent、Workflow Agents 以及自定义 BaseAgent 的概念,并提供了丰富的代码示例,展示如何集成 Google 搜索、代码执行等预置工具以及自定义函数。此外,还强调了如何通过 Tool Confirmation 实现人机协作审批流程,并说明了部署到 Vertex AI Agent Engine 或 Cloud Run 等平台的方法。该技能特别适合需要快速原型设计、生产级部署和系统化评估智能体的开发团队,它贯彻了将智能体开发视为传统软件工程的最佳实践,鼓励使用版本控制、模块化设计和测试。

兼容平台✓Claude Code~Codex CLI~Cursor✓Gemini CLI
npx skills add https://github.com/majiayu000/claude-skill-registry/tree/HEAD/skills/agent/google-adk-python-hoanghd218-landing-page-ai-kien

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Google ADK Python 技能

您是 Google Agent Development Kit (ADK) Python 的专家指南——这是一个开源的、代码优先的工具包,用于构建、评估和部署 AI 智能体。

何时使用此技能

当用户需要以下场景时,请使用此技能:

  • 构建具有工具集成和编排能力的 AI 智能体
  • 创建具有分层协调机制的多智能体系统
  • 为可预测的流程实现工作流智能体(顺序、并行、循环)
  • 将 LLM 驱动的智能体与 Google 搜索、代码执行或自定义工具集成
  • 将智能体部署到 Vertex AI Agent Engine、Cloud Run 或自定义基础设施
  • 系统性地评估和测试智能体性能
  • 实现工具执行的人机协作审批流程

核心概念

智能体类型

LlmAgent:LLM 驱动的智能体,具备动态路由和自适应行为

  • 使用名称、模型、指令、描述和工具进行定义
  • 支持子智能体进行委托和协调
  • 基于上下文的智能决策

工作流智能体:结构化的、可预测的编排模式

  • SequentialAgent:按定义顺序执行智能体
  • ParallelAgent:并发运行多个智能体
  • LoopAgent:使用迭代逻辑重复执行

BaseAgent:自定义智能体实现的基础

关键组件

工具生态系统:

  • 预置工具 (google_search, code_execution)
  • 作为工具的自定义 Python 函数
  • OpenAPI 规范集成
  • 用于人工审批的工具确认流程

多智能体架构:

  • 分层智能体组合
  • 面向特定领域的专业化智能体
  • 用于委托的协调智能体

安装

# 稳定版本(推荐)
pip install google-adk

# 开发版本(最新特性)
pip install git+https://github.com/google/adk-python.git@main

实现模式

带工具的单智能体

from google.adk.agents import LlmAgent
from google.adk.tools import google_search

agent = LlmAgent(
    name="search_assistant",
    model="gemini-2.5-flash",
    instruction="你是一个乐于助人的助手,负责在网上搜索信息。",
    description="用于网络查询的搜索助手",
    tools=[google_search]
)

多智能体系统

from google.adk.agents import LlmAgent

# 专业化智能体
researcher = LlmAgent(
    name="Researcher",
    model="gemini-2.5-flash",
    instruction="使用网络搜索彻底研究主题。",
    tools=[google_search]
)

writer = LlmAgent(
    name="Writer",
    model="gemini-2.5-flash",
    instruction="根据研究结果撰写清晰、引人入胜的内容。",
)

# 协调智能体
coordinator = LlmAgent(
    name="Coordinator",
    model="gemini-2.5-flash",
    instruction="将任务委托给研究员和写手智能体。",
    sub_agents=[researcher, writer]
)

自定义工具创建

from google.adk.tools import Tool

def calculate_sum(a: int, b: int) -> int:
    """计算两个数字的和。"""
    return a + b

# 将函数转换为工具
sum_tool = Tool.from_function(calculate_sum)

agent = LlmAgent(
    name="calculator",
    model="gemini-2.5-flash",
    tools=[sum_tool]
)

顺序工作流

from google.adk.agents import SequentialAgent

workflow = SequentialAgent(
    name="research_workflow",
    agents=[researcher, summarizer, writer]
)

并行工作流

from google.adk.agents import ParallelAgent

parallel_research = ParallelAgent(
    name="parallel_research",
    agents=[web_researcher, paper_researcher, expert_researcher]
)

人机协作

from google.adk.tools import google_search

# 需要确认的工具
agent = LlmAgent(
    name="careful_searcher",
    model="gemini-2.5-flash",
    tools=[google_search],
    tool_confirmation=True  # 执行前需要审批
)

部署选项

Cloud Run 部署

# 容器化智能体
docker build -t my-agent .

# 部署到 Cloud Run
gcloud run deploy my-agent --image my-agent

Vertex AI Agent Engine

# 部署到 Vertex AI 以实现可扩展的智能体托管
# 与 Google Cloud 的托管基础设施集成

自定义基础设施

# 在本地或自定义服务器上运行智能体
# 完全控制部署环境

模型支持

针对 Gemini 优化:

  • gemini-2.5-flash
  • gemini-2.5-pro
  • gemini-1.5-flash
  • gemini-1.5-pro

模型无关:尽管针对 Gemini 进行了优化,但 ADK 通过标准 API 支持其他 LLM 提供商。

最佳实践

  1. 代码优先理念:在 Python 中定义智能体,以实现版本控制、测试和灵活性
  2. 模块化设计:创建针对特定领域的专业化智能体,并组合成系统
  3. 工具集成:利用预置工具,使用自定义函数进行扩展
  4. 评估:根据测试用例系统性地测试智能体
  5. 安全性:为敏感操作实现确认流程
  6. 分层结构:为复杂多智能体工作流使用协调智能体
  7. 工作流选择:为可预测的流水线选择工作流智能体,为动态路由选择 LLM 智能体

常见用例

  • 研究助手:网络搜索 + 摘要 + 报告生成
  • 代码助手:代码执行 + 文档 + 调试
  • 客户支持:查询路由 + 知识库 + 升级
  • 内容创作:研究 + 写作 + 编辑流水线
  • 数据分析:数据获取 + 处理 + 可视化
  • 任务自动化:具有条件逻辑的多步骤工作流

开发 UI

ADK 包括内置界面,用于:

  • 交互式测试智能体行为
  • 调试工具调用和响应
  • 评估智能体性能
  • 迭代智能体设计

资源

实现工作流

实现基于 ADK 的智能体时:

  1. 定义需求:确定智能体能力和所需工具
  2. 选择架构:单智能体、多智能体或基于工作流
  3. 选择工具:预置、自定义函数或 OpenAPI 集成
  4. 实现智能体:使用指令和工具创建智能体定义
  5. 本地测试:使用开发 UI 进行迭代
  6. 添加评估:为系统性验证创建测试用例
  7. 部署:选择 Cloud Run、Vertex AI 或自定义基础设施
  8. 监控:跟踪智能体性能并迭代

请记住:ADK 将智能体开发视为传统软件工程——使用版本控制、编写测试,并遵循工程最佳实践。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

majiayu000/claude-skill-registry

Builds, edit or validate Agent Skill through conversational discovery. Use when the user requests to "Create an Agent", "Optimize an Agent" or "Edit an Agent".

majiayu000/claude-skill-registry

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry

Analyzes current state and user query to answer BMad questions or recommend the next workflow or agent. Use when user says what should I do next, what do I do now, or asks a question about BMad

majiayu000/claude-skill-registry

Build AI agents with Google ADK Python (Agent Development Kit). Use for multi-agent systems, workflow agents (sequential/parallel/loop), Vertex AI deployment, tool integration, human-in-the-loop.

majiayu000/claude-skill-registry

Portfolio allocation and rebalancing optimizer. Manages asset allocation across stocks/cash/bonds, performs periodic rebalancing, and ensures diversification according to market regime and risk tolerance.

majiayu000/claude-skill-registry

Create a hilarious and ultra-realistic video of an anthropomorphic animal acting like a human vlogger in a real-world setting.

majiayu000/claude-skill-registry

Speech-to-text transcription and translation via OpenAI Audio API -- models, response formats, timestamps, prompting, streaming, chunking, and diarization

majiayu000/claude-skill-registry

BlockRun works with Claude Code and Google Antigravity.

majiayu000/claude-skill-registry

This skill should be used when the user asks about libraries, frameworks, API references, or needs code examples. Activates for setup questions, code generation involving libraries, or mentions of specific frameworks like React, Vue, Next.js, Prisma, Supabase, etc.

majiayu000/claude-skill-registry

小省导购员数字人带货版即梦视频提示词生成系统,基于四大智能体协同(提示词生成师、质量管控师、知识库运维师、跨环节适配师),按照"主体+运动+场景+(镜头语言+光影+氛围)"公式输出中英文双版提示词,适配5s短视频。确保人物一致性、视觉连贯性、情绪连贯性,支持知识库智能复用和跨工具适配(Suno音乐、AI绘画),为数字人带货视频提供高质量提示词生成服务。

majiayu000/claude-skill-registry

Upload and manage files using Google Gemini File API via scripts/. Use for uploading images, audio, video, PDFs, and other files for use with Gemini models. Supports file upload, status checking, and file management. Triggers on "upload file", "file API", "upload image", "upload PDF", "upload video", "file management".

majiayu000/claude-skill-registry

CRITICAL: Use for MolyKit AI chat toolkit. Triggers on: BotClient, OpenAI, SSE streaming, AI chat, molykit, PlatformSend, spawn(), ThreadToken, cross-platform async, Chat widget, Messages, PromptInput, Avatar, LLM

majiayu000/claude-skill-registry

AI and machine learning workflow covering LLM application development, RAG implementation, agent architecture, ML pipelines, and AI-powered features.

majiayu000/claude-skill-registry

Analyze images/audio/video with Gemini API (better vision than Claude). Generate images (Imagen 4), videos (Veo 3). Use for vision analysis, transcription, OCR, design extraction, multimodal AI.

majiayu000/claude-skill-registry

Analyze images/audio/video with Gemini API (better vision than Claude). Generate images (Imagen 4), videos (Veo 3). Use for vision analysis, transcription, OCR, design extraction, multimodal AI.

majiayu000/claude-skill-registry

Conduct domain and industry research. Use when the user says "lets create a research report on [domain or industry]

majiayu000/claude-skill-registry

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

相关技能