google-adk-extras 0.1.1__py3-none-any.whl → 0.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google_adk_extras/__init__.py +31 -1
- google_adk_extras/adk_builder.py +1030 -0
- google_adk_extras/artifacts/__init__.py +25 -12
- google_adk_extras/artifacts/base_custom_artifact_service.py +148 -11
- google_adk_extras/artifacts/local_folder_artifact_service.py +133 -13
- google_adk_extras/artifacts/s3_artifact_service.py +135 -19
- google_adk_extras/artifacts/sql_artifact_service.py +109 -10
- google_adk_extras/credentials/__init__.py +34 -0
- google_adk_extras/credentials/base_custom_credential_service.py +113 -0
- google_adk_extras/credentials/github_oauth2_credential_service.py +213 -0
- google_adk_extras/credentials/google_oauth2_credential_service.py +216 -0
- google_adk_extras/credentials/http_basic_auth_credential_service.py +388 -0
- google_adk_extras/credentials/jwt_credential_service.py +345 -0
- google_adk_extras/credentials/microsoft_oauth2_credential_service.py +250 -0
- google_adk_extras/credentials/x_oauth2_credential_service.py +240 -0
- google_adk_extras/custom_agent_loader.py +170 -0
- google_adk_extras/enhanced_adk_web_server.py +137 -0
- google_adk_extras/enhanced_fastapi.py +507 -0
- google_adk_extras/enhanced_runner.py +38 -0
- google_adk_extras/memory/__init__.py +30 -13
- google_adk_extras/memory/base_custom_memory_service.py +37 -5
- google_adk_extras/memory/sql_memory_service.py +105 -19
- google_adk_extras/memory/yaml_file_memory_service.py +115 -22
- google_adk_extras/sessions/__init__.py +29 -13
- google_adk_extras/sessions/base_custom_session_service.py +133 -11
- google_adk_extras/sessions/sql_session_service.py +127 -16
- google_adk_extras/sessions/yaml_file_session_service.py +122 -14
- google_adk_extras-0.2.5.dist-info/METADATA +302 -0
- google_adk_extras-0.2.5.dist-info/RECORD +37 -0
- google_adk_extras/py.typed +0 -0
- google_adk_extras-0.1.1.dist-info/METADATA +0 -175
- google_adk_extras-0.1.1.dist-info/RECORD +0 -25
- {google_adk_extras-0.1.1.dist-info → google_adk_extras-0.2.5.dist-info}/WHEEL +0 -0
- {google_adk_extras-0.1.1.dist-info → google_adk_extras-0.2.5.dist-info}/licenses/LICENSE +0 -0
- {google_adk_extras-0.1.1.dist-info → google_adk_extras-0.2.5.dist-info}/top_level.txt +0 -0
@@ -53,7 +53,12 @@ class SQLMemoryModel(Base):
|
|
53
53
|
|
54
54
|
|
55
55
|
class SQLMemoryService(BaseCustomMemoryService):
|
56
|
-
"""SQL-based memory service implementation.
|
56
|
+
"""SQL-based memory service implementation.
|
57
|
+
|
58
|
+
This service stores memory entries in a SQL database using SQLAlchemy.
|
59
|
+
It supports efficient searching of memory entries by extracting and indexing
|
60
|
+
text content from conversation events.
|
61
|
+
"""
|
57
62
|
|
58
63
|
def __init__(self, database_url: str):
|
59
64
|
"""Initialize the SQL memory service.
|
@@ -67,7 +72,11 @@ class SQLMemoryService(BaseCustomMemoryService):
|
|
67
72
|
self.session_local: Optional[object] = None
|
68
73
|
|
69
74
|
async def _initialize_impl(self) -> None:
|
70
|
-
"""Initialize the database connection and create tables.
|
75
|
+
"""Initialize the database connection and create tables.
|
76
|
+
|
77
|
+
Raises:
|
78
|
+
RuntimeError: If database initialization fails.
|
79
|
+
"""
|
71
80
|
try:
|
72
81
|
self.engine = create_engine(self.database_url)
|
73
82
|
Base.metadata.create_all(self.engine)
|
@@ -87,20 +96,47 @@ class SQLMemoryService(BaseCustomMemoryService):
|
|
87
96
|
self.session_local = None
|
88
97
|
|
89
98
|
def _get_db_session(self):
|
90
|
-
"""Get a database session.
|
99
|
+
"""Get a database session.
|
100
|
+
|
101
|
+
Returns:
|
102
|
+
A database session object.
|
103
|
+
|
104
|
+
Raises:
|
105
|
+
RuntimeError: If the service is not initialized.
|
106
|
+
"""
|
91
107
|
if not self.session_local:
|
92
108
|
raise RuntimeError("Service not initialized")
|
93
109
|
return self.session_local()
|
94
110
|
|
95
111
|
def _serialize_content(self, content: types.Content) -> str:
|
96
|
-
"""Serialize Content object to JSON string.
|
112
|
+
"""Serialize Content object to JSON string.
|
113
|
+
|
114
|
+
Args:
|
115
|
+
content: The Content object to serialize.
|
116
|
+
|
117
|
+
Returns:
|
118
|
+
JSON string representation of the content.
|
119
|
+
|
120
|
+
Raises:
|
121
|
+
ValueError: If serialization fails.
|
122
|
+
"""
|
97
123
|
try:
|
98
124
|
return json.dumps(content.to_json_dict())
|
99
125
|
except (TypeError, ValueError) as e:
|
100
126
|
raise ValueError(f"Failed to serialize content: {e}")
|
101
127
|
|
102
128
|
def _deserialize_content(self, content_str: str) -> types.Content:
|
103
|
-
"""Deserialize Content object from JSON string.
|
129
|
+
"""Deserialize Content object from JSON string.
|
130
|
+
|
131
|
+
Args:
|
132
|
+
content_str: JSON string representation of the content.
|
133
|
+
|
134
|
+
Returns:
|
135
|
+
The deserialized Content object.
|
136
|
+
|
137
|
+
Raises:
|
138
|
+
ValueError: If deserialization fails.
|
139
|
+
"""
|
104
140
|
try:
|
105
141
|
content_dict = json.loads(content_str) if content_str else {}
|
106
142
|
return types.Content(**content_dict)
|
@@ -108,7 +144,14 @@ class SQLMemoryService(BaseCustomMemoryService):
|
|
108
144
|
raise ValueError(f"Failed to deserialize content: {e}")
|
109
145
|
|
110
146
|
def _extract_text_from_content(self, content: types.Content) -> str:
|
111
|
-
"""Extract text content from a Content object for storage and search.
|
147
|
+
"""Extract text content from a Content object for storage and search.
|
148
|
+
|
149
|
+
Args:
|
150
|
+
content: The Content object to extract text from.
|
151
|
+
|
152
|
+
Returns:
|
153
|
+
Extracted text content.
|
154
|
+
"""
|
112
155
|
if not content or not content.parts:
|
113
156
|
return ""
|
114
157
|
|
@@ -120,14 +163,28 @@ class SQLMemoryService(BaseCustomMemoryService):
|
|
120
163
|
return " ".join(text_parts)
|
121
164
|
|
122
165
|
def _extract_search_terms(self, text: str) -> str:
|
123
|
-
"""Extract search terms from text content.
|
166
|
+
"""Extract search terms from text content.
|
167
|
+
|
168
|
+
Args:
|
169
|
+
text: The text to extract search terms from.
|
170
|
+
|
171
|
+
Returns:
|
172
|
+
Space-separated unique search terms.
|
173
|
+
"""
|
124
174
|
# Extract words from text and convert to lowercase
|
125
175
|
words = re.findall(r'[A-Za-z]+', text.lower())
|
126
176
|
# Return space-separated unique words
|
127
177
|
return " ".join(sorted(set(words)))
|
128
178
|
|
129
179
|
async def _add_session_to_memory_impl(self, session: "Session") -> None:
|
130
|
-
"""Implementation of adding a session to memory.
|
180
|
+
"""Implementation of adding a session to memory.
|
181
|
+
|
182
|
+
Args:
|
183
|
+
session: The session to add to memory.
|
184
|
+
|
185
|
+
Raises:
|
186
|
+
RuntimeError: If adding the session to memory fails.
|
187
|
+
"""
|
131
188
|
db_session = self._get_db_session()
|
132
189
|
try:
|
133
190
|
# Add each event in the session as a separate memory entry
|
@@ -163,9 +220,25 @@ class SQLMemoryService(BaseCustomMemoryService):
|
|
163
220
|
async def _search_memory_impl(
|
164
221
|
self, *, app_name: str, user_id: str, query: str
|
165
222
|
) -> "SearchMemoryResponse":
|
166
|
-
"""Implementation of searching memory.
|
167
|
-
|
168
|
-
|
223
|
+
"""Implementation of searching memory.
|
224
|
+
|
225
|
+
Args:
|
226
|
+
app_name: The name of the application.
|
227
|
+
user_id: The id of the user.
|
228
|
+
query: The query to search for.
|
229
|
+
|
230
|
+
Returns:
|
231
|
+
A SearchMemoryResponse containing the matching memories.
|
232
|
+
|
233
|
+
Raises:
|
234
|
+
RuntimeError: If searching memory fails.
|
235
|
+
"""
|
236
|
+
try:
|
237
|
+
from google.adk.memory.base_memory_service import SearchMemoryResponse
|
238
|
+
from google.adk.memory.memory_entry import MemoryEntry
|
239
|
+
except Exception: # Fallback when ADK surface differs
|
240
|
+
from types import SimpleNamespace as MemoryEntry # type: ignore
|
241
|
+
SearchMemoryResponse = None # type: ignore
|
169
242
|
|
170
243
|
db_session = self._get_db_session()
|
171
244
|
try:
|
@@ -199,15 +272,28 @@ class SQLMemoryService(BaseCustomMemoryService):
|
|
199
272
|
memories = []
|
200
273
|
for db_memory in db_memories:
|
201
274
|
content = self._deserialize_content(db_memory.content_json)
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
275
|
+
try:
|
276
|
+
memory_entry = MemoryEntry(
|
277
|
+
content=content,
|
278
|
+
author=db_memory.author,
|
279
|
+
timestamp=db_memory.timestamp.isoformat() if db_memory.timestamp else None
|
280
|
+
)
|
281
|
+
except TypeError:
|
282
|
+
# SimpleNamespace fallback
|
283
|
+
from types import SimpleNamespace
|
284
|
+
memory_entry = SimpleNamespace(
|
285
|
+
content=content,
|
286
|
+
author=db_memory.author,
|
287
|
+
timestamp=db_memory.timestamp.isoformat() if db_memory.timestamp else None
|
288
|
+
)
|
207
289
|
memories.append(memory_entry)
|
208
|
-
|
209
|
-
|
290
|
+
|
291
|
+
if SearchMemoryResponse is not None:
|
292
|
+
return SearchMemoryResponse(memories=memories)
|
293
|
+
else:
|
294
|
+
from types import SimpleNamespace
|
295
|
+
return SimpleNamespace(memories=memories)
|
210
296
|
except SQLAlchemyError as e:
|
211
297
|
raise RuntimeError(f"Failed to search memory: {e}")
|
212
298
|
finally:
|
213
|
-
db_session.close()
|
299
|
+
db_session.close()
|
@@ -18,13 +18,18 @@ logger = logging.getLogger('google_adk_extras.' + __name__)
|
|
18
18
|
|
19
19
|
|
20
20
|
class YamlFileMemoryService(BaseCustomMemoryService):
|
21
|
-
"""YAML file-based memory service implementation.
|
21
|
+
"""YAML file-based memory service implementation.
|
22
|
+
|
23
|
+
This service stores memory entries in YAML files in a hierarchical directory structure.
|
24
|
+
Each memory entry is stored in a separate YAML file organized by app name and user ID.
|
25
|
+
Memory entries are searchable by extracting and indexing text content from conversation events.
|
26
|
+
"""
|
22
27
|
|
23
28
|
def __init__(self, base_directory: str = "./memory"):
|
24
29
|
"""Initialize the YAML file memory service.
|
25
30
|
|
26
31
|
Args:
|
27
|
-
base_directory: Base directory for storing memory files
|
32
|
+
base_directory: Base directory for storing memory files. Defaults to "./memory".
|
28
33
|
"""
|
29
34
|
super().__init__()
|
30
35
|
self.base_directory = Path(base_directory)
|
@@ -32,7 +37,10 @@ class YamlFileMemoryService(BaseCustomMemoryService):
|
|
32
37
|
self.base_directory.mkdir(parents=True, exist_ok=True)
|
33
38
|
|
34
39
|
async def _initialize_impl(self) -> None:
|
35
|
-
"""Initialize the file system memory service.
|
40
|
+
"""Initialize the file system memory service.
|
41
|
+
|
42
|
+
Ensures the base directory exists.
|
43
|
+
"""
|
36
44
|
# Ensure base directory exists
|
37
45
|
self.base_directory.mkdir(parents=True, exist_ok=True)
|
38
46
|
|
@@ -41,32 +49,76 @@ class YamlFileMemoryService(BaseCustomMemoryService):
|
|
41
49
|
pass
|
42
50
|
|
43
51
|
def _get_memory_directory(self, app_name: str, user_id: str) -> Path:
|
44
|
-
"""Generate directory path for memory entries.
|
52
|
+
"""Generate directory path for memory entries.
|
53
|
+
|
54
|
+
Args:
|
55
|
+
app_name: The name of the application.
|
56
|
+
user_id: The ID of the user.
|
57
|
+
|
58
|
+
Returns:
|
59
|
+
Path to the memory directory.
|
60
|
+
"""
|
45
61
|
directory = self.base_directory / app_name / user_id
|
46
62
|
directory.mkdir(parents=True, exist_ok=True)
|
47
63
|
return directory
|
48
64
|
|
49
65
|
def _get_memory_file_path(self, app_name: str, user_id: str, memory_id: str) -> Path:
|
50
|
-
"""Generate file path for a memory entry.
|
66
|
+
"""Generate file path for a memory entry.
|
67
|
+
|
68
|
+
Args:
|
69
|
+
app_name: The name of the application.
|
70
|
+
user_id: The ID of the user.
|
71
|
+
memory_id: The ID of the memory entry.
|
72
|
+
|
73
|
+
Returns:
|
74
|
+
Path to the memory file.
|
75
|
+
"""
|
51
76
|
directory = self._get_memory_directory(app_name, user_id)
|
52
77
|
return directory / f"{memory_id}.yaml"
|
53
78
|
|
54
79
|
def _serialize_content(self, content: types.Content) -> dict:
|
55
|
-
"""Serialize Content object to dictionary.
|
80
|
+
"""Serialize Content object to dictionary.
|
81
|
+
|
82
|
+
Args:
|
83
|
+
content: The Content object to serialize.
|
84
|
+
|
85
|
+
Returns:
|
86
|
+
Dictionary representation of the content.
|
87
|
+
|
88
|
+
Raises:
|
89
|
+
ValueError: If serialization fails.
|
90
|
+
"""
|
56
91
|
try:
|
57
92
|
return content.to_json_dict()
|
58
93
|
except (TypeError, ValueError) as e:
|
59
94
|
raise ValueError(f"Failed to serialize content: {e}")
|
60
95
|
|
61
96
|
def _deserialize_content(self, content_dict: dict) -> types.Content:
|
62
|
-
"""Deserialize Content object from dictionary.
|
97
|
+
"""Deserialize Content object from dictionary.
|
98
|
+
|
99
|
+
Args:
|
100
|
+
content_dict: Dictionary representation of the content.
|
101
|
+
|
102
|
+
Returns:
|
103
|
+
The deserialized Content object.
|
104
|
+
|
105
|
+
Raises:
|
106
|
+
ValueError: If deserialization fails.
|
107
|
+
"""
|
63
108
|
try:
|
64
109
|
return types.Content(**content_dict)
|
65
110
|
except (TypeError, ValueError) as e:
|
66
111
|
raise ValueError(f"Failed to deserialize content: {e}")
|
67
112
|
|
68
113
|
def _extract_text_from_content(self, content: types.Content) -> str:
|
69
|
-
"""Extract text content from a Content object for storage and search.
|
114
|
+
"""Extract text content from a Content object for storage and search.
|
115
|
+
|
116
|
+
Args:
|
117
|
+
content: The Content object to extract text from.
|
118
|
+
|
119
|
+
Returns:
|
120
|
+
Extracted text content.
|
121
|
+
"""
|
70
122
|
if not content or not content.parts:
|
71
123
|
return ""
|
72
124
|
|
@@ -78,14 +130,28 @@ class YamlFileMemoryService(BaseCustomMemoryService):
|
|
78
130
|
return " ".join(text_parts)
|
79
131
|
|
80
132
|
def _extract_search_terms(self, text: str) -> List[str]:
|
81
|
-
"""Extract search terms from text content.
|
133
|
+
"""Extract search terms from text content.
|
134
|
+
|
135
|
+
Args:
|
136
|
+
text: The text to extract search terms from.
|
137
|
+
|
138
|
+
Returns:
|
139
|
+
List of unique search terms.
|
140
|
+
"""
|
82
141
|
# Extract words from text and convert to lowercase
|
83
142
|
words = re.findall(r'[A-Za-z]+', text.lower())
|
84
143
|
# Return unique words as a list
|
85
144
|
return sorted(set(words))
|
86
145
|
|
87
146
|
async def _add_session_to_memory_impl(self, session: "Session") -> None:
|
88
|
-
"""Implementation of adding a session to memory.
|
147
|
+
"""Implementation of adding a session to memory.
|
148
|
+
|
149
|
+
Args:
|
150
|
+
session: The session to add to memory.
|
151
|
+
|
152
|
+
Raises:
|
153
|
+
RuntimeError: If adding the session to memory fails.
|
154
|
+
"""
|
89
155
|
try:
|
90
156
|
# Add each event in the session as a separate memory entry
|
91
157
|
for event in session.events:
|
@@ -122,9 +188,25 @@ class YamlFileMemoryService(BaseCustomMemoryService):
|
|
122
188
|
async def _search_memory_impl(
|
123
189
|
self, *, app_name: str, user_id: str, query: str
|
124
190
|
) -> "SearchMemoryResponse":
|
125
|
-
"""Implementation of searching memory.
|
126
|
-
|
127
|
-
|
191
|
+
"""Implementation of searching memory.
|
192
|
+
|
193
|
+
Args:
|
194
|
+
app_name: The name of the application.
|
195
|
+
user_id: The id of the user.
|
196
|
+
query: The query to search for.
|
197
|
+
|
198
|
+
Returns:
|
199
|
+
A SearchMemoryResponse containing the matching memories.
|
200
|
+
|
201
|
+
Raises:
|
202
|
+
RuntimeError: If searching memory fails.
|
203
|
+
"""
|
204
|
+
try:
|
205
|
+
from google.adk.memory.base_memory_service import SearchMemoryResponse
|
206
|
+
from google.adk.memory.memory_entry import MemoryEntry
|
207
|
+
except Exception:
|
208
|
+
from types import SimpleNamespace as MemoryEntry # type: ignore
|
209
|
+
SearchMemoryResponse = None # type: ignore
|
128
210
|
|
129
211
|
try:
|
130
212
|
# Extract search terms from query
|
@@ -163,14 +245,25 @@ class YamlFileMemoryService(BaseCustomMemoryService):
|
|
163
245
|
timestamp_str = None
|
164
246
|
if entry.get("timestamp"):
|
165
247
|
timestamp_str = datetime.fromtimestamp(entry["timestamp"]).isoformat()
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
248
|
+
try:
|
249
|
+
memory_entry = MemoryEntry(
|
250
|
+
content=content,
|
251
|
+
author=entry.get("author"),
|
252
|
+
timestamp=timestamp_str
|
253
|
+
)
|
254
|
+
except TypeError:
|
255
|
+
from types import SimpleNamespace
|
256
|
+
memory_entry = SimpleNamespace(
|
257
|
+
content=content,
|
258
|
+
author=entry.get("author"),
|
259
|
+
timestamp=timestamp_str
|
260
|
+
)
|
172
261
|
memories.append(memory_entry)
|
173
|
-
|
174
|
-
|
262
|
+
|
263
|
+
if SearchMemoryResponse is not None:
|
264
|
+
return SearchMemoryResponse(memories=memories)
|
265
|
+
else:
|
266
|
+
from types import SimpleNamespace
|
267
|
+
return SimpleNamespace(memories=memories)
|
175
268
|
except Exception as e:
|
176
|
-
raise RuntimeError(f"Failed to search memory: {e}")
|
269
|
+
raise RuntimeError(f"Failed to search memory: {e}")
|
@@ -1,13 +1,29 @@
|
|
1
|
-
"""Custom session service implementations for Google ADK.
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
"""Custom session service implementations for Google ADK.
|
2
|
+
|
3
|
+
Optional backends are imported lazily based on installed dependencies.
|
4
|
+
"""
|
5
|
+
|
6
|
+
try:
|
7
|
+
from .sql_session_service import SQLSessionService # type: ignore
|
8
|
+
except Exception:
|
9
|
+
SQLSessionService = None # type: ignore
|
10
|
+
|
11
|
+
try:
|
12
|
+
from .mongo_session_service import MongoSessionService # type: ignore
|
13
|
+
except Exception:
|
14
|
+
MongoSessionService = None # type: ignore
|
15
|
+
|
16
|
+
try:
|
17
|
+
from .redis_session_service import RedisSessionService # type: ignore
|
18
|
+
except Exception:
|
19
|
+
RedisSessionService = None # type: ignore
|
20
|
+
|
21
|
+
try:
|
22
|
+
from .yaml_file_session_service import YamlFileSessionService # type: ignore
|
23
|
+
except Exception:
|
24
|
+
YamlFileSessionService = None # type: ignore
|
25
|
+
|
26
|
+
__all__ = []
|
27
|
+
for _name in ("SQLSessionService", "MongoSessionService", "RedisSessionService", "YamlFileSessionService"):
|
28
|
+
if globals().get(_name) is not None:
|
29
|
+
__all__.append(_name)
|
@@ -10,7 +10,11 @@ from google.adk.sessions.base_session_service import GetSessionConfig, ListSessi
|
|
10
10
|
|
11
11
|
|
12
12
|
class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
13
|
-
"""Base class for custom session services with common functionality.
|
13
|
+
"""Base class for custom session services with common functionality.
|
14
|
+
|
15
|
+
This abstract base class provides a foundation for implementing custom
|
16
|
+
session services with automatic initialization and cleanup handling.
|
17
|
+
"""
|
14
18
|
|
15
19
|
def __init__(self):
|
16
20
|
"""Initialize the base custom session service."""
|
@@ -22,6 +26,9 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
22
26
|
|
23
27
|
This method should be called before using the service to ensure
|
24
28
|
any required setup (database connections, etc.) is complete.
|
29
|
+
|
30
|
+
Raises:
|
31
|
+
RuntimeError: If initialization fails.
|
25
32
|
"""
|
26
33
|
if not self._initialized:
|
27
34
|
await self._initialize_impl()
|
@@ -33,6 +40,9 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
33
40
|
|
34
41
|
This method should handle any setup required for the service to function,
|
35
42
|
such as database connections, creating tables, etc.
|
43
|
+
|
44
|
+
Raises:
|
45
|
+
RuntimeError: If initialization fails.
|
36
46
|
"""
|
37
47
|
pass
|
38
48
|
|
@@ -63,7 +73,21 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
63
73
|
state: Optional[dict[str, Any]] = None,
|
64
74
|
session_id: Optional[str] = None,
|
65
75
|
) -> Session:
|
66
|
-
"""Create a new session.
|
76
|
+
"""Create a new session.
|
77
|
+
|
78
|
+
Args:
|
79
|
+
app_name: The name of the application.
|
80
|
+
user_id: The ID of the user.
|
81
|
+
state: Optional initial state for the session.
|
82
|
+
session_id: Optional specific ID for the session. If not provided,
|
83
|
+
a UUID will be generated.
|
84
|
+
|
85
|
+
Returns:
|
86
|
+
The created Session object.
|
87
|
+
|
88
|
+
Raises:
|
89
|
+
RuntimeError: If session creation fails.
|
90
|
+
"""
|
67
91
|
if not self._initialized:
|
68
92
|
await self.initialize()
|
69
93
|
return await self._create_session_impl(
|
@@ -81,7 +105,20 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
81
105
|
session_id: str,
|
82
106
|
config: Optional[GetSessionConfig] = None,
|
83
107
|
) -> Optional[Session]:
|
84
|
-
"""Get a session by ID.
|
108
|
+
"""Get a session by ID.
|
109
|
+
|
110
|
+
Args:
|
111
|
+
app_name: The name of the application.
|
112
|
+
user_id: The ID of the user.
|
113
|
+
session_id: The ID of the session to retrieve.
|
114
|
+
config: Optional configuration for session retrieval.
|
115
|
+
|
116
|
+
Returns:
|
117
|
+
The Session object if found, None otherwise.
|
118
|
+
|
119
|
+
Raises:
|
120
|
+
RuntimeError: If session retrieval fails.
|
121
|
+
"""
|
85
122
|
if not self._initialized:
|
86
123
|
await self.initialize()
|
87
124
|
return await self._get_session_impl(
|
@@ -97,7 +134,18 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
97
134
|
app_name: str,
|
98
135
|
user_id: str
|
99
136
|
) -> ListSessionsResponse:
|
100
|
-
"""List all sessions for a user.
|
137
|
+
"""List all sessions for a user.
|
138
|
+
|
139
|
+
Args:
|
140
|
+
app_name: The name of the application.
|
141
|
+
user_id: The ID of the user.
|
142
|
+
|
143
|
+
Returns:
|
144
|
+
A ListSessionsResponse containing the sessions.
|
145
|
+
|
146
|
+
Raises:
|
147
|
+
RuntimeError: If session listing fails.
|
148
|
+
"""
|
101
149
|
if not self._initialized:
|
102
150
|
await self.initialize()
|
103
151
|
return await self._list_sessions_impl(
|
@@ -112,7 +160,16 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
112
160
|
user_id: str,
|
113
161
|
session_id: str
|
114
162
|
) -> None:
|
115
|
-
"""Delete a session.
|
163
|
+
"""Delete a session.
|
164
|
+
|
165
|
+
Args:
|
166
|
+
app_name: The name of the application.
|
167
|
+
user_id: The ID of the user.
|
168
|
+
session_id: The ID of the session to delete.
|
169
|
+
|
170
|
+
Raises:
|
171
|
+
RuntimeError: If session deletion fails.
|
172
|
+
"""
|
116
173
|
if not self._initialized:
|
117
174
|
await self.initialize()
|
118
175
|
await self._delete_session_impl(
|
@@ -122,7 +179,18 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
122
179
|
)
|
123
180
|
|
124
181
|
async def append_event(self, session: Session, event: Event) -> Event:
|
125
|
-
"""Append an event to a session.
|
182
|
+
"""Append an event to a session.
|
183
|
+
|
184
|
+
Args:
|
185
|
+
session: The session to append the event to.
|
186
|
+
event: The event to append.
|
187
|
+
|
188
|
+
Returns:
|
189
|
+
The appended event.
|
190
|
+
|
191
|
+
Raises:
|
192
|
+
RuntimeError: If appending the event fails.
|
193
|
+
"""
|
126
194
|
if not self._initialized:
|
127
195
|
await self.initialize()
|
128
196
|
# Update the session object
|
@@ -141,7 +209,20 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
141
209
|
state: Optional[dict[str, Any]] = None,
|
142
210
|
session_id: Optional[str] = None,
|
143
211
|
) -> Session:
|
144
|
-
"""Implementation of session creation.
|
212
|
+
"""Implementation of session creation.
|
213
|
+
|
214
|
+
Args:
|
215
|
+
app_name: The name of the application.
|
216
|
+
user_id: The ID of the user.
|
217
|
+
state: Optional initial state for the session.
|
218
|
+
session_id: Optional specific ID for the session.
|
219
|
+
|
220
|
+
Returns:
|
221
|
+
The created Session object.
|
222
|
+
|
223
|
+
Raises:
|
224
|
+
RuntimeError: If session creation fails.
|
225
|
+
"""
|
145
226
|
pass
|
146
227
|
|
147
228
|
@abc.abstractmethod
|
@@ -153,7 +234,20 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
153
234
|
session_id: str,
|
154
235
|
config: Optional[GetSessionConfig] = None,
|
155
236
|
) -> Optional[Session]:
|
156
|
-
"""Implementation of session retrieval.
|
237
|
+
"""Implementation of session retrieval.
|
238
|
+
|
239
|
+
Args:
|
240
|
+
app_name: The name of the application.
|
241
|
+
user_id: The ID of the user.
|
242
|
+
session_id: The ID of the session to retrieve.
|
243
|
+
config: Optional configuration for session retrieval.
|
244
|
+
|
245
|
+
Returns:
|
246
|
+
The Session object if found, None otherwise.
|
247
|
+
|
248
|
+
Raises:
|
249
|
+
RuntimeError: If session retrieval fails.
|
250
|
+
"""
|
157
251
|
pass
|
158
252
|
|
159
253
|
@abc.abstractmethod
|
@@ -163,7 +257,18 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
163
257
|
app_name: str,
|
164
258
|
user_id: str
|
165
259
|
) -> ListSessionsResponse:
|
166
|
-
"""Implementation of session listing.
|
260
|
+
"""Implementation of session listing.
|
261
|
+
|
262
|
+
Args:
|
263
|
+
app_name: The name of the application.
|
264
|
+
user_id: The ID of the user.
|
265
|
+
|
266
|
+
Returns:
|
267
|
+
A ListSessionsResponse containing the sessions.
|
268
|
+
|
269
|
+
Raises:
|
270
|
+
RuntimeError: If session listing fails.
|
271
|
+
"""
|
167
272
|
pass
|
168
273
|
|
169
274
|
@abc.abstractmethod
|
@@ -174,10 +279,27 @@ class BaseCustomSessionService(BaseSessionService, abc.ABC):
|
|
174
279
|
user_id: str,
|
175
280
|
session_id: str
|
176
281
|
) -> None:
|
177
|
-
"""Implementation of session deletion.
|
282
|
+
"""Implementation of session deletion.
|
283
|
+
|
284
|
+
Args:
|
285
|
+
app_name: The name of the application.
|
286
|
+
user_id: The ID of the user.
|
287
|
+
session_id: The ID of the session to delete.
|
288
|
+
|
289
|
+
Raises:
|
290
|
+
RuntimeError: If session deletion fails.
|
291
|
+
"""
|
178
292
|
pass
|
179
293
|
|
180
294
|
@abc.abstractmethod
|
181
295
|
async def _append_event_impl(self, session: Session, event: Event) -> None:
|
182
|
-
"""Implementation of event appending.
|
296
|
+
"""Implementation of event appending.
|
297
|
+
|
298
|
+
Args:
|
299
|
+
session: The session to append the event to.
|
300
|
+
event: The event to append.
|
301
|
+
|
302
|
+
Raises:
|
303
|
+
RuntimeError: If appending the event fails.
|
304
|
+
"""
|
183
305
|
pass
|