Skip to content

Commit 3c64aa8

Browse files
authored
Merge branch 'main' into zzz-day-02-notes
2 parents a202308 + c693874 commit 3c64aa8

7 files changed

Lines changed: 170 additions & 3 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Lint PR Title"
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
jobs:
11+
main:
12+
name: Validate PR Title
13+
runs-on: ubuntu-slim
14+
steps:
15+
- name: Semantic PR Title
16+
uses: amannn/action-semantic-pull-request@v5
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
with:
20+
# Enforce that the subject starts with a lowercase letter.
21+
subjectPattern: ^[a-z].*$
22+
subjectPatternError: |
23+
The subject "{subject}" must start with a lowercase letter.

agents/my_agent/agent.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from google.adk.agents.config_agent_utils import load_agent_from_config
2+
from google.adk.runners import Runner
3+
from google.adk.sessions import InMemorySessionService
4+
from google.genai import types
5+
import asyncio
6+
from pathlib import Path
7+
8+
# CONFIGURATION
9+
APP_NAME = "simple_search_agent"
10+
USER_ID = "user_default"
11+
SESSION_ID = "session_01"
12+
13+
# AGENT DEFINITION - Load from YAML using ADK's built-in method
14+
yaml_path = Path(__file__).parent / 'root_agent.yaml'
15+
root_agent = load_agent_from_config(str(yaml_path))
16+
17+
18+
# Session and Runner
19+
async def setup_session_and_runner():
20+
session_service = InMemorySessionService()
21+
session = await session_service.create_session(
22+
app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID
23+
)
24+
runner = Runner(
25+
agent=root_agent, app_name=APP_NAME, session_service=session_service
26+
)
27+
return session, runner
28+
29+
30+
# Agent Interaction
31+
async def call_agent_async(query):
32+
content = types.Content(role="user", parts=[types.Part(text=query)])
33+
session, runner = await setup_session_and_runner()
34+
events = runner.run_async(
35+
user_id=USER_ID, session_id=SESSION_ID, new_message=content
36+
)
37+
38+
async for event in events:
39+
if event.is_final_response():
40+
final_response = event.content.parts[0].text
41+
print("Agent Response: ", final_response)
42+
43+
44+
if __name__ == "__main__":
45+
asyncio.run(call_agent_async("what's the latest ai news?"))

agents/my_agent/root_agent.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# yaml-language-server: $schema=https://raw.githubusercontent.com/google/adk-python/refs/heads/main/src/google/adk/agents/config_schemas/AgentConfig.json
2-
name: root_agent
3-
description: A helpful assistant for user questions.
4-
instruction: Answer user questions to the best of your knowledge
2+
name: search_agent
3+
description: A helpful assistant that can search Google.
4+
instruction: |
5+
You are a helpful assistant with access to Google Search.
6+
7+
If the user asks a question that requires current information or facts, use the 'google_search' tool.
8+
Always cite your sources implicitly by providing the answer clearly based on the search results.
59
model: gemini-2.5-flash
10+
tools:
11+
- name: google_search

figs/day-03.png

979 KB
Loading

notes/day-02.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
- 后续使用方便起见,这次直接安装了完整的 `google-adk`
2121
- 注意⚠️:其中的 `MCP` 组件强制要求Python版本在**3.10**以上,新建环境时要注意编译器的选择
2222
- 在Pycharm终端调用agent互动时,无法显式输出日志,只能通过prompt要求输出思考过程
23+
- 网站上给的 command 是错误的,运行 `uvx --from google-adk adk web` 时默认时读取 a directory of agents,而不是在 agent directory。
24+
- Tutorial: AI agent with Google Search(YAML) instruction 也是错的. `adk web` 运行的时候directory应该在agent的parent folder里。
25+
- Tutorial: Multi-agent app with MCP (YAML) 要安装Node.Js 是firecrawl的dependency。firecrawl需要注册,free tier不需要花钱,api key能在设置里找到。
2326

2427
## Code Examples
2528

