adk-skill

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Google Agent Development Kit (ADK) Guide

Google Agent Development Kit (ADK) 指南

Overview

概述

ADK is Google's open-source framework for building AI agents powered by Gemini models. It supports single-agent and multi-agent architectures with built-in tool integration, state management, callbacks, guardrails, and deployment options.
ADK是Google推出的开源框架,用于构建基于Gemini模型的AI Agent。它支持单Agent和多Agent架构,内置工具集成、状态管理、回调机制、防护措施以及部署选项。

Documentation & Resources

文档与资源

For up-to-date API references and detailed guides beyond this skill, always consult:
如需获取本技能之外的最新API参考和详细指南,请务必查阅:

Supported Languages

支持的语言

LanguagePackageInstall
Python
google-adk
pip install google-adk
Java
com.google.adk:google-adk
Maven/Gradle
Go
google.golang.org/adk
go get
TypeScript
@google/adk
npm install @google/adk
This guide shows Python examples. For Java, Go, and TypeScript patterns, see references/multi-language.md.
语言包名安装方式
Python
google-adk
pip install google-adk
Java
com.google.adk:google-adk
Maven/Gradle
Go
google.golang.org/adk
go get
TypeScript
@google/adk
npm install @google/adk
本指南展示Python示例。Java、Go和TypeScript的实现模式,请参阅references/multi-language.md

Quick Reference

快速参考

TaskApproach
Single agent
Agent
or
LlmAgent
with tools and instructions
Sequential pipeline
SequentialAgent
with ordered sub_agents
Parallel execution
ParallelAgent
with independent sub_agents
Iterative refinement
LoopAgent
with max_iterations or checker agent
Agent-as-toolWrap agent with
AgentTool
for on-demand delegation
Remote agent (A2A)
RemoteA2aAgent
+
to_a2a()
for cross-service agents
Custom toolsPython functions with type hints + docstrings
Structured outputPydantic model via
output_schema
+
output_key
State management
callback_context.state
and
tool_context.state
MCP integration
MCPToolset
with connection params
Testing
pytest
with
InMemoryRunner
EvaluationEvalSet with
.test.json
,
adk eval
CLI, pytest

任务实现方式
单Agent使用带工具和指令的
Agent
LlmAgent
顺序流水线使用包含有序子Agent的
SequentialAgent
并行执行使用包含独立子Agent的
ParallelAgent
迭代优化使用带max_iterations或检查器Agent的
LoopAgent
Agent作为工具使用
AgentTool
包装Agent以实现按需委托
远程Agent(A2A)使用
RemoteA2aAgent
+
to_a2a()
实现跨服务Agent
自定义工具带类型提示和文档字符串的Python函数
结构化输出通过
output_schema
+
output_key
使用Pydantic模型
状态管理使用
callback_context.state
tool_context.state
MCP集成使用带连接参数的
MCPToolset
测试使用
pytest
InMemoryRunner
评估使用带
.test.json
的EvalSet、
adk eval
CLI或pytest

Project Structure

项目结构

Every ADK project follows this layout:
my_agent/
├── my_agent/
│   ├── __init__.py          # Must import agent module
│   ├── agent.py             # Defines root_agent (entry point)
│   ├── prompts.py           # Instruction strings (optional)
│   ├── tools.py             # Custom tool functions (optional)
│   ├── sub_agents/          # Sub-agent packages (optional)
│   └── shared_libraries/    # Callbacks, utilities (optional)
├── tests/
│   └── test_agent.py
├── pyproject.toml
└── .env                     # GOOGLE_API_KEY or GOOGLE_CLOUD_PROJECT
每个ADK项目都遵循以下布局:
my_agent/
├── my_agent/
│   ├── __init__.py          # 必须导入agent模块
│   ├── agent.py             # 定义root_agent(入口点)
│   ├── prompts.py           # 指令字符串(可选)
│   ├── tools.py             # 自定义工具函数(可选)
│   ├── sub_agents/          # 子Agent包(可选)
│   └── shared_libraries/    # 回调函数、工具库(可选)
├── tests/
│   └── test_agent.py
├── pyproject.toml
└── .env                     # GOOGLE_API_KEY或GOOGLE_CLOUD_PROJECT

