In the Agent Development Kit (ADK), an agent is an independent execution unit designed to act autonomously to achieve specific goals. Google ADK provides different types of agents that can be extended from the base Agent class.
The diagram illustrates the primary agent types in Google ADK:
For comprehensive documentation, tutorials, and API references, visit the official Google Agent Development Kit website:
Google ADK DocumentationGoogle has announced a Multi-Agent Interaction Communication Protocol (Agent to Agent, Protocol A to A) that enables agents from different vendors and platforms to communicate and collaborate. Along with this protocol, Google has open-sourced the Agent Developer Kit (ADK) and an agent marketplace.
ADK is a flexible, modular framework for developing and deploying AI agents. It works with popular LLMs and open-source AI tools, with special integration for Google's ecosystem and Gemini models. It allows developers to easily create simple agents powered by Gemini models and Google AI tools, while providing structure for more complex agent architectures.
The foundation of all agents in ADK is the Base Agent class, which can be extended in three main ways:
my_project) with a subdirectory (e.g.,
hello_adk)
.env (for API keys if needed)__init__.py (package initialization)agent.py (main engine file)# Import necessary packages from litellm import LiteLLM from google.adk.agent import Agent # Define LLM agent model = LiteLLM("ollama/qwen:7b") # Using Qwen model through Ollama agent = Agent( engine="LLM", name="Base Agent", description="A programming development assistant", instruction="You are a programming development assistant" )
my_project directoryLet's analyze the code structure for a Google ADK agent implementation.
#package的初始文件 from . import agent
This is a standard Python package initialization file that imports the agent module
from the current package. This makes the agent module accessible when importing the package. The
comment at the top indicates this is a package initialization file in Chinese.
#執行 adk web from google.adk.agents import LlmAgent from google.adk.models.lite_llm import LiteLlm root_agent = LlmAgent( model=LiteLlm(model="ollama/qwen2.5:latest"), name="base_agent", description=( "你是一位程式開發助手." ), instruction=( "你是一位程式開發助手" ), )
The agent.py file implements a Google ADK agent with the following components:
LlmAgent from google.adk.agents - this is a class
for creating language model-based agentsLiteLlm from google.adk.models.lite_llm - this is
a wrapper for connecting to various LLM providersroot_agent that instantiates an
LlmAgent with the following parameters:
model: Uses LiteLlm to connect to the Qwen 2.5 model via
Ollama (a local model server)name: Sets the agent's name to "base_agent"description: Provides a description in Chinese stating "You are a
programming development assistant"instruction: Sets instructions, also in Chinese, with the same message
Comparing the actual code to the tutorial example, there are several differences:
from litellm import LiteLLM and
from google.adk.agent import Agent
from google.adk.agents import LlmAgent and
from google.adk.models.lite_llm import LiteLlm
model = LiteLLM("ollama/qwen:7b") (using Qwen 7B)LiteLlm(model="ollama/qwen2.5:latest") (using the
newer Qwen 2.5 model)Agent with engine="LLM" parameterLlmAgent classThis suggests that the code uses a newer or different version of the Google ADK framework than what's described in the tutorial. The implemented agent is a language model-based agent that uses the Qwen 2.5 model through Ollama to act as a programming development assistant.
在代理開發工具包 (ADK) 中,代理程式是一個獨立的執行單元,旨在自主行動以實現特定目標。Google ADK 提供了不同類型的代理,可以從基本 Agent 類擴展。
該圖表說明了 Google ADK 中的主要代理類型:
Google 宣布了多代理互動通信協議(Agent to Agent, Protocol A to A),使不同供應商和平台的代理能夠互相溝通和協作。Google 同時開源了代理開發套件(ADK)和代理市集。
ADK 是一個用於開發和部署 AI 代理的靈活模組化框架。它可以與流行的 LLM 和開源 AI 工具一起使用,特別是與 Google 生態系統和 Gemini 模型緊密整合。它允許開發者輕鬆創建由 Gemini 模型和 Google AI 工具驅動的簡單代理,同時提供更複雜代理架構所需的結構。
ADK 中所有代理的基礎是 Base Agent 類別,可通過三種主要方式擴展:
my_project)和子目錄(例如 hello_adk).env(如需 API 密鑰)__init__.py(套件初始化)agent.py(主引擎文件)# 導入必要包 from litellm import LiteLLM from google.adk.agent import Agent # 定義 LLM 代理 model = LiteLLM("ollama/qwen:7b") # 通過 Ollama 使用千問模型 agent = Agent( engine="LLM", name="Base Agent", description="一位程式開發助手", instruction="你是一位程式開發助手" )
my_project 目錄運行代理讓我們分析 Google ADK 代理實現的代碼結構。
#package的初始文件 from . import agent
這是一個標準的 Python 包初始化文件,從當前包中導入 agent 模塊。這使得在導入包時可以訪問 agent 模塊。頂部的註釋說明這是一個包初始化文件。
#執行 adk web from google.adk.agents import LlmAgent from google.adk.models.lite_llm import LiteLlm root_agent = LlmAgent( model=LiteLlm(model="ollama/qwen2.5:latest"), name="base_agent", description=( "你是一位程式開發助手." ), instruction=( "你是一位程式開發助手" ), )
agent.py 文件實現了一個 Google ADK 代理,具有以下組件:
google.adk.agents 導入 LlmAgent - 這是用於創建基於語言模型的代理的類google.adk.models.lite_llm 導入 LiteLlm - 這是一個用於連接各種 LLM 提供商的包裝器
root_agent 的變量,它實例化了一個 LlmAgent,具有以下參數:
model:使用 LiteLlm 通過 Ollama(一個本地模型服務器)連接到 Qwen 2.5 模型name:將代理的名稱設置為 "base_agent"description:提供一個中文描述,說明 "你是一位程式開發助手"instruction:設置指令,同樣是中文,內容相同比較實際代碼與教程示例,有幾個差異:
from litellm import LiteLLM 和
from google.adk.agent import Agent
from google.adk.agents import LlmAgent 和
from google.adk.models.lite_llm import LiteLlm
model = LiteLLM("ollama/qwen:7b")(使用 Qwen 7B)LiteLlm(model="ollama/qwen2.5:latest")(使用更新的 Qwen 2.5 模型)Agent 並帶有 engine="LLM" 參數LlmAgent 類這表明代碼使用的是比教程中描述的更新或不同版本的 Google ADK 框架。實現的代理是一個基於語言模型的代理,它使用通過 Ollama 運行的 Qwen 2.5 模型來作為程式開發助手。