From 0248081b8324e7350b97b3112318455be3b79c6b Mon Sep 17 00:00:00 2001 From: chrischristiansen-glitch Date: Sun, 24 May 2026 15:12:08 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20agent.py=20=E2=80=94=20bruk=20riktig=20i?= =?UTF-8?q?mport-path=20for=20VertexAiRagRetrieval=20(ADK=201.x)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agents/core-logic/agent.py | 60 +++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/agents/core-logic/agent.py b/agents/core-logic/agent.py index d12b593..7525dff 100644 --- a/agents/core-logic/agent.py +++ b/agents/core-logic/agent.py @@ -1,48 +1,54 @@ #!/usr/bin/env python3 """ -agent.py — OSVauco root agent using ADK 2.0. -Requires: google-adk >= 1.29, google-cloud-aiplatform >= 1.111.0 +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 -from google.adk.integrations.secret_manager.secret_client import SecretManagerClient -from vertexai.preview import rag -PROJECT_ID = "propane-will-491900-m5" -LOCATION = "us-central1" +logger = logging.getLogger(__name__) -# --- Secret Manager integration (ADK >= 1.29) --- -_sm = SecretManagerClient() -def _get_secret(name: str) -> str: - return _sm.get_secret( - f"projects/{PROJECT_ID}/secrets/{name}/versions/latest" - ) +PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT", "propane-will-491900-m5") +LOCATION = os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1") -# --- RAG retrieval tool --- -RAG_CORPUS = os.environ.get("RAG_CORPUS", "") # set via Secret Manager or env +# 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: - from google.adk.tools import VertexAiRagRetrieval - rag_tool = VertexAiRagRetrieval( - name="retrieve_knowledge", - description="Retrieve relevant documentation from the knowledge base.", - rag_resources=[rag.RagResource(rag_corpus=RAG_CORPUS)], - similarity_top_k=10, - vector_distance_threshold=0.6, - ) + 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 -# --- Root agent --- + 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", # cost-optimized default - name="oavauco_root", + 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." + "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 [], )