在 Vertex AI SDK 的 v1.112.0 版本中,Python 版 Vertex AI SDK 中的 agent_engines
模块被重构为基于客户端的设计。
该页面介绍了模块的主要变化,以及如何将现有代码迁移到基于客户端的设计。
如需了解有关 Agent Engine 的一般信息,请参阅概览。
主要变化
从高层来看,服务客户端参数是按客户端初始化的,并且客户端包含用于服务交互的相关模块。
具体包括以下这些照片和视频:
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()