Critical: init.py

关键文件:init.py

python
undefined
python
undefined

my_agent/init.py

my_agent/init.py

from . import agent
undefined
from . import agent
undefined

Critical: root_agent

关键:root_agent

The
root_agent
variable at module level is the framework entry point:
python
undefined
模块级别的
root_agent
变量是框架的入口点:
python
undefined

my_agent/agent.py

my_agent/agent.py

from google.adk.agents import Agent
root_agent = Agent( name="my_agent", model="gemini-2.5-flash", description="Brief description for agent discovery", instruction="Detailed system prompt...", tools=[...], )
undefined
from google.adk.agents import Agent
root_agent = Agent( name="my_agent", model="gemini-2.5-flash", description="用于Agent发现的简短描述", instruction="详细的系统提示词...", tools=[...], )
undefined

pyproject.toml

pyproject.toml

toml
[project]
name = "my-agent"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = ["google-adk"]

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

toml
[project]
name = "my-agent"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = ["google-adk"]

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

Agent Types

Agent类型

1. LlmAgent (Single Agent)

1. LlmAgent(单Agent)

The fundamental building block. Wraps a single LLM call with tools and instructions.
python
from google.adk.agents import LlmAgent

agent = LlmAgent(
    name="assistant",
    model="gemini-2.5-flash",
    description="General assistant",
    instruction="""You are a helpful assistant.
    Use the search tool when you need current information.""",
    tools=[search_tool],
    output_schema=ResponseModel,   # Optional structured output
    output_key="response",         # State key for output
    generate_content_config=types.GenerateContentConfig(
        temperature=0.7,
    ),
)
基础构建模块。将单次LLM调用与工具和指令封装在一起。
python
from google.adk.agents import LlmAgent

agent = LlmAgent(
    name="assistant",
    model="gemini-2.5-flash",
    description="通用助手",
    instruction="""你是一个乐于助人的助手。
    需要当前信息时,请使用搜索工具。""",
    tools=[search_tool],
    output_schema=ResponseModel,   # 可选的结构化输出
    output_key="response",         # 用于存储输出的状态键
    generate_content_config=types.GenerateContentConfig(
        temperature=0.7,
    ),
)

2. SequentialAgent

2. SequentialAgent

Runs sub-agents in order. Output of each flows to the next via shared state.
python
from google.adk.agents import SequentialAgent

pipeline = SequentialAgent(
    name="research_pipeline",
    description="Research then summarize",
    sub_agents=[
        researcher_agent,    # Step 1: writes to state["research"]
        summarizer_agent,    # Step 2: reads state["research"]
    ],
)
按顺序运行子Agent。每个Agent的输出通过共享状态传递给下一个。
python
from google.adk.agents import SequentialAgent

pipeline = SequentialAgent(
    name="research_pipeline",
    description="先研究再总结",
    sub_agents=[
        researcher_agent,    # 步骤1:写入state["research"]
        summarizer_agent,    # 步骤2:读取state["research"]
    ],
)

3. ParallelAgent

3. ParallelAgent

Runs sub-agents concurrently. Use for independent tasks.
python
from google.adk.agents import ParallelAgent

parallel = ParallelAgent(
    name="multi_channel",
    description="Send to all channels simultaneously",
    sub_agents=[
        email_agent,
        slack_agent,
        calendar_agent,
    ],
)
并发运行子Agent。适用于独立任务。
python
from google.adk.agents import ParallelAgent

parallel = ParallelAgent(
    name="multi_channel",
    description="同时发送到所有渠道",
    sub_agents=[
        email_agent,
        slack_agent,
        calendar_agent,
    ],
)

