Vertex AI Agent Engine
以 OpenAI 的請求/回應格式呼叫 Vertex AI Agent Engine(Reasoning Engines)。
| 屬性 | 詳細資訊 |
|---|---|
| 說明 | Vertex AI Agent Engine 提供代管的代理程式執行環境,可使用基礎模型、工具與自訂邏輯來執行 agentic 工作流程。 |
| LiteLLM 上的提供者路由 | vertex_ai/agent_engine/{RESOURCE_NAME} |
| 支援的端點 | /chat/completions, /v1/messages, /v1/responses, /v1/a2a/message/send |
| 提供者文件 | Vertex AI Agent Engine ↗ |
快速開始
模型格式
Model Format
vertex_ai/agent_engine/{RESOURCE_NAME}
範例:
vertex_ai/agent_engine/projects/1060139831167/locations/us-central1/reasoningEngines/8263861224643493888
LiteLLM Python SDK
Basic Agent Completion
import litellm
response = litellm.completion(
model="vertex_ai/agent_engine/projects/1060139831167/locations/us-central1/reasoningEngines/8263861224643493888",
messages=[
{"role": "user", "content": "Explain machine learning in simple terms"}
],
)
print(response.choices[0].message.content)
Streaming Agent Responses
import litellm
response = await litellm.acompletion(
model="vertex_ai/agent_engine/projects/1060139831167/locations/us-central1/reasoningEngines/8263861224643493888",
messages=[
{"role": "user", "content": "What are the key principles of software architecture?"}
],
stream=True,
)
async for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
LiteLLM Proxy
1. 在 config.yaml 中設定您的模型
- config.yaml
LiteLLM Proxy Configuration
model_list:
- model_name: vertex-agent-1
litellm_params:
model: vertex_ai/agent_engine/projects/1060139831167/locations/us-central1/reasoningEngines/8263861224643493888
vertex_project: your-project-id
vertex_location: us-central1
2. 啟動 LiteLLM Proxy
Start LiteLLM Proxy
litellm --config config.yaml
3. 對您的 Vertex AI Agent Engine 發出請求
- Curl
- OpenAI Python SDK
Basic Agent Request
curl http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-d '{
"model": "vertex-agent-1",
"messages": [
{"role": "user", "content": "Summarize the main benefits of cloud computing"}
]
}'
Using OpenAI SDK with LiteLLM Proxy
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:4000",
api_key="your-litellm-api-key"
)
response = client.chat.completions.create(
model="vertex-agent-1",
messages=[
{"role": "user", "content": "What are best practices for API design?"}
]
)
print(response.choices[0].message.content)
LiteLLM A2A Gateway
您也可以透過 LiteLLM 的 A2A(Agent-to-Agent)Gateway UI 連接到 Vertex AI Agent Engine。這提供了一種無需撰寫程式碼即可註冊與測試代理程式的可視化方式。
1. 前往 Agents
從側邊欄點選「Agents」開啟代理程式管理頁面,然後點選「+ Add New Agent」。


2. 選擇 Vertex AI Agent Engine 類型
點選「A2A Standard」查看可用的代理程式類型,然後選擇「Vertex AI Agent Engine」。


3. 設定代理程式
填入以下欄位:
- Agent Name - 您的代理程式友善名稱(例如,
my-vertex-agent) - Reasoning Engine Resource ID - 來自 Google Cloud Console 的完整資源路徑(例如,
projects/1060139831167/locations/us-central1/reasoningEngines/8263861224643493888) - Vertex Project - 您的 Google Cloud 專案 ID
- Vertex Location - 您的代理程式部署所在的區域(例如,
us-central1)


您可以在 Google Cloud Console 的 Vertex AI > Agent Engine 下找到 Resource ID:


您可以在 Google Cloud Console 中找到 Project ID:


4. 建立代理程式
點選「Create Agent」以儲存您的設定。

5. 在 Playground 中測試
前往側邊欄中的「Playground」測試您的代理程式。

6. 選擇 A2A 端點
點選端點下拉選單並選擇 /v1/a2a/message/send。

7. 選擇您的代理程式並傳送訊息
從下拉選單中選取您的 Vertex AI Agent Engine,然後傳送測試訊息。



環境變數
| 變數 | 說明 |
|---|---|
GOOGLE_APPLICATION_CREDENTIALS | 服務帳戶 JSON 金鑰檔案的路徑 |
VERTEXAI_PROJECT | Google Cloud 專案 ID |
VERTEXAI_LOCATION | Google Cloud 區域(預設:us-central1) |
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
export VERTEXAI_PROJECT="your-project-id"
export VERTEXAI_LOCATION="us-central1"