agent_engines モジュールがリファクタリングされ、スタンドアロンの agentplatform パッケージの runtimes に名前が変更されました。このページでは、モジュールの主な変更点と、新しい SDK 構造に既存のコードを移行する方法について説明します。Agent Runtime の一般的な情報については、概要をご覧ください。
主な変更点
全体としては、サービス クライアント パラメータはクライアントごとに初期化され、クライアントにはサービス インタラクションに関連するモジュールが含まれます。まとめると次のようになります。
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 には、非推奨のモジュールおよびパッケージと同等の機能がすべて備わっています。
| 以前の Namespace | 影響を受けるコード | 交換(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.
)