diff --git a/src/google/adk/sessions/__init__.py b/src/google/adk/sessions/__init__.py index 3f3c9db651..bafce6dea3 100644 --- a/src/google/adk/sessions/__init__.py +++ b/src/google/adk/sessions/__init__.py @@ -14,6 +14,7 @@ from __future__ import annotations +from typing_extensions import override import importlib from typing import TYPE_CHECKING @@ -28,6 +29,45 @@ from .in_memory_session_service import InMemorySessionService from .vertex_ai_session_service import VertexAiSessionService +try: + from .database_session_service import DatabaseSessionService +except ImportError: + # This handles the case where optional dependencies (like sqlalchemy) + # are not installed. A placeholder class ensures the symbol is always + # available for documentation tools and static analysis. + # We use type: ignore[no-redef, misc] to satisfy strict mypy checks. + class DatabaseSessionService(BaseSessionService): # type: ignore[no-redef, misc] + """Placeholder for DatabaseSessionService when dependencies are not installed.""" + + _ERROR_MESSAGE = ( + 'DatabaseSessionService requires sqlalchemy>=2.0, please ensure it is' + ' installed correctly.' + ) + + def __init__(self, *args: Any, **kwargs: Any) -> None: + raise ImportError(self._ERROR_MESSAGE) + + @override + async def create_session(self, *args: Any, **kwargs: Any) -> Any: + raise ImportError(self._ERROR_MESSAGE) + + @override + async def get_session(self, *args: Any, **kwargs: Any) -> Any: + raise ImportError(self._ERROR_MESSAGE) + + @override + async def list_sessions(self, *args: Any, **kwargs: Any) -> Any: + raise ImportError(self._ERROR_MESSAGE) + + @override + async def delete_session(self, *args: Any, **kwargs: Any) -> Any: + raise ImportError(self._ERROR_MESSAGE) + + @override + async def append_event(self, *args: Any, **kwargs: Any) -> Any: + raise ImportError(self._ERROR_MESSAGE) + + __all__ = [ 'BaseSessionService', 'DatabaseSessionService', @@ -55,3 +95,4 @@ def __getattr__(name: str): raise missing_extra('sqlalchemy', 'db') from e return vars(module)['DatabaseSessionService'] raise AttributeError(f'module {__name__!r} has no attribute {name!r}') +