In version v1.112.0 of the Vertex AI SDK, the agent_engines
module within the Vertex AI SDK for Python was refactored to a
client-based design.
The page describes the key changes to the module and how to migrate your existing code to the client based design.
For general information about Agent Engine, see Overview.
Key changes
At a high level, service client parameters are initialized on a per-client basis, and the client contains the relevant modules for service interactions.
Namely,
import vertexai
from vertexai import agent_engines
vertexai.init(project=GCP_PROJECT, location=GCP_REGION)
agent_engines.create(...)
is replaced by
import vertexai
client = vertexai.Client(project=GCP_PROJECT, location=GCP_REGION)
client.agent_engines.create(...)
The following namespaces for Vertex AI Agent Engine in the Vertex AI SDK are in the deprecation phase. Use the equivalent namespaces from the client-based Vertex AI SDK, which has full feature parity with the deprecated modules and packages.
Vertex AI SDK namespace | Impacted code | Client-based Vertex AI SDK replacement |
---|---|---|
vertexai.agent_engines |
Impacted methods:
|
Replacement:
|
client.agent_engines |
Impacted methods:
|
Replacement:
|
Migrate to the client-based design
This section contains code snippets that demonstrate how to migrate your existing Agent Engine code to the client-based design.
Creating an Agent Engine instance
Before
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,
# ...
)
After
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,
# ...
},
)
Updating an Agent Engine instance
Before
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,
# ...
)
After
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,
# ...
},
)
Getting an Agent Engine instance
Before
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
)
agent_engine = agent_engines.get(resource_name)
After
import vertexai
client = vertexai.Client(
project=PROJECT,
location=LOCATION,
)
agent_engine = client.agent_engines.get(name=resource_name)
Listing Agent Engine instances
Before
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
)
agent_engine = agent_engines.list()
After
import vertexai
client = vertexai.Client(
project=PROJECT,
location=LOCATION,
)
agent_engine = client.agent_engines.list()
Deleting an Agent Engine instance
Before
import vertexai
from vertexai import agent_engines
vertexai.init(
project=PROJECT,
location=LOCATION,
)
agent_engine = agent_engines.list()
After
import vertexai
client = vertexai.Client(
project=PROJECT,
location=LOCATION,
)
agent_engine = client.agent_engines.list()