adk-dev-guide
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseADK Development Workflow & Guidelines
ADK Agent开发工作流与规范
Session Continuity
会话连续性
If this is a long session, re-read the relevant skill before each phase —
before writing code, before running evals,
before deploying, before scaffolding.
Context compaction may have dropped earlier skill content.
/adk-cheatsheet/adk-eval-guide/adk-deploy-guide/adk-scaffold如果是长会话,请在每个阶段前重新阅读相关技能文档——编写代码前查看,运行评估前查看,部署前查看,搭建脚手架前查看。上下文压缩可能会丢失早期的技能文档内容。
/adk-cheatsheet/adk-eval-guide/adk-deploy-guide/adk-scaffoldDESIGN_SPEC.md — Your Primary Reference
DESIGN_SPEC.md — 你的首要参考文档
IMPORTANT: If exists in this project, it is your primary source of truth.
DESIGN_SPEC.mdRead it FIRST to understand:
- Functional requirements and capabilities
- Success criteria and quality thresholds
- Agent behavior constraints
- Expected tools and integrations
The spec is your contract. All implementation decisions should align with it. When in doubt, refer back to DESIGN_SPEC.md.
重要提示:如果项目中存在,它就是你的首要事实依据。
DESIGN_SPEC.md请先阅读它,以了解:
- 功能需求与能力要求
- 成功标准与质量阈值
- Agent行为约束
- 预期使用的工具与集成方案
规范就是你的契约。所有实现决策都必须与它保持一致。有疑问时,请随时参考DESIGN_SPEC.md。
Phase 1: Understand the Spec
阶段1:理解规范
Before writing any code:
- Read thoroughly
DESIGN_SPEC.md - Identify the core capabilities required
- Note any constraints or things the agent should NOT do
- Understand success criteria for evaluation
在编写任何代码之前:
- 仔细阅读
DESIGN_SPEC.md - 明确所需的核心能力
- 记录所有约束条件以及Agent不应该执行的操作
- 理解评估的成功标准
Phase 2: Build and Implement
阶段2:构建与实现
Implement the agent logic:
- Write/modify code in the agent directory (check GEMINI.md for directory name)
- Use (or
make playground) for interactive testing during developmentadk web . - Iterate on the implementation based on user feedback
For ADK API patterns and code examples, use .
/adk-cheatsheet实现Agent逻辑:
- 在Agent目录中编写/修改代码(请查看GEMINI.md获取目录名称)
- 开发期间使用(或
make playground)进行交互式测试adk web . - 根据用户反馈迭代实现方案
如需ADK API模式与代码示例,请查看。
/adk-cheatsheetPhase 3: Evaluate
阶段3:评估
This is the most important phase. Evaluation validates agent behavior end-to-end using.
MANDATORY: Activate before running evaluation. It contains the evalset schema, config format, and critical gotchas. Do NOT skip this.
/adk-eval-guideTests () are NOT evaluation. They test code correctness but say nothing about whether the agent behaves correctly. Always run .
pytestadk eval- Start small: Begin with 1-2 sample eval cases, not a full suite
- Run evaluations: (or
adk evalif the project has a Makefile)make eval - Discuss results with the user
- Fix issues and iterate on the core cases first
- Only after core cases pass, add edge cases and new scenarios
- Repeat until quality thresholds are met
Expect 5-10+ iterations here.
这是最重要的阶段。评估会端到端验证Agent的行为。
强制要求:运行评估前请激活,其中包含评估集 schema、配置格式以及关键注意事项。请勿跳过此步骤。
/adk-eval-guide测试()不等同于评估。测试仅验证代码正确性,但无法说明Agent行为是否符合预期。请务必运行。
pytestadk eval- 从小处着手:先从1-2个示例评估用例开始,而非完整套件
- 运行评估:(如果项目有Makefile,也可使用
adk eval)make eval - 与用户讨论评估结果
- 修复问题并优先迭代核心用例
- 仅当核心用例通过后,再添加边缘案例与新场景
- 重复上述步骤,直到达到质量阈值
预计需要5-10+次迭代。
Phase 4: Deploy
阶段4:部署
Once evaluation thresholds are met:
- Deploy when ready — see for deployment options
/adk-deploy-guide
IMPORTANT: Never deploy without explicit human approval.
当达到评估阈值后:
- 准备就绪后进行部署——请查看获取部署选项
/adk-deploy-guide
重要提示:未经明确的人工批准,请勿部署。
Operational Guidelines for Coding Agents
Agent编码操作规范
Principle 1: Code Preservation & Isolation
原则1:代码保留与隔离
When executing code modifications, your paramount objective is surgical precision. You must alter only the code segments directly targeted by the user's request, while strictly preserving all surrounding and unrelated code.
Mandatory Pre-Execution Verification:
Before finalizing any code replacement, verify:
- Target Identification: Clearly define the exact lines or expressions to be changed, based solely on the user's explicit instructions.
- Preservation Check: Ensure all code, configuration values (e.g., ,
model,version), comments, and formatting outside the identified target remain identical.api_key
Example:
- User Request: "Change the agent's instruction to be a recipe suggester."
- Incorrect (VIOLATION):
python
root_agent = Agent( name="recipe_suggester", model="gemini-1.5-flash", # UNINTENDED - model was not requested to change instruction="You are a recipe suggester." ) - Correct (COMPLIANT):
python
root_agent = Agent( name="recipe_suggester", # OK, related to new purpose model="gemini-3-flash-preview", # PRESERVED instruction="You are a recipe suggester." # OK, the direct target )
执行代码修改时,你的首要目标是精准操作。你必须仅修改用户请求直接指向的代码段,同时严格保留所有周边及无关代码。
执行前强制验证:
在最终确定任何代码替换前,请验证:
- 目标识别:仅根据用户的明确指令,明确定义需要修改的具体代码行或表达式。
- 保留检查:确保所有目标范围外的代码、配置值(如、
model、version)、注释与格式保持完全一致。api_key
示例:
- 用户请求:"将Agent的指令修改为食谱推荐器。"
- 错误示例(违反规范):
python
root_agent = Agent( name="recipe_suggester", model="gemini-1.5-flash", # 非预期修改——未要求更改模型 instruction="You are a recipe suggester." ) - 正确示例(符合规范):
python
root_agent = Agent( name="recipe_suggester", # 符合要求,与新用途相关 model="gemini-3-flash-preview", # 保留原配置 instruction="You are a recipe suggester." # 符合要求,为直接修改目标 )
Principle 2: Execution Best Practices
原则2:执行最佳实践
-
Model Selection — CRITICAL:
- NEVER change the model unless explicitly asked. If the code uses , keep it as
gemini-3-flash-preview. Do NOT "upgrade" or "fix" model names.gemini-3-flash-preview - When creating NEW agents (not modifying existing), use Gemini 3 series: ,
gemini-3-flash-preview.gemini-3-pro-preview - Do NOT use older models (,
gemini-2.0-flash, etc.) unless the user explicitly requests them.gemini-1.5-flash
- NEVER change the model unless explicitly asked. If the code uses
-
Location Matters More Than Model:
- If a model returns a 404, it's almost always a issue (e.g., needing
GOOGLE_CLOUD_LOCATIONinstead ofglobal).us-central1 - Changing the model name to "fix" a 404 is a violation — fix the location instead.
- Some models (like ) require specific locations. Check the error message for hints.
gemini-3-flash-preview
- If a model returns a 404, it's almost always a
-
ADK Built-in Tool Imports (Precision Required):python
# CORRECT - imports the tool instance from google.adk.tools.load_web_page import load_web_page # WRONG - imports the module, not the tool from google.adk.tools import load_web_pagePass the imported tool directly to, nottools=[load_web_page].tools=[load_web_page.load_web_page] -
Running Python Commands:
- Always use to execute Python commands (e.g.,
uv)uv run python script.py - Run (or
make install) before executing scriptsuv sync - Consult and
Makefilefor available commands (if present)README.md
- Always use
-
Breaking Infinite Loops:
- Stop immediately if you see the same error 3+ times in a row
- Don't retry failed operations — fix the root cause first
- RED FLAGS: Lock IDs incrementing, names appending v5->v6->v7, "I'll try one more time" repeatedly
- State conflicts (Error 409: Resource already exists): Import existing resources with instead of retrying creation
terraform import - Tool bugs: Fix source code bugs before continuing — don't work around them
- When stuck: Run underlying commands directly (e.g., CLI) instead of calling problematic tools
terraform
-
Troubleshooting:
- Check first — it covers most common patterns
/adk-cheatsheet - Search the installed ADK package with Glob/Grep/Read (find it with — use
python -c "import google.adk; print(google.adk.__path__[0])"if using uv)uv run python - For ADK docs, see in the cheatsheet skill for WebFetch URLs
references/docs-index.md - For framework questions or GCP products, check official documentation
- When encountering persistent errors, a targeted Google Search often finds solutions faster
- Check
-
模型选择——至关重要:
- 除非明确要求,否则绝不更改模型。如果代码使用,请保持不变。请勿“升级”或“修复”模型名称。
gemini-3-flash-preview - 创建新Agent(而非修改现有Agent)时,请使用Gemini 3系列:、
gemini-3-flash-preview。gemini-3-pro-preview - 除非用户明确要求,否则请勿使用旧版模型(如、
gemini-2.0-flash等)。gemini-1.5-flash
- 除非明确要求,否则绝不更改模型。如果代码使用
-
位置配置比模型更重要:
- 如果模型返回404错误,几乎都是配置问题(例如需要
GOOGLE_CLOUD_LOCATION而非global)。us-central1 - 通过更改模型名称来“修复”404错误属于违规操作——应修改位置配置。
- 部分模型(如)需要特定位置配置。请查看错误信息获取提示。
gemini-3-flash-preview
- 如果模型返回404错误,几乎都是
-
ADK内置工具导入(需精准操作):python
# 正确示例 - 导入工具实例 from google.adk.tools.load_web_page import load_web_page # 错误示例 - 导入模块而非工具实例 from google.adk.tools import load_web_page请直接将导入的工具传递给,而非tools=[load_web_page]。tools=[load_web_page.load_web_page] -
运行Python命令:
- 请始终使用执行Python命令(例如
uv)uv run python script.py - 执行脚本前请先运行(或
make install)uv sync - 请参考Makefile和README.md获取可用命令(如果存在)
- 请始终使用
-
打破无限循环:
- 如果连续3次以上看到相同错误,请立即停止
- 不要重试失败的操作——先修复根本原因
- 危险信号:锁ID递增、名称从v5追加到v6再到v7、反复出现“我再试一次”
- 状态冲突(错误409:资源已存在):使用导入现有资源,而非重复尝试创建
terraform import - 工具bug:先修复源代码bug再继续——不要绕过问题
- 遇到瓶颈时:直接运行底层命令(例如CLI),而非调用有问题的工具
terraform
-
故障排查:
- 首先查看——它涵盖了大多数常见模式
/adk-cheatsheet - 使用Glob/Grep/Read搜索已安装的ADK包(通过查找路径——如果使用uv,请用
python -c "import google.adk; print(google.adk.__path__[0])")uv run python - 如需ADK文档,请查看cheatsheet技能中的获取WebFetch链接
references/docs-index.md - 如需框架相关问题或GCP产品信息,请查阅官方文档
- 遇到持续错误时,针对性的谷歌搜索通常能更快找到解决方案
- 首先查看
Scaffold as Reference
脚手架作为参考
When you need specific infrastructure files but don't want to scaffold the current project directly, use the skill to create a temporary reference project in and copy over what you need.
/adk-scaffold/tmp/See for full CLI commands and options.
/adk-scaffold当你需要特定的基础设施文件但不想直接为当前项目搭建脚手架时,可以使用技能在目录中创建一个临时参考项目,然后复制所需内容。
/adk-scaffold/tmp/请查看获取完整的CLI命令与选项。
/adk-scaffoldDevelopment Commands
开发命令
Projects created via the Agent Starter Pack CLI include a Makefile with these commands.
To create or enhance a project, see the skill for full instructions.
For non-scaffolded projects, use the ADK CLI equivalents.
/adk-scaffold| Make (scaffolded) | ADK CLI equivalent | Purpose |
|---|---|---|
| | Interactive local testing |
| | Run unit and integration tests |
| | Run evaluation against evalsets |
| | Check code quality |
| — (scaffolded only) | Set up dev infrastructure (Terraform) |
| — (scaffolded only) | Deploy to dev (requires human approval) |
通过Agent Starter Pack CLI创建的项目包含一个带有以下命令的Makefile。如需创建或增强项目,请查看技能获取完整说明。对于非脚手架创建的项目,请使用ADK CLI的等效命令。
/adk-scaffold| Make(脚手架项目) | ADK CLI等效命令 | 用途 |
|---|---|---|
| | 交互式本地测试 |
| | 运行单元与集成测试 |
| | 针对评估集运行评估 |
| | 检查代码质量 |
| —(仅脚手架项目可用) | 设置开发基础设施(Terraform) |
| —(仅脚手架项目可用) | 部署到开发环境(需人工批准) |
Skills Version
技能版本
Troubleshooting hint: If you encounter repeated errors, unexpected tool failures, or instructions in these skills that seem incomplete or reference features you can't find, the skills may be outdated. Run:uvx --from "google-adk" adk dev skills checkIf it reports outdated skills, tell the user to update:uvx --from "google-adk" adk dev skills setup -yDo NOT run this check on every session — only when you suspect stale skills are causing problems.
故障排查提示:如果你遇到重复错误、工具意外故障,或者技能文档中的说明不完整、引用了找不到的功能,可能是技能文档已过期。请运行:uvx --from "google-adk" adk dev skills check如果报告技能已过时,请告知用户进行更新:uvx --from "google-adk" adk dev skills setup -y请勿在每个会话中都运行此检查——仅当你怀疑过时的技能文档导致问题时才执行。