fix(startup): lazy-init root_agent in lifespan — fix Cloud Run startup probe
This commit is contained in:
parent
4dfcffd0b3
commit
0f663c1d3d
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user