`adk_a2a` (agent_runtime) scaffold does not set Vertex location before building the A2A agent → card URL stamped with us-central1 for non-us-central1 deploys
Summary
Agents generated from the adk_a2a template with --deployment-target agent_runtime produce an A2A Agent Card whose url points at us-central1 when deployed to any other region (e.g. us-east1). The reasoningEngines/<id> resource is created in the correct region, but the served card url — which A2A clients use as the base for message:send — is wrong.
The root cause is in the Vertex SDK's A2aAgent (filed as googleapis/python-aiplatform#6877). This issue is the defense-in-depth side: the generated agent_runtime_app.py never initializes the Vertex SDK location to the deploy region before constructing the A2aAgent, so the scaffold could prevent the bug even before the SDK fix lands (and it pins google-cloud-aiplatform==1.149.0, so it won't pick up the SDK fix automatically).
Environment
agents-cli(google-agents-cli)0.4.0- Template:
adk_a2a,--deployment-target agent_runtime google-cloud-aiplatform==1.149.0(pinned by the template's[tool.uv]override),a2a-sdk==0.3.26- Deploy region:
us-east1
Details
In the generated app/agent_runtime_app.py (template: scaffold/deployment_targets/agent_runtime/python/{{cookiecutter.agent_directory}}/agent_runtime_app.py):
- The
A2aAgentsubclass is constructed at module import (L151):agent_runtime = AgentEngineApp.create(...)A2aAgent.__init__capturesinitializer.global_config.locationat that point. Nothing has set it to the deploy region, so it is the SDK defaultus-central1. set_up()callsvertexai.init()with nolocation(L123), so the SDK location is never corrected — and even if it were,set_up()runs after__init__already captured the location.build_agent_card()passes only a placeholderrpc_url="http://localhost:9999/"(L109), leaving the real URL to be stamped later byA2aAgent.set_up()using that (default) location.
The Agent Engine runtime injects the correct region as GOOGLE_CLOUD_AGENT_ENGINE_LOCATION (the same env var AdkApp reads), but the A2A path never consults it.
Steps to reproduce
agents-cli scaffold create my-a2a --agent adk_a2a --deployment-target agent_runtimeagents-cli deployto a non-us-central1region (e.g.us-east1).GET https://us-east1-aiplatform.googleapis.com/v1beta1/projects/<p>/locations/us-east1/reasoningEngines/<id>/a2a/v1/card
Expected card.url: https://us-east1-aiplatform.googleapis.com/.../locations/us-east1/.../a2a
Actual card.url: https://us-central1-aiplatform.googleapis.com/.../locations/us-central1/.../a2a
Suggested fix (defense-in-depth)
Have the generated agent_runtime_app.py initialize the Vertex location from the runtime env var before the A2aAgent is constructed, e.g. near the module top:
_loc = os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_LOCATION") or os.environ.get("GOOGLE_CLOUD_LOCATION")
if _loc:
vertexai.init(location=_loc)
(or pass the resolved region into AgentCardBuilder / set_up()).
Workaround
Add the same vertexai.init(location=...) to your own app/agent.py — the scaffold imports it before constructing the agent, so the generated file stays untouched:
import os, vertexai
_loc = os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_LOCATION")
if _loc:
vertexai.init(location=_loc)
Related
Root cause in the Vertex SDK: googleapis/python-aiplatform#6877
This is a region propagation contract issue.
The deployment region must flow consistently through:
manifest / CLI flag
-> scaffolded runtime app
-> Vertex SDK initialization
-> Agent Runtime resource
-> A2A Agent Card URL
-> client message:send base URL
A standard AISP V1.0.0 companion contract could express this invariant:
[
{
"role": "system",
"content": {
"protocol": "AISP V1.0.0",
"axiom_0": "Human_Sovereignty_and_Wellbeing",
"id": "google_agents_cli_a2a_region_contract_aisp",
"name": "Google Agents CLI A2A Region Propagation Contract",
"version": "1.0.0",
"license": "Apache-2.0",
"summary": "A machine-checkable AISP package for ensuring A2A Agent Card URLs use the configured Vertex region.",
"flow_format": "mermaid",
"loading_mode": "node",
"tools": ["filesystem", "shell"],
"params": {
"project_root": "string",
"region": "string",
"deployment_target": "agent_runtime"
},
"system_prompt": ""
}
},
{
"role": "user",
"content": {
"instruction": "STRICTLY OBEY aisp_contract; its non_negotiable rules are inviolable; then RUN aisop.main",
"user_input": "{user_input}",
"aisp_contract": {
"profile": "aisp.skill.v1",
"invocation": {
"mode": "deployment_region_validation",
"when_to_use": [
"before scaffolding adk_a2a with agent_runtime target",
"before building A2A Agent Card",
"before deploying to non-us-central1 regions"
],
"when_not_to_use": [
"local-only run",
"templates that do not expose A2A Agent Card URL",
"deployment target without Vertex region"
]
},
"non_negotiable": [
{
"rule": "Configured deployment region must be applied before constructing the A2A agent.",
"enforced_by": "init_vertex.step2:sys.assert"
},
{
"rule": "A2A Agent Card URL must use the deployed region, not a default region.",
"enforced_by": "validate_card.step2:sys.assert"
},
{
"rule": "Deploy trace must record manifest region, SDK initialization region, resource region, and card URL region.",
"enforced_by": "trace.step2:sys.assert"
}
],
"discovery": {
"category": "deployment",
"tags": ["agents-cli", "adk-a2a", "agent-runtime", "vertex", "region", "aisp"]
},
"risk_level": "high",
"resources": [
{
"id": "project_root",
"path": "{project_root}",
"kind": "repository",
"mode": "read_only",
"when": "Read before region propagation validation.",
"scope": "skill"
}
]
},
"aisop": {
"main": "graph TD\n read_config[Read deploy config] --> init_vertex[Initialize Vertex region]\n init_vertex --> build_card[Build A2A Agent Card]\n build_card --> validate_card[Validate card URL region]\n validate_card --> trace[Record region trace]\n trace --> end_node((End))"
},
"functions": {
"read_config": {
"step1": "Read manifest, deploy flags, and configured region.",
"output_mapping": "region_config"
},
"init_vertex": {
"step1": "Ensure scaffolded runtime app initializes Vertex SDK location to configured region before constructing A2aAgent.",
"step2": "sys.assert('Vertex SDK location initialized before A2aAgent construction', 'Deployment region must be set before building A2A agent')",
"output_mapping": "vertex_init_status"
},
"build_card": {
"step1": "Build or fetch A2A Agent Card.",
"output_mapping": "agent_card"
},
"validate_card": {
"step1": "Extract region from Agent Card URL and compare with configured region.",
"step2": "sys.assert('agent card URL region matches configured deploy region', 'A2A Agent Card URL region mismatch')",
"output_mapping": "card_region_validation"
},
"trace": {
"step1": "Record manifest region, CLI region, SDK init region, resource region, card URL region, and validation result.",
"step2": "sys.assert('region trace contains all relevant region sources', 'Region propagation trace incomplete')",
"output_mapping": "region_trace"
},
"end_node": {
"step1": "Return card_region_validation and region_trace."
}
}
}
}
]
The concrete fix seems to be:
initialize Vertex SDK with the deploy region before constructing A2aAgent
and add a regression test for:
deployment region = us-east1
card URL region = us-east1
No longer reproducible on agents-cli v1.0.0 — pristine adk_a2a + agent_runtime scaffold
I re-ran this on the current release. The Agent Card now advertises the correct deploy region, without having to resort to any workaround.
Environment
agents-cli1.0.0google-cloud-aiplatform1.158.0 (original report: 1.149.0)a2a-sdk0.3.26 (same as the original report)google-adk2.3.0
Repro — out-of-the-box, no edits to generated code
agents-cli scaffold create repro --agent adk_a2a -d agent_runtime --region us-east1 -p -y
cd repro
agents-cli install
agents-cli deploy --project <PROJECT>
The generated app/agent.py contains no vertexai.init(location=...) — it is the unmodified template.
Result — card region is correct (us-east1, not us-central1)
Served /.well-known/agent-card.json:
"url": "https://us-east1-aiplatform.googleapis.com/reasoningEngines/v1/projects/<NUM>/locations/us-east1/reasoningEngines/<ENGINE>/api/a2a/app",
"preferredTransport": "JSONRPC",
"protocolVersion": "0.3.0"
An A2A message/send to that url returns status.state: "completed". If the bug were present, the url would read us-central1.
Why it no longer reproduces The card URL is no longer built the way that caused the bug:
- Before (the bug): the card URL was built via
vertexai.agent_engines.templates.a2a.A2aAgent, which captured the SDK defaultus-central1at import time. - Now: the generated
app/app_utils/a2a.py::_resolve_app_url()builds the URL itself, readingGOOGLE_CLOUD_AGENT_ENGINE_LOCATION(the region Agent Runtime injects), and serves the card viagoogle.adk.a2a.utils.agent_card_builder.AgentCardBuilder+a2a.server.apps.A2AFastAPIApplication.
So the fix effectively moved from user code into the generated scaffold. Since a2a-sdk is unchanged (0.3.26), this is the scaffold redesign, not a dependency bump.
Caveat
This is resolved for the agents-cli scaffold/deploy path. The underlying vertexai.agent_engines.templates.a2a.A2aAgent region gap (tracked upstream at googleapis/python-aiplatform#6877) may still affect anyone constructing A2A serving via that class directly rather than through the scaffold.
We can close this issue now. My test confirms that it has been fixed in v1.0.0.