google-agents-cli-adk-code
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseADK Cheatsheet
ADK速查表
Before using this skill, activatefirst — it contains the required development phases and scaffolding steps./google-agents-cli-workflow
使用本技能前,请先激活——它包含所需的开发阶段和脚手架步骤。/google-agents-cli-workflow
Prerequisites
前置条件
- Run — if it shows project config, skip to the cheatsheet below
agents-cli info - If no project exists: run
agents-cli scaffold create <name> - If user has existing code: run
agents-cli scaffold enhance .
Do NOT write agent code until a project is scaffolded.
Python only for now. This cheatsheet currently covers the Python ADK SDK. Support for other languages is coming soon.
- 运行——如果显示项目配置,直接跳至下方速查表
agents-cli info - 若无项目存在:运行
agents-cli scaffold create <name> - 若用户已有代码:运行
agents-cli scaffold enhance .
在完成项目脚手架搭建前,请勿编写Agent代码。
目前仅支持Python。本速查表当前覆盖Python ADK SDK。 其他语言的支持即将推出。
Quick Reference — Most Common Patterns
快速参考——最常用模式
Agent Creation
Agent创建
python
from google.adk.agents import Agent
root_agent = Agent(
name="my_agent",
model="gemini-flash-latest",
instruction="You are a helpful assistant that ...",
tools=[my_tool],
)NEVER change an existing agent'svalue unless the user explicitly asks. If a Gemini model returns a 404, it's almost always amodel=issue — run the listing command to verify availability before changing anything. For model docs, fetchGOOGLE_CLOUD_LOCATION.https://adk.dev/agents/models/google-gemini/index.mdbashuv run --with google-genai python -c " from google import genai client = genai.Client(vertexai=True, location='global') for m in client.models.list(): print(m.name) "
python
from google.adk.agents import Agent
root_agent = Agent(
name="my_agent",
model="gemini-flash-latest",
instruction="You are a helpful assistant that ...",
tools=[my_tool],
)除非用户明确要求,否则绝不要修改现有Agent的值。如果Gemini模型返回404错误,几乎都是model=问题——在修改任何内容前,先运行列表命令验证可用性。如需模型文档,请获取GOOGLE_CLOUD_LOCATION。https://adk.dev/agents/models/google-gemini/index.mdbashuv run --with google-genai python -c " from google import genai client = genai.Client(vertexai=True, location='global') for m in client.models.list(): print(m.name) "
Basic Tool
基础工具
python
from google.adk.tools import FunctionTool
def get_weather(city: str) -> dict:
"""Get current weather for a city."""
return {"city": city, "temp": "22°C", "condition": "sunny"}
weather_tool = FunctionTool(func=get_weather)ADK built-in tool imports: Import the tool instance, not the module.pythonfrom google.adk.tools.load_web_page import load_web_page # CORRECT from google.adk.tools import load_web_page # WRONG
python
from google.adk.tools import FunctionTool
def get_weather(city: str) -> dict:
"""Get current weather for a city."""
return {"city": city, "temp": "22°C", "condition": "sunny"}
weather_tool = FunctionTool(func=get_weather)ADK内置工具导入方式:导入工具实例,而非模块。pythonfrom google.adk.tools.load_web_page import load_web_page # 正确 from google.adk.tools import load_web_page # 错误
Simple Callback
简单回调
python
from google.adk.agents.callback_context import CallbackContext
async def initialize_state(callback_context: CallbackContext) -> None:
state = callback_context.state
if "history" not in state:
state["history"] = []
root_agent = Agent(
name="my_agent",
model="gemini-flash-latest",
instruction="...",
before_agent_callback=initialize_state,
)python
from google.adk.agents.callback_context import CallbackContext
async def initialize_state(callback_context: CallbackContext) -> None:
state = callback_context.state
if "history" not in state:
state["history"] = []
root_agent = Agent(
name="my_agent",
model="gemini-flash-latest",
instruction="...",
before_agent_callback=initialize_state,
)Reference Files
参考文件
| File | When to read |
|---|---|
| ADK Python API — agents, tools, callbacks, plugins, state, artifacts, context caching, session rewind |
| ADK 2.0 Workflow API (experimental pre-GA, opt-in) — graph-based workflows, nodes, edges, HITL, parallel processing |
| 文件 | 阅读时机 |
|---|---|
| ADK Python API——agents、tools、callbacks、plugins、state、artifacts、context caching、session rewind |
| ADK 2.0 Workflow API(实验性预GA版本,需手动启用)——基于图的工作流、节点、边、人机交互(HITL)、并行处理 |
ADK 2.0 Workflows — Opt-in
ADK 2.0工作流——需手动启用
The Workflow API is experimental, pre-GA (ADK 2.0). Do NOT recommend it by default.Before suggesting workflow patterns, explain the following to the user and ask if they want to proceed:
- What it is: ADK 2.0 introduces a graph-based Workflow API — nodes (functions, LLM agents, tools) connected by edges with conditional routing, fan-out/fan-in parallelism, and human-in-the-loop interrupts.
- When it helps: Complex multi-step pipelines needing deterministic control flow, parallel processing of list items, structured approval gates, or retry logic — cases where SequentialAgent/ParallelAgent/LoopAgent feel limiting.
- Risks: Pre-GA — APIs may change before GA. Requires
and Python >= 3.11. Incompatible with Live Streaming. Scaffolded projects needgoogle-adk >= 2.0.0changes before upgrade — see the reference file for step-by-step instructions.pyproject.tomlOnly readafter the user explicitly opts in. If they decline or are unsure, use the standard ADK 1.x orchestration patterns fromreferences/adk-2.0.md(SequentialAgent, ParallelAgent, LoopAgent, BaseAgent).references/adk-python.md
Workflow API为实验性预GA版本(ADK 2.0)。默认不推荐使用。在推荐工作流模式前,请向用户解释以下内容并询问是否要继续:
- 是什么:ADK 2.0引入基于图的Workflow API——节点(函数、LLM agents、工具)通过带有条件路由、扇出/扇入并行处理和人机交互中断的边连接。
- 适用场景:需要确定性控制流、列表项并行处理、结构化审批 gate 或重试逻辑的复杂多步骤流水线——即SequentialAgent/ParallelAgent/LoopAgent无法满足需求的场景。
- 风险:预GA版本——API在正式发布前可能会变更。需要
和Python >= 3.11。与Live Streaming不兼容。脚手架项目升级前需要修改google-adk >= 2.0.0——请查看参考文件获取分步说明。pyproject.toml仅在用户明确同意后,才可查阅。若用户拒绝或不确定,请使用references/adk-2.0.md中的标准ADK 1.x编排模式(SequentialAgent、ParallelAgent、LoopAgent、BaseAgent)。references/adk-python.md
ADK Documentation
ADK文档
For the ADK docs index (titles and URLs for fetching documentation pages), use .
curl https://adk.dev/llms.txt如需ADK文档索引(可用于获取文档页面的标题和URL),请使用。
curl https://adk.dev/llms.txtRelated Skills
相关技能
- — Development workflow, coding guidelines, and operational rules
/google-agents-cli-workflow - — Project creation and enhancement with
/google-agents-cli-scaffold/agents-cli scaffold createscaffold enhance - — Evaluation methodology, evalset schema, and the eval-fix loop
/google-agents-cli-eval - — Deployment targets, CI/CD pipelines, and production workflows
/google-agents-cli-deploy
- ——开发工作流、编码指南和操作规则
/google-agents-cli-workflow - ——使用
/google-agents-cli-scaffold/agents-cli scaffold create创建和优化项目scaffold enhance - ——评估方法、评估集 schema 和 eval-fix循环
/google-agents-cli-eval - ——部署目标、CI/CD流水线和生产工作流
/google-agents-cli-deploy