@@ -46,6 +49,20 @@ model: gemini-2.5-flash
4649
tools:
4750
- name: google_search
4851
```
52+
### `adk api_server` 的使用
53+
以调取api的模式使用agent不能直接点击网页或者和UI直接交互。just in case有人和我一样不懂怎么调取api,下面是使用范例。
54+
55+
输入`adk api_server` 之后新开一个terminal
56+
```bash
57+
curl -X POST http://localhost:8000/apps/my_agent/users/u_123/sessions/s_123 -H "Content-Type: application/json"
58+
```
59+
apps 后面是agent的名字,user后面是userId,session后面是sessionId.
60+
61+
```bash
62+
curl -X POST http://localhost:8000/run -H "Content-Type: application/json" -d '{"appName":"my_agent", "userId":"u_123", "sessionId":"s_123", "newMessage": {"role": "user", "parts":[{"text": "hello"}]}}'
63+
```
64+
app_name、userId、sessionId需要和上文对应。text后输入user想说的话。
65+
你会在这个terminal看到model的回复。
4966

5067
## Resources
5168

notes/day-03.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Day 03 - 在 Python 代码中加载 YAML 配置的智能体
2+
3+
**挑战链接**: [Advent of Agents - Day 03](https://adventofagents.com/day/03)
4+
5+
![Day 03 Screenshot](figs/day-03.png)
6+
7+
## 关键学习
8+
9+
- Google ADK 提供了内置方法 `load_agent_from_config()` 来从 YAML 文件加载智能体配置
10+
- YAML 配置文件可以包含完整的智能体定义,包括名称、描述、指令、模型和工具
11+
- 工具可以在 YAML 文件中通过 `tools` 部分定义,例如 `google_search`
12+
- ADK Web Developer UI 可以自动检测并加载 Python 代码中定义的智能体
13+
- 使用 `Path(__file__).parent` 可以获取相对于当前脚本文件的路径,方便加载同目录下的 YAML 文件
14+
15+
## 面临的挑战
16+
17+
- 最初尝试手动解析 YAML 文件,但发现 ADK 有更优雅的内置方法
18+
- 需要了解 `Agent` 类和 `LlmAgent` 类的区别,以及何时使用 `load_agent_from_config`
19+
- 确保 YAML 文件中的工具名称与 ADK 提供的工具名称匹配
20+
21+
## 资源
22+
23+
- [ADK Config Agent Documentation](http://google.github.io/adk-docs/agent/config/) - 使用 YAML 配置构建智能体的官方文档
24+
- [ADK Agents API Reference](http://google.github.io/adk-docs/agents/) - 智能体 API 参考文档
25+
- [Google ADK Python Documentation](http://google.github.io/adk-docs/) - ADK Python 完整文档
26+
27+
## 问题 / 开放话题
28+
29+
- 不是必须要用 Gemini Pro 3,在 YAML 配置里把 model 模型改成 free tier 里提供的即可

notes/day-04.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Day 04 - [源码部署]
2+
3+
**挑战链接**: [Advent of Agents - Day 04](https://adventofagents.com/day/04)
4+
5+
## 关键学习
6+
7+
- **使用 agent-starter-pack 自动生成部署配置**:通过 `uvx agent-starter-pack enhance -d agent_engine` 命令,工具会自动生成所有 Vertex AI Agent Engine 部署所需的代码和配置(包括 `deploy.py``agent_engine_app.py`、Makefile 等)。部署时使用 `make deploy` 即可,工具会自动处理源代码打包、上传到云端、构建容器镜像等步骤,无需手动配置。
8+
9+
## 面临的挑战
10+
11+
- **Google Cloud SDK 安装和配置**
12+
- 需要安装 Google Cloud SDK (`gcloud`)
13+
- 运行 `gcloud auth application-default login` 进行身份认证
14+
15+
- **必须启用的 API**
16+
- Vertex AI API - 核心服务,用于部署 agent
17+
- Cloud Resource Manager API - 用于项目资源管理
18+
19+
- **项目 ID 配置**
20+
- 必须设置 Google Cloud 项目 ID,否则部署会失败
21+
- 可以通过环境变量 `export GOOGLE_CLOUD_PROJECT=your-project-id` 设置
22+
- 或通过 Makefile 参数 `make deploy PROJECT_ID=your-project-id` 传递
23+
- 或使用 `gcloud config set project your-project-id` 设置默认项目
24+
25+
- **成本优化配置**
26+
- 默认 `min-instances=1` 会导致持续计费(约 $50-100/月)
27+
- 可以手动设置 `min-instances=0` 实现按需启动,空闲时缩容到零
28+
- **Vertex AI Agent Engine Free Tier**(每月免费额度):
29+
- vCPU:前 180,000 vCPU秒(50 小时)免费
30+
- RAM:前 360,000 GiB秒(100 小时)免费
31+
32+
## 代码示例
33+
34+
```python
35+
# 在此添加你的代码示例
36+
```
37+
38+
## 资源
39+
40+
- [Source-Based Deployment Tutorial(Video)](https://www.youtube.com/watch?v=8RjzMG3BKA0)
41+
- [Agent Starter Pack](https://github.com/GoogleCloudPlatform/agent-starter-pack)
42+
- [Agent Engine Deployment Docs](https://docs.cloud.google.com/agent-builder/agent-engine/deploy)
43+
44+
## 问题 / 开放话题
45+
46+
-
47+
-

0 commit comments

Comments
 (0)