AI 领域发展迅速,已不再满足于单一目的模型,而是转向智能、自主的多智能体系统。然而,构建这些多智能体系统带来了全新的挑战。这便是为什么我们今天会在 2025 年 Google Cloud NEXT 大会上推出智能体开发套件 (ADK),这是 Google 的一个全新开源框架,旨在简化智能体和多智能体系统的全栈端到端开发。像您这样的开发者能够借助 ADK 以更大的灵活性和精确的控制手段构建生产就绪型智能体应用。
Agentspace 和 Google Customer Engagement Suite (CES) 等 Google 产品便是采用 ADK 来为自身智能体提供支持的。通过将 ADK 开源,我们旨在为开发者提供强大、灵活的工具,以便他们在快速发展的智能体领域中构建项目。ADK 在设计时充分考虑了灵活性,可使用不同模型,针对不同部署环境构建生产就绪型智能体。
ADK 可在整个智能体开发生命周期中提供以下功能:
顺序
、并行
、循环
)为可预测流水线定义工作流,或利用 LLM 驱动的动态路由(LlmAgent
传输)开发自适应行为。虽然我们鼓励您探索文档中的示例,但核心思想还是 Python 式简洁。您负责定义智能体的逻辑、可使用工具及其处理信息的方式。ADK 则提供用于管理状态、编排工具调用以及与底层 LLM 交互的结构。下面是一个基础智能体的说明性示例。
您可以在快速入门指南中找到相关代码。
from google.adk.agents import LlmAgent
from google.adk.tools import google_Search
dice_agent = LlmAgent(
model="gemini-2.0-flash-exp", # Required: Specify the LLM
name="question_answer_agent", # Requdired: Unique agent name
description="A helpful assistant agent that can answer questions.",
instruction="""Respond to the query using google search""",
tools=[google_search], # Provide an instance of the tool
)
# you can run this by using adk web
这个简单示例展示了基础结构。如果您需要构建涉及多个智能体、复杂工具使用以及动态编排的复杂应用,同时又需要保持掌控,ADK 真的是很理想的工具。
ADK 可让您灵活选择与智能体交互的方式:CLI、Web 界面、API 服务器和 API (Python)。无论您选择哪种交互方式,您定义智能体的方式(agent.py
中的核心逻辑)都是一样的。不同之处在于您如何发起和管理交互。您可以在 ADK 文档中找到所有示例。
当您不再满足于单个智能体,而是想要构建可利用各种工具的协作式多智能体系统时,ADK 会是很理想的工具。不妨想象一下,您可创建一个专用智能体团队,其中的主要智能体可以根据对话委派任务。ADK 可通过分层结构和智能路由助您轻松实现此构想。
来看看以下说明性示例:WeatherAgent
可处理天气查询,但会将问候委托给专用的GreetingAgent。
1. 定义工具:智能体使用工具来执行操作。此处,我们的 WeatherAgent
需要工具来获取天气数据。我们定义了一个 Python 函数;ADK 会使用其文档字符串
来了解何时以及如何使用它。
def get_weather(city: str) -> Dict:
# Best Practice: Log tool execution for easier debugging
print(f"--- Tool: get_weather called for city: {city} ---")
city_normalized = city.lower().replace(" ", "") # Basic input normalization
# Mock weather data for simplicity (matching Step 1 structure)
mock_weather_db = {
"newyork": {"status": "success", "report": "The weather in New York is sunny with a temperature of 25°C."},
"london": {"status": "success", "report": "It's cloudy in London with a temperature of 15°C."},
"tokyo": {"status": "success", "report": "Tokyo is experiencing light rain and a temperature of 18°C."},
"chicago": {"status": "success", "report": "The weather in Chicago is sunny with a temperature of 25°C."},
"toronto": {"status": "success", "report": "It's partly cloudy in Toronto with a temperature of 30°C."},
"chennai": {"status": "success", "report": "It's rainy in Chennai with a temperature of 15°C."},
}
# Best Practice: Handle potential errors gracefully within the tool
if city_normalized in mock_weather_db:
return mock_weather_db[city_normalized]
else:
return {"status": "error", "error_message": f"Sorry, I don't have weather information for '{city}'."}
2. 定义智能体及它们之间关系:我们使用 LlmAgent
来创建智能体。请密切注意指令和描述字段,LLM 在了解角色并使用子智能体的自动委派功能做出委派决策时,会严重依赖这些内容。
greeting_agent = Agent(
model=LiteLlm(model="anthropic/claude-3-sonnet-20240229"),
name="greeting_agent",
instruction="You are the Greeting Agent. Your ONLY task is to provide a friendly greeting to the user. " "Do not engage in any other conversation or tasks.",
# Crucial for delegation: Clear description of capability
description="Handles simple greetings and hellos",
)
farewell_agent = Agent(
model=LiteLlm(model="anthropic/claude-3-sonnet-20240229"),
name="farewell_agent",
instruction="You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message. "
"Do not perform any other actions.",
# Crucial for delegation: Clear description of capability
description="Handles simple farewells and goodbyes",
)
root_agent = Agent(
name="weather_agent_v2",
model="gemini-2.0-flash-exp",
description="You are the main Weather Agent, coordinating a team. - Your main task: Provide weather using the `get_weather` tool. Handle its 'status' response ('report' or 'error_message'). - Delegation Rules: - If the user gives a simple greeting (like 'Hi', 'Hello'), delegate to `greeting_agent`. - If the user gives a simple farewell (like 'Bye', 'See you'), delegate to `farewell_agent`. - Handle weather requests yourself using `get_weather`. - For other queries, state clearly if you cannot handle them.",
tools=[get_weather], # Root agent still needs the weather tool
sub_agents=[greeting_agent, farewell_agent]
)
描述
以及相关智能体(在层次结构中定义的父/子智能体)的描述
字段。GreetingAgent
的描述相匹配),便会发起转接流程。清晰、鲜明的描述至关重要!LLM 可使用它们来有效地委派任务。
在此设置中,如果用户以“Hi”开头,则 WeatherAgent
(如果是处理输入的根智能体)会识别出那不是天气查询,并根据 GreetingAgent
的描述确定它更适用,然后自动转移控制权。如果用户询问“芝加哥天气如何?”,WeatherAgent
便会直接使用 get_weather
工具处理查询。
此示例演示了 ADK 的层次结构和描述驱动型委派功能可如何助您构建有组织、可维护的复杂多智能体应用。
构建 WeatherAgent 等智能体只是基础操作,但将它们可靠地提供给用户却涉及到关键的后续步骤:严格的评估和无缝部署。在智能体上线之前,应务必确保其行为可预测且正确。ADK 的集成式评估工具正是为此而设计的,可让您根据预定义数据集(例如 evaluation.test.json
或 test.json
)系统地测试执行路径和响应质量。您可以使用 AgentEvaluator.evaluate()
在测试套件中以编程方式运行这些检查。您也可以直接通过 ADK 评估命令行工具或 Web 界面使用评估功能。
在您对性能感到满意后,ADK 可选择部署到任何容器运行时或使用其与 Vertex AI Agent Engine 的集成,为生产提供一条清晰的简化路径。您可借此利用全托管式可扩展企业级运行时,完成开发生命周期,将复杂的原型转变为强大的生产就绪型智能体应用。
在您借助 ADK 探索构建多智能体系统的各种可能性时,您可能想知道它在更广泛的 Google GenAI 开发工具领域中处于何种地位。虽然有多种 SDK 和框架可供使用(例如 Genkit 框架),但了解 ADK 的相对关注重点会对工具选择有所帮助。以下是一个简短比较:
最终,最佳选择取决于项目的具体目标。如果您要在明确定义的框架内构建复杂的协作式智能体系统,则 ADK 可为您提供强大的解决方案。对于许多其他需要灵活性和广泛模型支持的 GenAI 项目,Genkit 是一个很好的选择。
虽然智能体开发套件 (ADK) 极具灵活性,可配合各种工具使用,但它仅针对 Google Cloud 生态系统内的无缝集成进行了优化,特别是与 Gemini 模型和 Vertex AI 的无缝集成。这种量身定制的设计使开发者能够充分利用 Gemini 的先进功能,例如 Gemini 2.5 Pro Experimental 中的增强型推理和工具使用。这种设计还提供了一种直接的原生路径,可将这些智能体部署到 Vertex AI 的全代管式企业级运行时中,从而实现可扩展性。
最重要的是,这种深度集成可以扩展到更广泛的企业领域;ADK 使智能体能够通过 100 多个预构建的连接器直接连接系统和数据,利用通过 Application Integration 构建的工作流,以及访问存储在 AlloyDB、BigQuery 和 NetApp 等系统中的数据,而无需复制数据。
此外,使用 ADK 构建的智能体可以安全地利用通过 Apigee 管理的组织现有 API 投资,并通过利用已建立的界面进一步增强其功能。
通过这种包含先进 AI 模型、可扩展部署、多样化数据源和现有 API 的全面连接,当 ADK 在 Google Cloud 环境中使用时,它会变得非常强大。
智能体开发套件 (ADK) 可为构建新一代 AI 应用提供强大、灵活的开源基础。它通过提供以下功能来应对多智能体开发的核心挑战:
我们很期待看到您使用 ADK 构建的项目!
探索代码:官方 ADK 文档。