-
Notifications
You must be signed in to change notification settings - Fork 390
Description
client.agent_engines.create
does not pass the client's location
to the AdkApp
instance, causing deployment to use an incorrect or default region.
Problem:
The provided code demonstrates a conflict between the new client-based and the older global initialization methods in the Vertex AI SDK. While vertexai.Client
is correctly instantiated with location="us-central1"
, the AdkApp
object is created in a way that it remains unaware of this client-scoped configuration.
When client.agent_engines.create(agent=app, ...)
is called, the app
object does not carry the us-central1
location. Consequently, the deployment process falls back to a default location (or one set by a global vertexai.init
call), leading to a regional mismatch and deployment failures. The operation should be self-contained within the client's configuration.
Code to Reproduce:
import vertexai
import asyncio
import logging
# Configure logging
logging.basicConfig(level=logging.INFO)
# --- Problem Area ---
# 1. Client is configured for "us-central1"
project_id = "my-project"
client = vertexai.Client(project=project_id, location="us-central1")
# 2. Agent is defined independently
from google.adk.agents import Agent
root_agent = Agent(
name="root_agent",
model="gemini-2.5-flash",
instruction="You are a helpful AI assistant designed to provide accurate and useful information.",
)
# 3. AdkApp is instantiated without knowledge of the client's location.
# The global init() further complicates which configuration is used.
from vertexai.agent_engines import AdkApp
vertexai.init(project=project_id)
app = AdkApp(agent=root_agent)
# At this point, app's internal configuration does not know about "us-central1"
# 4. Deployment is called on the client, but the `app` object lacks the correct location.
# This is where the regional mismatch occurs.
remote_agent = client.agent_engines.create(
agent=app,
config={
"staging_bucket": "gs://<YOUR_BUCKET_IN_US_CENTRAL1>",
"requirements": ["google-adk", "google-cloud-aiplatform"]
}
)
print("Remote agent created successfully:")
print(remote_agent)
# --- Remote Query (will fail if deployment used the wrong region) ---
async def run_remote_query():
print("\nStreaming remote query...")
async for event in remote_agent.async_stream_query(message="hi!", user_id="test"):
print(event)
asyncio.run(run_remote_query())
Expected Behavior:
The client.agent_engines.create()
method should ensure that the AdkApp
instance (app
) it is deploying inherits the configuration of the client
object, specifically the location
. The deployment should seamlessly proceed in us-central1
as defined in the client.
Actual Behavior:
The AdkApp
object is unaware of the client
's location. The deployment process initiated by client.agent_engines.create()
uses a default or globally configured location, which conflicts with the client's explicit us-central1
setting, causing the deployment to fail.