跳转到内容

Agent Platform 为 ADK(Application Development Kit)代理程序提供了托管的模型(即预先训练好的机器学习模型)。

为了实现企业级可扩展性、可靠性以及与 Google Cloud 的 MLOps 生态系统的集成,您可以将模型部署到 Agent Platform 的终端节点上。这些模型可以来自 Model Garden,也可以是你自己精心调优的模型。

集成方法: 传递完整的 Agent Platform Endpoint 资源字符串。projects/PROJECT_ID/locations/LOCATION/endpoints/ENDPOINT_ID)直接发送到 model “parameter of” 的意思是“……的参数”。 LlmAgent.

代理平台设置(Agent Platform Setup)

有关将 ADK 代理连接到由 Google Cloud 托管的模型和服务的更多详细信息(包括 Gemini Enterprise Agent Platform),请参阅…… 连接到 Google Cloud 和 Agent Platform。 guide.

Model Garden 部署方案

在 ADK 中得到支持。Python v0.2.0Java v0.1.0

您可以从以下资源中部署各种开源或专有的模型: Model Garden 发送到某个端点(endpoint)。

示例:

from google.adk.agents import LlmAgent
from google.genai import types # For config objects

# --- Example Agent using a Llama 3 model deployed from Model Garden ---

# Replace with your actual Agent Platform Endpoint resource name
llama3_endpoint = "projects/YOUR_PROJECT_ID/locations/us-central1/endpoints/YOUR_LLAMA3_ENDPOINT_ID"

agent_llama3_vertex = LlmAgent(
    model=llama3_endpoint,
    name="llama3_vertex_agent",
    instruction="You are a helpful assistant based on Llama 3, hosted on Agent Platform.",
    generate_content_config=types.GenerateContentConfig(max_output_tokens=2048),
    # ... other agent parameters
)
import com.google.adk.agents.LlmAgent;
import com.google.adk.models.Gemini;
import com.google.genai.types.GenerateContentConfig;

// ...

// Replace with your actual Agent Platform Endpoint resource name
String llama3Endpoint = "projects/YOUR_PROJECT_ID/locations/us-central1/endpoints/YOUR_LLAMA3_ENDPOINT_ID";

LlmAgent agentLlama3Vertex = LlmAgent.builder()
    .model(Gemini.builder()
        .modelName(llama3Endpoint)
        .build())
    .name("llama3_vertex_agent")
    .instruction("You are a helpful assistant based on Llama 3, hosted on Agent Platform.")
    .generateContentConfig(GenerateContentConfig.builder()
        .maxOutputTokens(2048)
        .build())
    // ... other agent parameters
    .build();

经过微调的模型端点(Fine-tuned Model Endpoints)

在 ADK 中得到支持。Python v0.2.0Java v0.1.0

部署经过微调的模型(无论是基于 Gemini 架构,还是 Agent Platform 支持的其他架构)后,会生成一个可以直接使用的终端点(endpoint)。

示例:

from google.adk.agents import LlmAgent

# --- Example Agent using a fine-tuned Gemini model endpoint ---

# Replace with your fine-tuned model's endpoint resource name
finetuned_gemini_endpoint = "projects/YOUR_PROJECT_ID/locations/us-central1/endpoints/YOUR_FINETUNED_ENDPOINT_ID"

agent_finetuned_gemini = LlmAgent(
    model=finetuned_gemini_endpoint,
    name="finetuned_gemini_agent",
    instruction="You are a specialized assistant trained on specific data.",
    # ... other agent parameters
)
import com.google.adk.agents.LlmAgent;
import com.google.adk.models.Gemini;

// ...

// Replace with your fine-tuned model's endpoint resource name
String finetunedGeminiEndpoint = "projects/YOUR_PROJECT_ID/locations/us-central1/endpoints/YOUR_FINETUNED_ENDPOINT_ID";

LlmAgent agentFinetunedGemini = LlmAgent.builder()
    .model(Gemini.builder()
        .modelName(finetunedGeminiEndpoint)
        .build())
    .name("finetuned_gemini_agent")
    .instruction("You are a specialized assistant trained on specific data.")
    // ... other agent parameters
    .build();

Anthropic 的 Claude 模型在 Agent Platform 上的运行

在 ADK 中得到支持。Python v0.2.0TypeScript v2.4.0Go v2.7.0Java v0.1.0Kotlin v1.4.0

一些提供商(如 Anthropic)会直接通过 Agent Platform 提供他们的模型。要在 Agent Platform 上设置并使用 Claude 模型(包括扩展性思维功能以及提示缓存功能),请参阅相关文档。 通过代理平台进行连接。 在《Claude模型指南》中。

在 Agent 平台上使用 Open Models(开放模型)

在 ADK 中得到支持。Python v0.1.0Java v0.1.0

Agent Platform 通过“模型即服务”(Model-as-a-Service, MaaS)模式,提供了一系列精选的开源模型(例如 Meta Llama)。这些模型可以通过受管理的 API 进行访问,因此您无需自行管理底层基础设施即可轻松部署和扩展模型。如需查看所有可用模型的完整列表,请参阅…… Agent Platform 提供了适用于 MaaS(即“即服务”模式)的开放模型(open models)。 documentation.

您可以使用…… LiteLLM 一个用于在 Agent Platform MaaS 上访问开源模型的库(例如 Meta 公司的 Llama 模型)。

集成方法: 使用 LiteLlm 包装类(wrapper class),并将其设置为…… model “parameter of” 的意思是“……的参数”。 LlmAgent请确保您仔细阅读并完成相关步骤。 用于 ADK 代理的 LiteLLM 模型连接器 关于如何在 ADK 中使用 LiteLLM 的文档

设置:

  1. 代理平台环境(Agent Platform Environment): 请确保代理平台(Agent Platform)的配置已正确完成,包括 ADC(Application Delivery Controller)、环境变量(Env Variables)等所有相关组件的配置。 GOOGLE_GENAI_USE_ENTERPRISE=TRUE) 已经完成。

  2. 安装 LiteLLM: ADK 需要…… litellm>=1.84.

    pip install "litellm>=1.84"
    

示例:

from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm

# --- Example Agent using Meta's Llama 4 Scout ---
agent_llama_vertexai = LlmAgent(
    model=LiteLlm(model="vertex_ai/meta/llama-4-scout-17b-16e-instruct-maas"), # LiteLLM model string format
    name="llama4_agent",
    instruction="You are a helpful assistant powered by Llama 4 Scout.",
    # ... other agent parameters
)