4. LoopAgent

4. LoopAgent

Repeats sub-agents until termination. Two termination patterns:
Pattern A: Fixed iterations
python
from google.adk.agents import LoopAgent

loop = LoopAgent(
    name="refinement_loop",
    description="Iteratively refine output",
    sub_agents=[writer_agent, critic_agent],
    max_iterations=3,
)
Pattern B: Checker agent with escalate
python
undefined
重复运行子Agent直到终止。有两种终止模式:
模式A:固定迭代次数
python
from google.adk.agents import LoopAgent

loop = LoopAgent(
    name="refinement_loop",
    description="迭代优化输出",
    sub_agents=[writer_agent, critic_agent],
    max_iterations=3,
)
模式B:带升级机制的检查器Agent
python
undefined

The checker agent uses tool_context.actions.escalate = True to stop

检查器Agent使用tool_context.actions.escalate = True来停止循环

def check_quality(score: float, tool_context: ToolContext) -> str: """Check if quality meets threshold.""" if score >= 0.9: tool_context.actions.escalate = True return "Quality threshold met, stopping loop." return "Quality below threshold, continuing refinement."
checker = Agent( name="checker", model="gemini-2.5-flash", instruction="Evaluate the output quality and call check_quality.", tools=[check_quality], )
loop = LoopAgent( name="quality_loop", sub_agents=[generator_agent, checker], )
undefined
def check_quality(score: float, tool_context: ToolContext) -> str: """检查质量是否达到阈值。""" if score >= 0.9: tool_context.actions.escalate = True return "质量阈值已满足,停止循环。" return "质量未达阈值,继续优化。"
checker = Agent( name="checker", model="gemini-2.5-flash", instruction="评估输出质量并调用check_quality。", tools=[check_quality], )
loop = LoopAgent( name="quality_loop", sub_agents=[generator_agent, checker], )
undefined

5. Composing Agent Types

5. 组合Agent类型

Nest agent types freely for complex workflows. Example:
SequentialAgent
containing a
ParallelAgent
containing
LlmAgent
s. See references/advanced-patterns.md for hierarchical workflow examples.

可自由嵌套Agent类型以实现复杂工作流。例如:包含
ParallelAgent
SequentialAgent
,而
ParallelAgent
中又包含多个
LlmAgent
。有关分层工作流示例,请参阅references/advanced-patterns.md

Tools

工具

Function Tools

函数工具

Any Python function with type hints and a docstring becomes a tool:
python
def get_weather(city: str, units: str = "celsius") -> dict:
    """Get current weather for a city.

    Args:
        city: The city name to look up weather for.
        units: Temperature units - 'celsius' or 'fahrenheit'.

    Returns:
        dict with temperature, conditions, and humidity.
    """
    # Implementation
    return {"temperature": 22, "conditions": "sunny", "humidity": 45}

agent = Agent(
    name="weather_agent",
    model="gemini-2.5-flash",
    instruction="Help users check the weather.",
    tools=[get_weather],
)
Requirements:
  • Type hints on all parameters
  • Docstring with description and Args section
  • Return type annotation
任何带类型提示和文档字符串的Python函数都可以成为工具:
python
def get_weather(city: str, units: str = "celsius") -> dict:
    """获取城市当前天气。

    参数:
        city: 要查询天气的城市名称。
        units: 温度单位 - 'celsius'或'fahrenheit'。

    返回:
        包含温度、天气状况和湿度的字典。
    """
    # 实现代码
    return {"temperature": 22, "conditions": "sunny", "humidity": 45}

agent = Agent(
    name="weather_agent",
    model="gemini-2.5-flash",
    instruction="帮助用户查询天气。",
    tools=[get_weather],
)
要求:
  • 所有参数都有类型提示
  • 包含描述和参数部分的文档字符串
  • 有返回类型注解

Tools with State Access

