agent_engines 模块被重构并重命名为独立 agentplatform 软件包下的 runtimes。
该页面介绍了模块的主要变化,以及如何将现有代码迁移到新的 SDK 结构。
如需了解有关代理运行时的一般信息,请参阅概览。
主要变化
从高层来看,服务客户端参数是按客户端初始化的,并且客户端包含用于服务交互的相关模块。具体包括以下这些照片和视频:
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.
)