From 0f663c1d3da776ac9c53fb7198beb1382399b613 Mon Sep 17 00:00:00 2001 From: Chris Christiansen Date: Tue, 23 Jun 2026 12:17:58 +0000 Subject: [PATCH] =?UTF-8?q?fix(startup):=20lazy-init=20root=5Fagent=20in?= =?UTF-8?q?=20lifespan=20=E2=80=94=20fix=20Cloud=20Run=20startup=20probe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agents/core-logic/agent.py | 3 --- agents/core-logic/app.py | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/agents/core-logic/agent.py b/agents/core-logic/agent.py index 6ab34dd..474464e 100644 --- a/agents/core-logic/agent.py +++ b/agents/core-logic/agent.py @@ -263,9 +263,6 @@ def build_agent(mode: str = "light", message: str = "") -> tuple: return agent, actual_model, instruction -root_agent, _, _ = build_agent(mode="light") - - async def _run_async(message: str, user_id: str, session_id: str, mode: str, caller_type: str = "agent") -> str: mode = _normalize_mode(mode) agent, actual_model, instruction = build_agent(mode=mode, message=message) diff --git a/agents/core-logic/app.py b/agents/core-logic/app.py index ba61a7d..f7e5fbc 100644 --- a/agents/core-logic/app.py +++ b/agents/core-logic/app.py @@ -21,7 +21,7 @@ try: from google.adk.runners import Runner from google.adk.sessions import InMemorySessionService from google.genai.types import Content, Part - from agent import root_agent + from agent import build_agent from agents.recommendations_engine import get_recommendations from token_logger import create_bq_table_if_not_exists except ImportError as e: @@ -29,6 +29,7 @@ except ImportError as e: raise session_service = InMemorySessionService() +root_agent = None APP_NAME = os.environ.get("CLOUD_RUN_SERVICE", "gcp-orchestrator") PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT", "propane-will-491900-m5") BQ_BILLING_DATASET = os.environ.get("BQ_BILLING_DATASET", "billing_data") @@ -42,9 +43,11 @@ _budget_store: dict = {} @asynccontextmanager async def lifespan(app: FastAPI): + global root_agent logger.info(f"OSVauco agent '{APP_NAME}' starting up") vertexai.init(project=PROJECT_ID, location=os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1")) create_bq_table_if_not_exists() + root_agent, _, _ = build_agent(mode="light") logger.info(f"Static dir: {STATIC_DIR} (exists={STATIC_DIR.exists()})") yield logger.info(f"OSVauco agent '{APP_NAME}' shutting down")