agent_engines 模組經過重構,並在獨立的 agentplatform 套件中重新命名為 runtimes。
本頁說明模組的主要異動,以及如何將現有程式碼遷移至新的 SDK 結構。如需 Agent Runtime 的一般資訊,請參閱總覽。
主要異動
從高層次來看,服務用戶端參數會依據每個用戶端初始化,且用戶端包含服務互動的相關模組。您還是可以透過 Google 相簿取得這些內容:
import vertexai
from vertexai import agent_engines
vertexai.init(project=GCP_PROJECT, location=GCP_REGION)
agent_engines.create(...)
已替換為
import agentplatform
# Mandatory for cross-project deployment and for use of the framework-specific templates.
client = agentplatform.Client(project=GCP_PROJECT, location=GCP_REGION)
client.runtimes.create(...)
SDK 中的下列命名空間已進入淘汰階段。請使用用戶端 Agent Platform SDK 的對等命名空間,該 SDK 與已淘汰的模組和套件具有完整的功能同位性。
| 舊版命名空間 | 受影響的程式碼 | 換貨裝置 (agentplatform) |
|---|---|---|
vertexai.agent_engines |
受影響的方法:
|
更換:
|
client.agent_engines |
受影響的方法:
|
更換:
|
遷移至以用戶端為基礎的設計
本節包含程式碼片段,示範如何將現有的 Agent Runtime 程式碼遷移至 agentplatform SDK 設計。注意:為提升可讀性,範例可能會省略匯入、依附元件和其他樣板程式碼。
建立 Agent Runtime 執行個體
事前
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 agentplatform
client = agentplatform.Client(
project=PROJECT,
location=LOCATION,
)
client.runtimes.create(
agent=local_agent,
config={
"staging_bucket": STAGING_BUCKET,
"requirements": REQUIREMENTS,
"extra_packages": EXTRA_PACKAGES,
# ...
},
)
更新 Agent Runtime 執行個體
事前
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 agentplatform
client = agentplatform.Client(
project=PROJECT,
location=LOCATION,
)
client.runtimes.update(
name=resource_name,
agent=local_agent,
config={
"staging_bucket": STAGING_BUCKET,
"requirements": REQUIREMENTS,
"extra_packages": EXTRA_PACKAGES,
# ...
},
)
取得 Agent Runtime 執行個體
事前
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
)
agent_engine = agent_engines.get(resource_name)
完成後
import agentplatform
client = agentplatform.Client(
project=PROJECT,
location=LOCATION,
)
remote_agent = client.runtimes.get(name=resource_name)
列出 Agent Runtime 執行個體
事前
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
)
agent_engine = agent_engines.list()
完成後
import agentplatform
client = agentplatform.Client(
project=PROJECT,
location=LOCATION,
)
runtimes = client.runtimes.list()
刪除 Agent Runtime 執行個體
事前
agent_engine.delete(
force=True, # Optional
)
或者
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
)
agent_engine = agent_engines.delete(
resource_name, # Required.
force=True, # Optional
)
完成後
remote_agent.delete(
force=True, # Optional.
)
或者
import agentplatform
client = agentplatform.Client(
project=PROJECT,
location=LOCATION,
)
remote_agent = client.runtimes.delete(
name=resource_name, # Required.
force=True, # Optional.
)