Skip to content

Commit 4e77c92

Browse files
committed
fix: construct cloud run url for agent card when using adk deploy cloud_run --a2a
1 parent 7206e0a commit 4e77c92

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/google/adk/cli/fast_api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from fastapi.staticfiles import StaticFiles
4141
from fastapi.websockets import WebSocket
4242
from fastapi.websockets import WebSocketDisconnect
43+
from google.cloud.resourcemanager_v3 import ProjectsClient
4344
from google.genai import types
4445
import graphviz
4546
from opentelemetry import trace
@@ -1102,7 +1103,15 @@ async def _get_a2a_runner_async() -> Runner:
11021103
logger.info("Setting up A2A agent: %s", app_name)
11031104

11041105
try:
1105-
a2a_rpc_path = f"http://{host}:{port}/a2a/{app_name}"
1106+
if "K_SERVICE" in os.environ: # Indicating Cloud Run
1107+
project_client = ProjectsClient()
1108+
project_resource_path = project_client.get_project(name=f"projects/{os.getenv('GOOGLE_CLOUD_PROJECT')}").name
1109+
project_number = project_resource_path.split('/')[-1]
1110+
cloud_run_service_url = f"{os.getenv('K_SERVICE')}-{project_number}.{os.getenv('GOOGLE_CLOUD_LOCATION')}.run.app"
1111+
a2a_rpc_path = f"https://{cloud_run_service_url}/a2a/{app_name}"
1112+
logger.info("Constructed Cloud Run URL to A2A App: %s", a2a_rpc_path)
1113+
else:
1114+
a2a_rpc_path = f"http://{host}:{port}/a2a/{app_name}"
11061115

11071116
agent_executor = A2aAgentExecutor(
11081117
runner=create_a2a_runner_loader(app_name),

0 commit comments

Comments
 (0)