#!/usr/bin/env python3 """ agent.py — OSVauco root agent using ADK 1.x. Requires: google-adk >= 1.0.0,<2.0.0 google-cloud-aiplatform >= 1.112.0 """ import os import logging from google.adk.agents import Agent logger = logging.getLogger(__name__) PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT", "propane-will-491900-m5") LOCATION = os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1") # RAG corpus resource name — injected via Secret Manager as env-var RAG_CORPUS RAG_CORPUS = os.environ.get("RAG_CORPUS", "") rag_tool = None if RAG_CORPUS: try: # ADK 1.x: VertexAiRagRetrieval lives in google.adk.tools.retrieval from google.adk.tools.retrieval.vertex_ai_rag_retrieval import VertexAiRagRetrieval from vertexai.preview import rag rag_tool = VertexAiRagRetrieval( name="retrieve_knowledge", description="Retrieve relevant documentation and context from the OSVauco knowledge base.", rag_resources=[rag.RagResource(rag_corpus=RAG_CORPUS)], similarity_top_k=10, vector_distance_threshold=0.6, ) logger.info(f"RAG tool initialised with corpus: {RAG_CORPUS}") except ImportError as e: logger.warning(f"VertexAiRagRetrieval not available — running without RAG: {e}") rag_tool = None else: logger.warning("RAG_CORPUS env var not set — running without RAG retrieval") # Root agent root_agent = Agent( model="gemini-2.5-flash", name="osvauco_root", description="OSVauco enterprise agent for propane-will-491900-m5", instruction=( "You are OSVauco, a GCP knowledge and workflow agent. " "Use the retrieve_knowledge tool to answer questions from the knowledge base. " "Always prefer grounded, documented answers over speculation. " "Always respond in Norwegian (Bokmål) regardless of the language used in the query." ), tools=[rag_tool] if rag_tool else [], )