带状态访问的工具

Use
ToolContext
to read/write session state:
python
from google.adk.tools import ToolContext

def add_to_cart(item: str, quantity: int, tool_context: ToolContext) -> dict:
    """Add an item to the shopping cart."""
    cart = tool_context.state.get("cart", [])
    cart.append({"item": item, "quantity": quantity})
    tool_context.state["cart"] = cart
    return {"status": "added", "cart_size": len(cart)}
使用
ToolContext
读取/写入会话状态:
python
from google.adk.tools import ToolContext

def add_to_cart(item: str, quantity: int, tool_context: ToolContext) -> dict:
    """将商品添加到购物车。"""
    cart = tool_context.state.get("cart", [])
    cart.append({"item": item, "quantity": quantity})
    tool_context.state["cart"] = cart
    return {"status": "added", "cart_size": len(cart)}

AgentTool (Agent-as-Tool)

AgentTool(Agent作为工具)

Wrap an agent to use it as a tool for another agent:
python
from google.adk.tools.agent_tool import AgentTool

specialist = Agent(
    name="code_reviewer",
    model="gemini-2.5-pro",
    instruction="Review code for bugs and best practices.",
)

coordinator = Agent(
    name="coordinator",
    model="gemini-2.5-flash",
    instruction="Coordinate tasks. Use code_reviewer for code reviews.",
    tools=[AgentTool(agent=specialist)],
)
包装一个Agent,使其成为另一个Agent的工具:
python
from google.adk.tools.agent_tool import AgentTool

specialist = Agent(
    name="code_reviewer",
    model="gemini-2.5-pro",
    instruction="检查代码中的漏洞和最佳实践。",
)

coordinator = Agent(
    name="coordinator",
    model="gemini-2.5-flash",
    instruction="协调任务。代码评审请使用code_reviewer。",
    tools=[AgentTool(agent=specialist)],
)

Built-in Tools

内置工具

python
from google.adk.tools import google_search

agent = Agent(
    name="researcher",
    tools=[google_search],
)
python
from google.adk.tools import google_search

agent = Agent(
    name="researcher",
    tools=[google_search],
)

MCP Tools

MCP工具

python
from google.adk.tools.mcp_tool import MCPToolset, StdioConnectionParams
from mcp import StdioServerParameters

agent = Agent(
    name="db_agent",
    tools=[
        MCPToolset(
            connection_params=StdioConnectionParams(
                server_params=StdioServerParameters(
                    command="npx",
                    args=["-y", "some-mcp-server"],
                ),
            ),
        ),
    ],
)
For advanced tool patterns (FunctionTool, ToolboxToolset, long-running tools), see references/tools-reference.md.

python
from google.adk.tools.mcp_tool import MCPToolset, StdioConnectionParams
from mcp import StdioServerParameters

agent = Agent(
    name="db_agent",
    tools=[
        MCPToolset(
            connection_params=StdioConnectionParams(
                server_params=StdioServerParameters(
                    command="npx",
                    args=["-y", "some-mcp-server"],
                ),
            ),
        ),
    ],
)
有关高级工具模式(FunctionTool、ToolboxToolset、长运行工具),请参阅references/tools-reference.md

Callbacks

回调函数

Callbacks intercept the agent lifecycle. Return
None
to proceed, return a value to short-circuit.
CallbackSignatureUse Case
before_agent_callback
(CallbackContext)
Initialize state
before_tool_callback
(BaseTool, dict, CallbackContext) -> dict|None
Validate inputs, auto-approve
after_tool_callback
(BaseTool, dict, ToolContext, dict) -> dict|None
Post-process results
before_model_callback
(CallbackContext, LlmRequest)
Rate limit, safety filter
python
def before_tool(tool, args, tool_context) -> dict | None:
    """Return dict to skip tool execution with that response."""
    if tool.name == "approve_discount" and args.get("value", 0) > 50:
        return {"status": "rejected", "reason": "Discount too large"}
    return None  # Proceed normally

