hindsight-api 0.1.10__py3-none-any.whl → 0.1.12__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.
- hindsight_api/__init__.py +2 -0
- hindsight_api/alembic/env.py +24 -1
- hindsight_api/alembic/versions/d9f6a3b4c5e2_rename_bank_to_interactions.py +14 -4
- hindsight_api/alembic/versions/e0a1b2c3d4e5_disposition_to_3_traits.py +54 -13
- hindsight_api/alembic/versions/rename_personality_to_disposition.py +18 -7
- hindsight_api/api/http.py +234 -228
- hindsight_api/api/mcp.py +14 -3
- hindsight_api/engine/__init__.py +12 -1
- hindsight_api/engine/entity_resolver.py +38 -37
- hindsight_api/engine/interface.py +592 -0
- hindsight_api/engine/llm_wrapper.py +176 -6
- hindsight_api/engine/memory_engine.py +993 -217
- hindsight_api/engine/retain/bank_utils.py +13 -12
- hindsight_api/engine/retain/chunk_storage.py +3 -2
- hindsight_api/engine/retain/fact_storage.py +10 -7
- hindsight_api/engine/retain/link_utils.py +17 -16
- hindsight_api/engine/retain/observation_regeneration.py +17 -16
- hindsight_api/engine/retain/orchestrator.py +2 -3
- hindsight_api/engine/retain/types.py +25 -8
- hindsight_api/engine/search/graph_retrieval.py +6 -5
- hindsight_api/engine/search/mpfp_retrieval.py +8 -7
- hindsight_api/engine/search/retrieval.py +12 -11
- hindsight_api/engine/search/think_utils.py +1 -1
- hindsight_api/engine/search/tracer.py +1 -1
- hindsight_api/engine/task_backend.py +32 -0
- hindsight_api/extensions/__init__.py +66 -0
- hindsight_api/extensions/base.py +81 -0
- hindsight_api/extensions/builtin/__init__.py +18 -0
- hindsight_api/extensions/builtin/tenant.py +33 -0
- hindsight_api/extensions/context.py +110 -0
- hindsight_api/extensions/http.py +89 -0
- hindsight_api/extensions/loader.py +125 -0
- hindsight_api/extensions/operation_validator.py +325 -0
- hindsight_api/extensions/tenant.py +63 -0
- hindsight_api/main.py +1 -1
- hindsight_api/mcp_local.py +7 -1
- hindsight_api/migrations.py +54 -10
- hindsight_api/models.py +15 -0
- hindsight_api/pg0.py +1 -1
- {hindsight_api-0.1.10.dist-info → hindsight_api-0.1.12.dist-info}/METADATA +1 -1
- hindsight_api-0.1.12.dist-info/RECORD +74 -0
- hindsight_api-0.1.10.dist-info/RECORD +0 -64
- {hindsight_api-0.1.10.dist-info → hindsight_api-0.1.12.dist-info}/WHEEL +0 -0
- {hindsight_api-0.1.10.dist-info → hindsight_api-0.1.12.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
"""Abstract interface for MemoryEngine public methods.
|
|
2
|
+
|
|
3
|
+
This module defines the public API that HTTP endpoints and extensions should use
|
|
4
|
+
to interact with the memory system. All methods require a RequestContext for
|
|
5
|
+
authentication when a TenantExtension is configured.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from abc import ABC, abstractmethod
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
from typing import TYPE_CHECKING, Any
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from hindsight_api.engine.memory_engine import Budget
|
|
14
|
+
from hindsight_api.engine.response_models import RecallResult, ReflectResult
|
|
15
|
+
from hindsight_api.models import RequestContext
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MemoryEngineInterface(ABC):
|
|
19
|
+
"""
|
|
20
|
+
Abstract interface for the Memory Engine.
|
|
21
|
+
|
|
22
|
+
This defines the public API that should be used by HTTP endpoints and extensions.
|
|
23
|
+
All methods require a RequestContext for authentication.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
# =========================================================================
|
|
27
|
+
# Health & Status
|
|
28
|
+
# =========================================================================
|
|
29
|
+
|
|
30
|
+
@abstractmethod
|
|
31
|
+
async def health_check(self) -> dict:
|
|
32
|
+
"""
|
|
33
|
+
Check the health of the memory system.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
Dict with 'status' key ('healthy' or 'unhealthy') and additional info.
|
|
37
|
+
"""
|
|
38
|
+
...
|
|
39
|
+
|
|
40
|
+
# =========================================================================
|
|
41
|
+
# Core Memory Operations
|
|
42
|
+
# =========================================================================
|
|
43
|
+
|
|
44
|
+
@abstractmethod
|
|
45
|
+
async def retain_batch_async(
|
|
46
|
+
self,
|
|
47
|
+
bank_id: str,
|
|
48
|
+
contents: list[dict[str, Any]],
|
|
49
|
+
*,
|
|
50
|
+
request_context: "RequestContext",
|
|
51
|
+
) -> dict[str, Any]:
|
|
52
|
+
"""
|
|
53
|
+
Retain a batch of memory items.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
bank_id: The memory bank ID.
|
|
57
|
+
contents: List of content dicts with 'content', optional 'event_date',
|
|
58
|
+
'context', 'metadata', 'document_id'.
|
|
59
|
+
request_context: Request context for authentication.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
Dict with processing results.
|
|
63
|
+
"""
|
|
64
|
+
...
|
|
65
|
+
|
|
66
|
+
@abstractmethod
|
|
67
|
+
async def recall_async(
|
|
68
|
+
self,
|
|
69
|
+
bank_id: str,
|
|
70
|
+
query: str,
|
|
71
|
+
*,
|
|
72
|
+
budget: "Budget | None" = None,
|
|
73
|
+
max_tokens: int = 4096,
|
|
74
|
+
enable_trace: bool = False,
|
|
75
|
+
fact_type: list[str] | None = None,
|
|
76
|
+
question_date: datetime | None = None,
|
|
77
|
+
include_entities: bool = False,
|
|
78
|
+
max_entity_tokens: int = 500,
|
|
79
|
+
include_chunks: bool = False,
|
|
80
|
+
max_chunk_tokens: int = 8192,
|
|
81
|
+
request_context: "RequestContext",
|
|
82
|
+
) -> "RecallResult":
|
|
83
|
+
"""
|
|
84
|
+
Recall memories relevant to a query.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
bank_id: The memory bank ID.
|
|
88
|
+
query: The search query.
|
|
89
|
+
budget: Search budget (LOW, MID, HIGH).
|
|
90
|
+
max_tokens: Maximum tokens in response.
|
|
91
|
+
enable_trace: Include trace information.
|
|
92
|
+
fact_type: Filter by fact types.
|
|
93
|
+
question_date: Context date for temporal relevance.
|
|
94
|
+
include_entities: Include entity observations.
|
|
95
|
+
max_entity_tokens: Max tokens for entity observations.
|
|
96
|
+
include_chunks: Include raw chunks.
|
|
97
|
+
max_chunk_tokens: Max tokens for chunks.
|
|
98
|
+
request_context: Request context for authentication.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
RecallResult with matching memories.
|
|
102
|
+
"""
|
|
103
|
+
...
|
|
104
|
+
|
|
105
|
+
@abstractmethod
|
|
106
|
+
async def reflect_async(
|
|
107
|
+
self,
|
|
108
|
+
bank_id: str,
|
|
109
|
+
query: str,
|
|
110
|
+
*,
|
|
111
|
+
budget: "Budget | None" = None,
|
|
112
|
+
context: str | None = None,
|
|
113
|
+
request_context: "RequestContext",
|
|
114
|
+
) -> "ReflectResult":
|
|
115
|
+
"""
|
|
116
|
+
Reflect on a query and generate a thoughtful response.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
bank_id: The memory bank ID.
|
|
120
|
+
query: The question to reflect on.
|
|
121
|
+
budget: Search budget for retrieving context.
|
|
122
|
+
context: Additional context for the reflection.
|
|
123
|
+
request_context: Request context for authentication.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
ReflectResult with generated response and supporting facts.
|
|
127
|
+
"""
|
|
128
|
+
...
|
|
129
|
+
|
|
130
|
+
# =========================================================================
|
|
131
|
+
# Bank Management
|
|
132
|
+
# =========================================================================
|
|
133
|
+
|
|
134
|
+
@abstractmethod
|
|
135
|
+
async def list_banks(
|
|
136
|
+
self,
|
|
137
|
+
*,
|
|
138
|
+
request_context: "RequestContext",
|
|
139
|
+
) -> list[dict[str, Any]]:
|
|
140
|
+
"""
|
|
141
|
+
List all memory banks.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
request_context: Request context for authentication.
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
List of bank info dicts.
|
|
148
|
+
"""
|
|
149
|
+
...
|
|
150
|
+
|
|
151
|
+
@abstractmethod
|
|
152
|
+
async def get_bank_profile(
|
|
153
|
+
self,
|
|
154
|
+
bank_id: str,
|
|
155
|
+
*,
|
|
156
|
+
request_context: "RequestContext",
|
|
157
|
+
) -> dict[str, Any]:
|
|
158
|
+
"""
|
|
159
|
+
Get bank profile including disposition and background.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
bank_id: The memory bank ID.
|
|
163
|
+
request_context: Request context for authentication.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
Bank profile dict.
|
|
167
|
+
"""
|
|
168
|
+
...
|
|
169
|
+
|
|
170
|
+
@abstractmethod
|
|
171
|
+
async def update_bank_disposition(
|
|
172
|
+
self,
|
|
173
|
+
bank_id: str,
|
|
174
|
+
disposition: dict[str, int],
|
|
175
|
+
*,
|
|
176
|
+
request_context: "RequestContext",
|
|
177
|
+
) -> None:
|
|
178
|
+
"""
|
|
179
|
+
Update bank disposition traits.
|
|
180
|
+
|
|
181
|
+
Args:
|
|
182
|
+
bank_id: The memory bank ID.
|
|
183
|
+
disposition: Dict with trait values.
|
|
184
|
+
request_context: Request context for authentication.
|
|
185
|
+
"""
|
|
186
|
+
...
|
|
187
|
+
|
|
188
|
+
@abstractmethod
|
|
189
|
+
async def merge_bank_background(
|
|
190
|
+
self,
|
|
191
|
+
bank_id: str,
|
|
192
|
+
new_info: str,
|
|
193
|
+
*,
|
|
194
|
+
update_disposition: bool = True,
|
|
195
|
+
request_context: "RequestContext",
|
|
196
|
+
) -> dict[str, Any]:
|
|
197
|
+
"""
|
|
198
|
+
Merge new background information into bank profile.
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
bank_id: The memory bank ID.
|
|
202
|
+
new_info: New background information to merge.
|
|
203
|
+
update_disposition: Whether to infer disposition from background.
|
|
204
|
+
request_context: Request context for authentication.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
Updated background info.
|
|
208
|
+
"""
|
|
209
|
+
...
|
|
210
|
+
|
|
211
|
+
@abstractmethod
|
|
212
|
+
async def delete_bank(
|
|
213
|
+
self,
|
|
214
|
+
bank_id: str,
|
|
215
|
+
*,
|
|
216
|
+
fact_type: str | None = None,
|
|
217
|
+
request_context: "RequestContext",
|
|
218
|
+
) -> dict[str, int]:
|
|
219
|
+
"""
|
|
220
|
+
Delete a bank or its memories.
|
|
221
|
+
|
|
222
|
+
Args:
|
|
223
|
+
bank_id: The memory bank ID.
|
|
224
|
+
fact_type: If specified, only delete memories of this type.
|
|
225
|
+
request_context: Request context for authentication.
|
|
226
|
+
|
|
227
|
+
Returns:
|
|
228
|
+
Dict with deletion counts.
|
|
229
|
+
"""
|
|
230
|
+
...
|
|
231
|
+
|
|
232
|
+
# =========================================================================
|
|
233
|
+
# Memory Units
|
|
234
|
+
# =========================================================================
|
|
235
|
+
|
|
236
|
+
@abstractmethod
|
|
237
|
+
async def list_memory_units(
|
|
238
|
+
self,
|
|
239
|
+
bank_id: str,
|
|
240
|
+
*,
|
|
241
|
+
fact_type: str | None = None,
|
|
242
|
+
search_query: str | None = None,
|
|
243
|
+
limit: int = 100,
|
|
244
|
+
offset: int = 0,
|
|
245
|
+
request_context: "RequestContext",
|
|
246
|
+
) -> dict[str, Any]:
|
|
247
|
+
"""
|
|
248
|
+
List memory units with pagination.
|
|
249
|
+
|
|
250
|
+
Args:
|
|
251
|
+
bank_id: The memory bank ID.
|
|
252
|
+
fact_type: Filter by fact type.
|
|
253
|
+
search_query: Full-text search query.
|
|
254
|
+
limit: Maximum results.
|
|
255
|
+
offset: Pagination offset.
|
|
256
|
+
request_context: Request context for authentication.
|
|
257
|
+
|
|
258
|
+
Returns:
|
|
259
|
+
Dict with 'items', 'total', 'limit', 'offset'.
|
|
260
|
+
"""
|
|
261
|
+
...
|
|
262
|
+
|
|
263
|
+
@abstractmethod
|
|
264
|
+
async def delete_memory_unit(
|
|
265
|
+
self,
|
|
266
|
+
unit_id: str,
|
|
267
|
+
*,
|
|
268
|
+
request_context: "RequestContext",
|
|
269
|
+
) -> dict[str, Any]:
|
|
270
|
+
"""
|
|
271
|
+
Delete a specific memory unit.
|
|
272
|
+
|
|
273
|
+
Args:
|
|
274
|
+
unit_id: The memory unit ID.
|
|
275
|
+
request_context: Request context for authentication.
|
|
276
|
+
|
|
277
|
+
Returns:
|
|
278
|
+
Deletion result.
|
|
279
|
+
"""
|
|
280
|
+
...
|
|
281
|
+
|
|
282
|
+
@abstractmethod
|
|
283
|
+
async def get_graph_data(
|
|
284
|
+
self,
|
|
285
|
+
bank_id: str,
|
|
286
|
+
*,
|
|
287
|
+
fact_type: str | None = None,
|
|
288
|
+
request_context: "RequestContext",
|
|
289
|
+
) -> dict[str, Any]:
|
|
290
|
+
"""
|
|
291
|
+
Get graph data for visualization.
|
|
292
|
+
|
|
293
|
+
Args:
|
|
294
|
+
bank_id: The memory bank ID.
|
|
295
|
+
fact_type: Filter by fact type.
|
|
296
|
+
request_context: Request context for authentication.
|
|
297
|
+
|
|
298
|
+
Returns:
|
|
299
|
+
Dict with nodes, edges, table_rows, total_units.
|
|
300
|
+
"""
|
|
301
|
+
...
|
|
302
|
+
|
|
303
|
+
# =========================================================================
|
|
304
|
+
# Documents
|
|
305
|
+
# =========================================================================
|
|
306
|
+
|
|
307
|
+
@abstractmethod
|
|
308
|
+
async def list_documents(
|
|
309
|
+
self,
|
|
310
|
+
bank_id: str,
|
|
311
|
+
*,
|
|
312
|
+
search_query: str | None = None,
|
|
313
|
+
limit: int = 100,
|
|
314
|
+
offset: int = 0,
|
|
315
|
+
request_context: "RequestContext",
|
|
316
|
+
) -> dict[str, Any]:
|
|
317
|
+
"""
|
|
318
|
+
List documents with pagination.
|
|
319
|
+
|
|
320
|
+
Args:
|
|
321
|
+
bank_id: The memory bank ID.
|
|
322
|
+
search_query: Search query.
|
|
323
|
+
limit: Maximum results.
|
|
324
|
+
offset: Pagination offset.
|
|
325
|
+
request_context: Request context for authentication.
|
|
326
|
+
|
|
327
|
+
Returns:
|
|
328
|
+
Dict with 'items', 'total', 'limit', 'offset'.
|
|
329
|
+
"""
|
|
330
|
+
...
|
|
331
|
+
|
|
332
|
+
@abstractmethod
|
|
333
|
+
async def get_document(
|
|
334
|
+
self,
|
|
335
|
+
document_id: str,
|
|
336
|
+
bank_id: str,
|
|
337
|
+
*,
|
|
338
|
+
request_context: "RequestContext",
|
|
339
|
+
) -> dict[str, Any] | None:
|
|
340
|
+
"""
|
|
341
|
+
Get a specific document.
|
|
342
|
+
|
|
343
|
+
Args:
|
|
344
|
+
document_id: The document ID.
|
|
345
|
+
bank_id: The memory bank ID.
|
|
346
|
+
request_context: Request context for authentication.
|
|
347
|
+
|
|
348
|
+
Returns:
|
|
349
|
+
Document dict or None if not found.
|
|
350
|
+
"""
|
|
351
|
+
...
|
|
352
|
+
|
|
353
|
+
@abstractmethod
|
|
354
|
+
async def delete_document(
|
|
355
|
+
self,
|
|
356
|
+
document_id: str,
|
|
357
|
+
bank_id: str,
|
|
358
|
+
*,
|
|
359
|
+
request_context: "RequestContext",
|
|
360
|
+
) -> dict[str, int]:
|
|
361
|
+
"""
|
|
362
|
+
Delete a document and its memory units.
|
|
363
|
+
|
|
364
|
+
Args:
|
|
365
|
+
document_id: The document ID.
|
|
366
|
+
bank_id: The memory bank ID.
|
|
367
|
+
request_context: Request context for authentication.
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
Dict with deletion counts.
|
|
371
|
+
"""
|
|
372
|
+
...
|
|
373
|
+
|
|
374
|
+
@abstractmethod
|
|
375
|
+
async def get_chunk(
|
|
376
|
+
self,
|
|
377
|
+
chunk_id: str,
|
|
378
|
+
*,
|
|
379
|
+
request_context: "RequestContext",
|
|
380
|
+
) -> dict[str, Any] | None:
|
|
381
|
+
"""
|
|
382
|
+
Get a specific chunk.
|
|
383
|
+
|
|
384
|
+
Args:
|
|
385
|
+
chunk_id: The chunk ID.
|
|
386
|
+
request_context: Request context for authentication.
|
|
387
|
+
|
|
388
|
+
Returns:
|
|
389
|
+
Chunk dict or None if not found.
|
|
390
|
+
"""
|
|
391
|
+
...
|
|
392
|
+
|
|
393
|
+
# =========================================================================
|
|
394
|
+
# Entities
|
|
395
|
+
# =========================================================================
|
|
396
|
+
|
|
397
|
+
@abstractmethod
|
|
398
|
+
async def list_entities(
|
|
399
|
+
self,
|
|
400
|
+
bank_id: str,
|
|
401
|
+
*,
|
|
402
|
+
limit: int = 100,
|
|
403
|
+
request_context: "RequestContext",
|
|
404
|
+
) -> list[dict[str, Any]]:
|
|
405
|
+
"""
|
|
406
|
+
List entities for a bank.
|
|
407
|
+
|
|
408
|
+
Args:
|
|
409
|
+
bank_id: The memory bank ID.
|
|
410
|
+
limit: Maximum results.
|
|
411
|
+
request_context: Request context for authentication.
|
|
412
|
+
|
|
413
|
+
Returns:
|
|
414
|
+
List of entity dicts.
|
|
415
|
+
"""
|
|
416
|
+
...
|
|
417
|
+
|
|
418
|
+
@abstractmethod
|
|
419
|
+
async def get_entity_observations(
|
|
420
|
+
self,
|
|
421
|
+
bank_id: str,
|
|
422
|
+
entity_id: str,
|
|
423
|
+
*,
|
|
424
|
+
limit: int = 10,
|
|
425
|
+
request_context: "RequestContext",
|
|
426
|
+
) -> list[Any]:
|
|
427
|
+
"""
|
|
428
|
+
Get observations for an entity.
|
|
429
|
+
|
|
430
|
+
Args:
|
|
431
|
+
bank_id: The memory bank ID.
|
|
432
|
+
entity_id: The entity ID.
|
|
433
|
+
limit: Maximum observations.
|
|
434
|
+
request_context: Request context for authentication.
|
|
435
|
+
|
|
436
|
+
Returns:
|
|
437
|
+
List of EntityObservation objects.
|
|
438
|
+
"""
|
|
439
|
+
...
|
|
440
|
+
|
|
441
|
+
@abstractmethod
|
|
442
|
+
async def regenerate_entity_observations(
|
|
443
|
+
self,
|
|
444
|
+
bank_id: str,
|
|
445
|
+
entity_id: str,
|
|
446
|
+
entity_name: str,
|
|
447
|
+
*,
|
|
448
|
+
request_context: "RequestContext",
|
|
449
|
+
) -> None:
|
|
450
|
+
"""
|
|
451
|
+
Regenerate observations for an entity.
|
|
452
|
+
|
|
453
|
+
Args:
|
|
454
|
+
bank_id: The memory bank ID.
|
|
455
|
+
entity_id: The entity ID.
|
|
456
|
+
entity_name: The entity's canonical name.
|
|
457
|
+
request_context: Request context for authentication.
|
|
458
|
+
"""
|
|
459
|
+
...
|
|
460
|
+
|
|
461
|
+
# =========================================================================
|
|
462
|
+
# Statistics & Operations
|
|
463
|
+
# =========================================================================
|
|
464
|
+
|
|
465
|
+
@abstractmethod
|
|
466
|
+
async def get_bank_stats(
|
|
467
|
+
self,
|
|
468
|
+
bank_id: str,
|
|
469
|
+
*,
|
|
470
|
+
request_context: "RequestContext",
|
|
471
|
+
) -> dict[str, Any]:
|
|
472
|
+
"""
|
|
473
|
+
Get statistics about memory nodes and links for a bank.
|
|
474
|
+
|
|
475
|
+
Args:
|
|
476
|
+
bank_id: The memory bank ID.
|
|
477
|
+
request_context: Request context for authentication.
|
|
478
|
+
|
|
479
|
+
Returns:
|
|
480
|
+
Dict with node_counts, link_counts, link_counts_by_fact_type,
|
|
481
|
+
link_breakdown, and operations stats.
|
|
482
|
+
"""
|
|
483
|
+
...
|
|
484
|
+
|
|
485
|
+
@abstractmethod
|
|
486
|
+
async def get_entity(
|
|
487
|
+
self,
|
|
488
|
+
bank_id: str,
|
|
489
|
+
entity_id: str,
|
|
490
|
+
*,
|
|
491
|
+
request_context: "RequestContext",
|
|
492
|
+
) -> dict[str, Any] | None:
|
|
493
|
+
"""
|
|
494
|
+
Get entity details including metadata and observations.
|
|
495
|
+
|
|
496
|
+
Args:
|
|
497
|
+
bank_id: The memory bank ID.
|
|
498
|
+
entity_id: The entity ID.
|
|
499
|
+
request_context: Request context for authentication.
|
|
500
|
+
|
|
501
|
+
Returns:
|
|
502
|
+
Entity dict with id, canonical_name, mention_count, first_seen,
|
|
503
|
+
last_seen, metadata, and observations. None if not found.
|
|
504
|
+
"""
|
|
505
|
+
...
|
|
506
|
+
|
|
507
|
+
@abstractmethod
|
|
508
|
+
async def list_operations(
|
|
509
|
+
self,
|
|
510
|
+
bank_id: str,
|
|
511
|
+
*,
|
|
512
|
+
request_context: "RequestContext",
|
|
513
|
+
) -> list[dict[str, Any]]:
|
|
514
|
+
"""
|
|
515
|
+
List async operations for a bank.
|
|
516
|
+
|
|
517
|
+
Args:
|
|
518
|
+
bank_id: The memory bank ID.
|
|
519
|
+
request_context: Request context for authentication.
|
|
520
|
+
|
|
521
|
+
Returns:
|
|
522
|
+
List of operation dicts with id, task_type, status, etc.
|
|
523
|
+
"""
|
|
524
|
+
...
|
|
525
|
+
|
|
526
|
+
@abstractmethod
|
|
527
|
+
async def cancel_operation(
|
|
528
|
+
self,
|
|
529
|
+
bank_id: str,
|
|
530
|
+
operation_id: str,
|
|
531
|
+
*,
|
|
532
|
+
request_context: "RequestContext",
|
|
533
|
+
) -> dict[str, Any]:
|
|
534
|
+
"""
|
|
535
|
+
Cancel a pending async operation.
|
|
536
|
+
|
|
537
|
+
Args:
|
|
538
|
+
bank_id: The memory bank ID.
|
|
539
|
+
operation_id: The operation ID to cancel.
|
|
540
|
+
request_context: Request context for authentication.
|
|
541
|
+
|
|
542
|
+
Returns:
|
|
543
|
+
Dict with success status and message.
|
|
544
|
+
|
|
545
|
+
Raises:
|
|
546
|
+
ValueError: If operation not found.
|
|
547
|
+
"""
|
|
548
|
+
...
|
|
549
|
+
|
|
550
|
+
@abstractmethod
|
|
551
|
+
async def update_bank(
|
|
552
|
+
self,
|
|
553
|
+
bank_id: str,
|
|
554
|
+
*,
|
|
555
|
+
name: str | None = None,
|
|
556
|
+
background: str | None = None,
|
|
557
|
+
request_context: "RequestContext",
|
|
558
|
+
) -> dict[str, Any]:
|
|
559
|
+
"""
|
|
560
|
+
Update bank name and/or background.
|
|
561
|
+
|
|
562
|
+
Args:
|
|
563
|
+
bank_id: The memory bank ID.
|
|
564
|
+
name: New bank name (optional).
|
|
565
|
+
background: New background text (optional, replaces existing).
|
|
566
|
+
request_context: Request context for authentication.
|
|
567
|
+
|
|
568
|
+
Returns:
|
|
569
|
+
Updated bank profile dict.
|
|
570
|
+
"""
|
|
571
|
+
...
|
|
572
|
+
|
|
573
|
+
@abstractmethod
|
|
574
|
+
async def submit_async_retain(
|
|
575
|
+
self,
|
|
576
|
+
bank_id: str,
|
|
577
|
+
contents: list[dict[str, Any]],
|
|
578
|
+
*,
|
|
579
|
+
request_context: "RequestContext",
|
|
580
|
+
) -> dict[str, Any]:
|
|
581
|
+
"""
|
|
582
|
+
Submit a batch retain operation to run asynchronously.
|
|
583
|
+
|
|
584
|
+
Args:
|
|
585
|
+
bank_id: The memory bank ID.
|
|
586
|
+
contents: List of content dicts to retain.
|
|
587
|
+
request_context: Request context for authentication.
|
|
588
|
+
|
|
589
|
+
Returns:
|
|
590
|
+
Dict with operation_id and items_count.
|
|
591
|
+
"""
|
|
592
|
+
...
|