Loading...
Loading...
Compare original and translation side by side
google-adkadk-goadk-javagoogle-adkadk-goadk-javaSTART: What's the agent's decision pattern?
│
├─> Requires natural language reasoning? ─Yes─> LlmAgent ★
│
├─> Fixed sequence of steps?
│ └─> Sequential Workflow Agent ★
│
├─> Independent parallel operations?
│ └─> Parallel Workflow Agent ★
│
├─> Iterative refinement needed?
│ └─> Loop Workflow Agent ★
│
└─> Custom orchestration logic?
└─> Custom Agent ★开始:智能体的决策模式是什么?
│
├─> 需要自然语言推理? ─是─> LlmAgent ★
│
├─> 固定步骤序列?
│ └─> 顺序工作流智能体 ★
│
├─> 独立并行操作?
│ └─> 并行工作流智能体 ★
│
├─> 需要迭代优化?
│ └─> 循环工作流智能体 ★
│
└─> 自定义编排逻辑?
└─> 自定义智能体 ★create_weather_assistant()create_data_pipeline()create_market_researcher()create_content_generator()create_stateful_session()create_weather_assistant()create_data_pipeline()create_market_researcher()create_content_generator()create_stateful_session()undefinedundefined
**Programmatic Testing:**
```python
**程序化测试:**
```python
**Evaluation Framework:**
```python
from google.adk.evaluation import evaluate_agent
**评估框架:**
```python
from google.adk.evaluation import evaluate_agentundefinedundefinedcalculate_tax()fetch_user_data()send_email()delete_user_account()send_email_tool()fetch_external_data()call_external_api()fetch_stock_price()calculate_tax()fetch_user_data()send_email()delete_user_account()send_email_tool()fetch_external_data()call_external_api()fetch_stock_price()create_api_agent()create_api_agent()create_mcp_agent()create_mcp_agent()create_coordinator_system()create_content_pipeline()create_market_analysis_system()create_project_management_system()create_quality_content_system()create_account_management_agent()StatefulAgentsave_state()load_state()create_coordinator_system()create_content_pipeline()create_market_analysis_system()create_project_management_system()create_quality_content_system()create_account_management_agent()StatefulAgentsave_state()load_state()create_stateful_session()create_stateful_session()StatefulAgentsave_state()load_state()StatefulAgentsave_state()load_state()pip install google-adk[cli]
adk auth login
adk deploy --agent-file agent.py --agent-name my_agent --project-id my-gcp-project --region us-central1create_production_agent()pip install google-adk[cli]
adk auth login
adk deploy --agent-file agent.py --agent-name my_agent --project-id my-gcp-project --region us-central1create_production_agent()| Agent Complexity | CPU | RAM | Concurrent Requests |
|---|---|---|---|
| Simple LlmAgent | 1 core | 512MB | 10 |
| Workflow Agent | 2 cores | 1GB | 20 |
| Multi-Agent (3-5 agents) | 4 cores | 2GB | 10 |
| Complex Multi-Agent (>5) | 8 cores | 4GB | 5 |
| 智能体复杂度 | CPU | 内存 | 并发请求数 |
|---|---|---|---|
| 简单LlmAgent | 1核 | 512MB | 10 |
| 工作流智能体 | 2核 | 1GB | 20 |
| 多智能体(3-5个) | 4核 | 2GB | 10 |
| 复杂多智能体(>5个) | 8核 | 4GB | 5 |
evaluate_agent_endpoint()evaluate_agent_endpoint()fetch_stock_price()fetch_external_data()send_email_tool()fetch_stock_price()fetch_external_data()send_email_tool()send_email_tool()rate_limit()send_email_tool()rate_limit()fetch_price()create_portfolio_analyzer()fetch_price()create_portfolio_analyzer()# BAD: Vague description
def process(data):
"""Process data.""" # Too generic
# GOOD: Specific description
def validate_email_format(email: str) -> bool:
"""Check if email address matches valid format (user@domain.com).
Use this tool ONLY to validate email syntax, not to verify
if email exists or is deliverable."""# Add max_iterations and explicit break condition
agent = LoopAgent(
tools=[...],
max_iterations=10, # Hard limit
break_condition=lambda result: result.get("completed", False)
)def robust_tool(param: str) -> str:
try:
result = risky_operation(param)
return f"Success: {result}"
except SpecificError as e:
return f"Operation failed: {e.message}"
except Exception as e:
logger.error(f"Unexpected error in robust_tool: {e}")
return "Temporary service error, please try again"# Use Parallel Agent or async tools
agent = ParallelAgent(
tools=[tool1, tool2, tool3] # Execute concurrently
)session = Session(
agent=my_agent,
max_history_turns=10, # Limit history
context_window_tokens=30000 # Set explicit limit
)# Ensure requirements.txt is complete
pip freeze > requirements.txt
# Set required environment variables
gcloud run deploy my-agent \
--set-env-vars GOOGLE_API_KEY=your_key,AGENT_CONFIG=prod# 糟糕:描述模糊
def process(data):
"""Process data.""" # 过于通用
# 优秀:具体描述
def validate_email_format(email: str) -> bool:
"""检查邮箱地址是否符合有效格式(user@domain.com)。
仅使用此工具验证邮箱语法,请勿用于验证邮箱是否存在或可送达。"""# 添加max_iterations和显式终止条件
agent = LoopAgent(
tools=[...],
max_iterations=10, # 硬限制
break_condition=lambda result: result.get("completed", False)
)def robust_tool(param: str) -> str:
try:
result = risky_operation(param)
return f"Success: {result}"
except SpecificError as e:
return f"Operation failed: {e.message}"
except Exception as e:
logger.error(f"Unexpected error in robust_tool: {e}")
return "临时服务错误,请重试"# 使用Parallel Agent或异步工具
agent = ParallelAgent(
tools=[tool1, tool2, tool3] # 并发执行
)session = Session(
agent=my_agent,
max_history_turns=10, # 限制历史长度
context_window_tokens=30000 # 设置显式限制
)# 确保requirements.txt完整
pip freeze > requirements.txt
# 设置所需环境变量
gcloud run deploy my-agent \
--set-env-vars GOOGLE_API_KEY=your_key,AGENT_CONFIG=prodimport logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("google.adk")
logger.setLevel(logging.DEBUG)undefinedimport logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("google.adk")
logger.setLevel(logging.DEBUG)undefined
**3. Use web UI for interactive debugging:**
```bash
adk api_server --debug
**3. 使用Web UI进行交互式调试:**
```bash
adk api_server --debug
**4. Inspect agent execution trace:**
```python
response = agent.run("test query", return_trace=True)
print(response.trace) # Shows all tool calls and decisions
**4. 检查智能体执行追踪:**
```python
response = agent.run("test query", return_trace=True)
print(response.trace) # 显示所有工具调用与决策| Task | Rating | Description |
|---|---|---|
| Simple LlmAgent with tools | 2 | Basic conversational agent |
| Sequential Workflow Agent | 2 | Fixed-order tool execution |
| Parallel Workflow Agent | 3 | Concurrent operations |
| Loop Workflow Agent | 3 | Iterative refinement |
| Custom Agent | 3 | User-defined orchestration |
| Coordinator/Dispatcher (2-3 agents) | 4 | Multi-agent routing |
| Sequential Pipeline (3+ agents) | 4 | Chained agent execution |
| Hierarchical Multi-Agent (>5 agents) | 5 | Complex nested architecture |
| Custom tool development | 2 | Python function wrapper |
| OpenAPI tool integration | 2 | Auto-generated from spec |
| MCP tool integration | 3 | Cross-framework tools |
| Deployment to Agent Engine | 2 | Managed deployment |
| Self-hosted Docker deployment | 3 | Container orchestration |
| Advanced evaluation framework | 4 | Custom criteria and simulation |
| 任务 | 评级 | 描述 |
|---|---|---|
| 带工具的简单LlmAgent | 2 | 基础对话式智能体 |
| 顺序工作流智能体 | 2 | 固定顺序工具执行 |
| 并行工作流智能体 | 3 | 并发操作 |
| 循环工作流智能体 | 3 | 迭代优化 |
| 自定义智能体 | 3 | 用户定义编排 |
| 协调器/调度器(2-3个智能体) | 4 | 多智能体路由 |
| 顺序流水线(3+个智能体) | 4 | 链式智能体执行 |
| 层级多智能体(>5个) | 5 | 复杂嵌套架构 |
| 自定义工具开发 | 2 | Python函数包装 |
| OpenAPI工具集成 | 2 | 从规范自动生成 |
| MCP工具集成 | 3 | 跨框架工具 |
| 部署到Agent Engine | 2 | 托管部署 |
| 自托管Docker部署 | 3 | 容器编排 |
| 高级评估框架 | 4 | 自定义标准与模拟 |
pip install google-adkpip install google-adkn8napi-design-architectcloud-devops-expertn8napi-design-architectcloud-devops-expert