agent = Agent(
    name="guarded_agent",
    model="gemini-2.5-flash",
    instruction="...",
    before_tool_callback=before_tool,
)
For rate limiting, input validation, and safety callbacks, see references/advanced-patterns.md.

回调函数可拦截Agent的生命周期。返回
None
表示继续执行,返回值则表示短路执行(跳过后续步骤)。
回调函数签名使用场景
before_agent_callback
(CallbackContext)
初始化状态
before_tool_callback
(BaseTool, dict, CallbackContext) -> dict|None
验证输入、自动批准
after_tool_callback
(BaseTool, dict, ToolContext, dict) -> dict|None
后处理结果
before_model_callback
(CallbackContext, LlmRequest)
速率限制、安全过滤
python
def before_tool(tool, args, tool_context) -> dict | None:
    """返回字典以跳过工具执行,直接使用该响应。"""
    if tool.name == "approve_discount" and args.get("value", 0) > 50:
        return {"status": "rejected", "reason": "折扣过大"}
    return None  # 正常继续执行

agent = Agent(
    name="guarded_agent",
    model="gemini-2.5-flash",
    instruction="...",
    before_tool_callback=before_tool,
)
有关速率限制、输入验证和安全回调的内容,请参阅references/advanced-patterns.md

State Management

状态管理

State is a shared dictionary across agents, tools, and callbacks. Scopes:
state["key"]
(session),
app:key
(app-wide),
user:key
(user-wide).
Passing data between agents: Use
output_key
to write to state, read in next agent's instruction:
python
researcher = Agent(name="researcher", output_key="findings", output_schema=ResearchOutput, ...)
writer = Agent(name="writer", instruction="Write report based on state['findings'].", ...)
pipeline = SequentialAgent(name="pipeline", sub_agents=[researcher, writer])

状态是Agent、工具和回调函数之间共享的字典。作用域包括:
state["key"]
(会话级)、
app:key
(应用级)、
user:key
(用户级)。
在Agent之间传递数据: 使用
output_key
写入状态,在下一个Agent的指令中读取:
python
researcher = Agent(name="researcher", output_key="findings", output_schema=ResearchOutput, ...)
writer = Agent(name="writer", instruction="基于state['findings']撰写报告。", ...)
pipeline = SequentialAgent(name="pipeline", sub_agents=[researcher, writer])

Structured Output

结构化输出

Use Pydantic models for typed, validated agent output:
python
from pydantic import BaseModel

class AnalysisResult(BaseModel):
    summary: str
    key_findings: list[str]
    confidence: float
    recommendations: list[str]

agent = Agent(
    name="analyzer",
    model="gemini-2.5-flash",
    instruction="Analyze the provided data and return structured results.",
    output_schema=AnalysisResult,
    output_key="analysis",  # Stored in state["analysis"]
)

使用Pydantic模型获取类型化、经过验证的Agent输出:
python
from pydantic import BaseModel

class AnalysisResult(BaseModel):
    summary: str
    key_findings: list[str]
    confidence: float
    recommendations: list[str]

agent = Agent(
    name="analyzer",
    model="gemini-2.5-flash",
    instruction="分析提供的数据并返回结构化结果。",
    output_schema=AnalysisResult,
    output_key="analysis",  # 存储在state["analysis"]中
)

Running and Testing

运行与测试

Local Development

本地开发

bash
undefined
bash
undefined

Install

安装

pip install google-adk
pip install google-adk

Set API key

设置API密钥

export GOOGLE_API_KEY="your-key"
export GOOGLE_API_KEY="your-key"

Run interactively

交互式运行

adk run my_agent
adk run my_agent

Run with web UI

带Web UI运行

adk web my_agent
undefined
adk web my_agent
undefined

Testing with InMemoryRunner

使用InMemoryRunner测试

