在 Vertex AI SDK 的 v1.112.0 版中,Vertex AI SDK for Python 中的 agent_engines
模組已重構為以用戶端為基礎的設計。
本頁說明模組的主要異動,以及如何遷移現有程式碼至以用戶端為基礎的設計。
如需 Agent Engine 的一般資訊,請參閱總覽。
主要異動
從高層次來看,服務用戶端參數會針對每個用戶端初始化,且用戶端包含服務互動的相關模組。
您還是可以透過 Google 相簿取得這些內容:
import vertexai
from vertexai import agent_engines
vertexai.init(project=GCP_PROJECT, location=GCP_REGION)
agent_engines.create(...)
已替換為
import vertexai
client = vertexai.Client(project=GCP_PROJECT, location=GCP_REGION)
client.agent_engines.create(...)
Vertex AI SDK 中 Vertex AI Agent Engine 的下列命名空間已進入淘汰階段。請使用以用戶端為基礎的 Vertex AI SDK 中的對等命名空間,該 SDK 與已淘汰的模組和套件具有完整的功能同位性。
Vertex AI SDK 命名空間 | 受影響的程式碼 | 以用戶端為基礎的 Vertex AI SDK 替代方案 |
---|---|---|
vertexai.agent_engines |
受影響的方法:
|
更換:
|
client.agent_engines |
受影響的方法:
|
更換:
|
遷移至以用戶端為基礎的設計
本節包含程式碼片段,說明如何將現有的 Agent Engine 程式碼遷移至以用戶端為基礎的設計。
建立 Agent Engine 執行個體
變更前
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
staging_bucket=STAGING_BUCKET,
)
agent_engines.create(
local_agent,
requirements=REQUIREMENTS,
extra_packages=EXTRA_PACKAGES,
# ...
)
完成後
import vertexai
client = vertexai.Client(
project=PROJECT,
location=LOCATION,
)
client.agent_engines.create(
agent=local_agent,
config={
"staging_bucket": STAGING_BUCKET,
"requirements": REQUIREMENTS,
"extra_packages": EXTRA_PACKAGES,
# ...
},
)
更新 Agent Engine 執行個體
變更前
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
staging_bucket=STAGING_BUCKET,
)
agent_engines.update(
resource_name,
agent_engine=local_agent,
requirements=REQUIREMENTS,
extra_packages=EXTRA_PACKAGES,
# ...
)
完成後
import vertexai
client = vertexai.Client(
project=PROJECT,
location=LOCATION,
)
client.agent_engines.update(
name=resource_name,
agent=local_agent,
config={
"staging_bucket": STAGING_BUCKET,
"requirements": REQUIREMENTS,
"extra_packages": EXTRA_PACKAGES,
# ...
},
)
取得 Agent Engine 執行個體
變更前
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
)
agent_engine = agent_engines.get(resource_name)
完成後
import vertexai
client = vertexai.Client(
project=PROJECT,
location=LOCATION,
)
agent_engine = client.agent_engines.get(name=resource_name)
列出 Agent Engine 執行個體
變更前
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
)
agent_engine = agent_engines.list()
完成後
import vertexai
client = vertexai.Client(
project=PROJECT,
location=LOCATION,
)
agent_engine = client.agent_engines.list()
刪除 Agent Engine 執行個體
變更前
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
)
agent_engine = agent_engines.list()
完成後
import vertexai
client = vertexai.Client(
project=PROJECT,
location=LOCATION,
)
agent_engine = client.agent_engines.list()