From b1f4aebb25093d7f91a92b966c14be6a182f90f6 Mon Sep 17 00:00:00 2001 From: "Wei Sun (Jack)" Date: Thu, 17 Jul 2025 16:19:43 -0700 Subject: [PATCH] chore: lint fixings in vertex_ai_memory_bank.py * Adds type hints; * Switches to lazy evaluation in logs. PiperOrigin-RevId: 784353566 --- .../memory/vertex_ai_memory_bank_service.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/google/adk/memory/vertex_ai_memory_bank_service.py b/src/google/adk/memory/vertex_ai_memory_bank_service.py index 083b48e8d..f8da6acd1 100644 --- a/src/google/adk/memory/vertex_ai_memory_bank_service.py +++ b/src/google/adk/memory/vertex_ai_memory_bank_service.py @@ -16,13 +16,15 @@ import json import logging +from typing import Any +from typing import Dict from typing import Optional from typing import TYPE_CHECKING +from google.genai import Client +from google.genai import types from typing_extensions import override -from google import genai - from .base_memory_service import BaseMemoryService from .base_memory_service import SearchMemoryResponse from .memory_entry import MemoryEntry @@ -84,7 +86,7 @@ async def add_session_to_memory(self, session: Session): path=f'reasoningEngines/{self._agent_engine_id}/memories:generate', request_dict=request_dict, ) - logger.info(f'Generate memory response: {api_response}') + logger.info('Generate memory response: %s', api_response) else: logger.info('No events to add to memory.') @@ -106,7 +108,7 @@ async def search_memory(self, *, app_name: str, user_id: str, query: str): }, ) api_response = _convert_api_response(api_response) - logger.info(f'Search memory response: {api_response}') + logger.info('Search memory response: %s', api_response) if not api_response or not api_response.get('retrievedMemories', None): return SearchMemoryResponse() @@ -117,10 +119,8 @@ async def search_memory(self, *, app_name: str, user_id: str, query: str): memory_events.append( MemoryEntry( author='user', - content=genai.types.Content( - parts=[ - genai.types.Part(text=memory.get('memory').get('fact')) - ], + content=types.Content( + parts=[types.Part(text=memory.get('memory').get('fact'))], role='user', ), timestamp=memory.get('updateTime'), @@ -137,13 +137,13 @@ def _get_api_client(self): Returns: An API client for the given project and location. """ - client = genai.Client( + client = Client( vertexai=True, project=self._project, location=self._location ) return client._api_client -def _convert_api_response(api_response): +def _convert_api_response(api_response) -> Dict[str, Any]: """Converts the API response to a JSON object based on the type.""" if hasattr(api_response, 'body'): return json.loads(api_response.body)