python
import pytest
from google.adk.runners import InMemoryRunner
from google.genai import types

@pytest.mark.asyncio
async def test_agent():
    runner = InMemoryRunner(agent=root_agent, app_name="test")
    session = await runner.session_service.create_session(
        user_id="test_user", app_name="test",
    )
    content = types.Content(
        role="user", parts=[types.Part.from_text(text="Hello")],
    )
    events = []
    async for event in runner.run_async(
        user_id="test_user", session_id=session.id, new_message=content,
    ):
        events.append(event)
    assert "expected" in events[-1].content.parts[0].text.lower()
python
import pytest
from google.adk.runners import InMemoryRunner
from google.genai import types

@pytest.mark.asyncio
async def test_agent():
    runner = InMemoryRunner(agent=root_agent, app_name="test")
    session = await runner.session_service.create_session(
        user_id="test_user", app_name="test",
    )
    content = types.Content(
        role="user", parts=[types.Part.from_text(text="Hello")],
    )
    events = []
    async for event in runner.run_async(
        user_id="test_user", session_id=session.id, new_message=content,
    ):
        events.append(event)
    assert "expected" in events[-1].content.parts[0].text.lower()

Evaluation

评估

ADK provides built-in evaluation for tool correctness, response quality, and safety. Define eval cases in
.test.json
files and run with
adk eval
,
pytest
, or the web UI. See references/evaluation.md for eval data formats, all 8 metrics, and patterns.

ADK内置了工具正确性、响应质量和安全性的评估功能。在
.test.json
文件中定义评估用例,然后使用
adk eval
pytest
或Web UI运行评估。有关评估数据格式、全部8项指标和模式,请参阅references/evaluation.md

Model Selection

模型选择

  • gemini-2.5-flash
    - Default, fast, cost-effective (temperature 0.1-0.7)
  • gemini-2.5-pro
    - Complex reasoning, code review (temperature 0.1-0.4)
Configure per-agent via
generate_content_config=types.GenerateContentConfig(temperature=0.2)
.

  • gemini-2.5-flash
    - 默认选项,速度快、成本低(温度值0.1-0.7)
  • gemini-2.5-pro
    - 适用于复杂推理、代码评审(温度值0.1-0.4)
可通过
generate_content_config=types.GenerateContentConfig(temperature=0.2)
为每个Agent单独配置。

Design Patterns

设计模式

PatternWhen to UseADK Implementation
Sequential pipelineMulti-step tasks with dependencies
SequentialAgent
with ordered sub-agents
Fan-out / Fan-inIndependent tasks then synthesis
ParallelAgent
→ merger
Agent
Reflection loopQuality matters more than speed
LoopAgent
with producer + critic agents
Dynamic routingDiverse inputs need different handlingParent
Agent
with
sub_agents
(Auto-Flow)
Layered fallbackTool failures need graceful recovery
SequentialAgent
: primary → fallback → response
Guardrailed agentSafety/compliance requirements
before_model_callback
+
before_tool_callback
Resource tieringCost optimization under constraintsDifferent
model
per agent (Pro vs Flash)
Key design rules:
  • One agent = one responsibility. Split agents with 5+ tools into specialists.
  • Use
    output_key
    for structured data flow between agents via state -- not free text.
  • Always set
    max_iterations
    on
    LoopAgent
    to prevent unbounded execution.
  • Separate generation from evaluation -- use a different agent to critique output (avoids self-review bias).
  • Write sub-agent
    description
    fields carefully -- they drive Auto-Flow routing decisions.
  • Use structured output (JSON/Pydantic) between pipeline stages for reliable data passing.
  • Embed reasoning steps in agent instructions: "1. Analyze → 2. Plan → 3. Execute → 4. Verify".
  • Always include a fallback route for unclear inputs -- ambiguous requests must not be silently misrouted.
For hierarchical workflows, agent transfer, and deployment patterns, see references/advanced-patterns.md. For comprehensive design patterns (chaining, reflection, planning, memory, error handling, HITL, guardrails, RAG, resource optimization, reasoning, evaluation, prompting), see references/design-patterns.md. For A2A (Agent-to-Agent) protocol patterns -- exposing agents as A2A servers, consuming remote agents with
RemoteA2aAgent
, agent cards, and cross-service communication -- see references/a2a-protocol.md.

模式使用场景ADK实现方式
顺序流水线有依赖关系的多步骤任务包含有序子Agent的
SequentialAgent
扇出/扇入独立任务后进行结果合成
ParallelAgent
→ 合并Agent
反射循环质量优先于速度的场景包含生成器+评审Agent的
LoopAgent
动态路由多样化输入需要不同处理方式包含
sub_agents
的父Agent(自动流)
分层降级工具故障时需要优雅恢复
SequentialAgent
:主工具→备用工具→响应
防护型Agent有安全/合规要求的场景
before_model_callback
+
before_tool_callback
资源分层约束条件下的成本优化为不同Agent使用不同
model
(Pro vs Flash)
关键设计规则:
  • 一个Agent对应一个职责。将包含5个以上工具的Agent拆分为多个专业Agent。
  • 使用
    output_key
    通过状态在Agent之间传递结构化数据——而非自由文本。
  • 始终为
    LoopAgent
    设置
    max_iterations
    以防止无限执行。
  • 将生成与评估分离——使用不同的Agent评审输出(避免自我评审偏差)。
  • 仔细编写子Agent的
    description
    字段——它们会驱动自动流的路由决策。
  • 在流水线阶段之间使用结构化输出(JSON/Pydantic)以确保可靠的数据传递。
  • 在Agent指令中嵌入推理步骤:"1. 分析 → 2. 规划 → 3. 执行 → 4. 验证"。
  • 始终为不明确的输入提供降级路由——模糊请求不能被静默错误路由。
有关分层工作流、Agent迁移和部署模式,请参阅references/advanced-patterns.md。 有关全面的设计模式(链式调用、反射、规划、记忆、错误处理、人在回路、防护措施、RAG、资源优化、推理、评估、提示词工程),请参阅references/design-patterns.md。 有关A2A(Agent-to-Agent)协议模式——将Agent暴露为A2A服务器、使用
RemoteA2aAgent
消费远程Agent、Agent卡片和跨服务通信,请参阅references/a2a-protocol.md

Decision Guide

决策指南

When to use which agent type:
Single task, one LLM call? → Agent / LlmAgent
Steps must run in order? → SequentialAgent
Steps are independent? → ParallelAgent
Need iteration/refinement? → LoopAgent
Need on-demand delegation? → AgentTool
Remote agent, different service? → RemoteA2aAgent (A2A)
Complex multi-stage? → Compose agent types
When to use which tool type:
Simple function? → Python function with type hints
Need state access? → Add ToolContext parameter
Delegate to another agent? → AgentTool
Remote agent over network? → RemoteA2aAgent (A2A protocol)
External MCP server? → MCPToolset
Database access? → ToolboxToolset
Web search? → google_search (built-in)
如何选择Agent类型:
单一任务,单次LLM调用? → Agent / LlmAgent
步骤必须按顺序执行? → SequentialAgent
步骤相互独立? → ParallelAgent
需要迭代/优化? → LoopAgent
需要按需委托? → AgentTool
远程Agent,不同服务? → RemoteA2aAgent(A2A)
复杂多阶段任务? → 组合多种Agent类型
如何选择工具类型:
简单函数? → 带类型提示的Python函数
需要访问状态? → 添加ToolContext参数
委托给另一个Agent? → AgentTool
网络上的远程Agent? → RemoteA2aAgent(A2A协议)
外部MCP服务器? → MCPToolset
数据库访问? → ToolboxToolset
网页搜索? → google_search(内置工具)