powermem 0.1.0__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.
- powermem/__init__.py +103 -0
- powermem/agent/__init__.py +35 -0
- powermem/agent/abstract/__init__.py +22 -0
- powermem/agent/abstract/collaboration.py +259 -0
- powermem/agent/abstract/context.py +187 -0
- powermem/agent/abstract/manager.py +232 -0
- powermem/agent/abstract/permission.py +217 -0
- powermem/agent/abstract/privacy.py +267 -0
- powermem/agent/abstract/scope.py +199 -0
- powermem/agent/agent.py +791 -0
- powermem/agent/components/__init__.py +18 -0
- powermem/agent/components/collaboration_coordinator.py +645 -0
- powermem/agent/components/permission_controller.py +586 -0
- powermem/agent/components/privacy_protector.py +767 -0
- powermem/agent/components/scope_controller.py +685 -0
- powermem/agent/factories/__init__.py +16 -0
- powermem/agent/factories/agent_factory.py +266 -0
- powermem/agent/factories/config_factory.py +308 -0
- powermem/agent/factories/memory_factory.py +229 -0
- powermem/agent/implementations/__init__.py +16 -0
- powermem/agent/implementations/hybrid.py +728 -0
- powermem/agent/implementations/multi_agent.py +1040 -0
- powermem/agent/implementations/multi_user.py +1020 -0
- powermem/agent/types.py +53 -0
- powermem/agent/wrappers/__init__.py +14 -0
- powermem/agent/wrappers/agent_memory_wrapper.py +427 -0
- powermem/agent/wrappers/compatibility_wrapper.py +520 -0
- powermem/config_loader.py +318 -0
- powermem/configs.py +249 -0
- powermem/core/__init__.py +19 -0
- powermem/core/async_memory.py +1493 -0
- powermem/core/audit.py +258 -0
- powermem/core/base.py +165 -0
- powermem/core/memory.py +1567 -0
- powermem/core/setup.py +162 -0
- powermem/core/telemetry.py +215 -0
- powermem/integrations/__init__.py +17 -0
- powermem/integrations/embeddings/__init__.py +13 -0
- powermem/integrations/embeddings/aws_bedrock.py +100 -0
- powermem/integrations/embeddings/azure_openai.py +55 -0
- powermem/integrations/embeddings/base.py +31 -0
- powermem/integrations/embeddings/config/base.py +132 -0
- powermem/integrations/embeddings/configs.py +31 -0
- powermem/integrations/embeddings/factory.py +48 -0
- powermem/integrations/embeddings/gemini.py +39 -0
- powermem/integrations/embeddings/huggingface.py +41 -0
- powermem/integrations/embeddings/langchain.py +35 -0
- powermem/integrations/embeddings/lmstudio.py +29 -0
- powermem/integrations/embeddings/mock.py +11 -0
- powermem/integrations/embeddings/ollama.py +53 -0
- powermem/integrations/embeddings/openai.py +49 -0
- powermem/integrations/embeddings/qwen.py +102 -0
- powermem/integrations/embeddings/together.py +31 -0
- powermem/integrations/embeddings/vertexai.py +54 -0
- powermem/integrations/llm/__init__.py +18 -0
- powermem/integrations/llm/anthropic.py +87 -0
- powermem/integrations/llm/base.py +132 -0
- powermem/integrations/llm/config/anthropic.py +56 -0
- powermem/integrations/llm/config/azure.py +56 -0
- powermem/integrations/llm/config/base.py +62 -0
- powermem/integrations/llm/config/deepseek.py +56 -0
- powermem/integrations/llm/config/ollama.py +56 -0
- powermem/integrations/llm/config/openai.py +79 -0
- powermem/integrations/llm/config/qwen.py +68 -0
- powermem/integrations/llm/config/qwen_asr.py +46 -0
- powermem/integrations/llm/config/vllm.py +56 -0
- powermem/integrations/llm/configs.py +26 -0
- powermem/integrations/llm/deepseek.py +106 -0
- powermem/integrations/llm/factory.py +118 -0
- powermem/integrations/llm/gemini.py +201 -0
- powermem/integrations/llm/langchain.py +65 -0
- powermem/integrations/llm/ollama.py +106 -0
- powermem/integrations/llm/openai.py +166 -0
- powermem/integrations/llm/openai_structured.py +80 -0
- powermem/integrations/llm/qwen.py +207 -0
- powermem/integrations/llm/qwen_asr.py +171 -0
- powermem/integrations/llm/vllm.py +106 -0
- powermem/integrations/rerank/__init__.py +20 -0
- powermem/integrations/rerank/base.py +43 -0
- powermem/integrations/rerank/config/__init__.py +7 -0
- powermem/integrations/rerank/config/base.py +27 -0
- powermem/integrations/rerank/configs.py +23 -0
- powermem/integrations/rerank/factory.py +68 -0
- powermem/integrations/rerank/qwen.py +159 -0
- powermem/intelligence/__init__.py +17 -0
- powermem/intelligence/ebbinghaus_algorithm.py +354 -0
- powermem/intelligence/importance_evaluator.py +361 -0
- powermem/intelligence/intelligent_memory_manager.py +284 -0
- powermem/intelligence/manager.py +148 -0
- powermem/intelligence/plugin.py +229 -0
- powermem/prompts/__init__.py +29 -0
- powermem/prompts/graph/graph_prompts.py +217 -0
- powermem/prompts/graph/graph_tools_prompts.py +469 -0
- powermem/prompts/importance_evaluation.py +246 -0
- powermem/prompts/intelligent_memory_prompts.py +163 -0
- powermem/prompts/templates.py +193 -0
- powermem/storage/__init__.py +14 -0
- powermem/storage/adapter.py +896 -0
- powermem/storage/base.py +109 -0
- powermem/storage/config/base.py +13 -0
- powermem/storage/config/oceanbase.py +58 -0
- powermem/storage/config/pgvector.py +52 -0
- powermem/storage/config/sqlite.py +27 -0
- powermem/storage/configs.py +159 -0
- powermem/storage/factory.py +59 -0
- powermem/storage/migration_manager.py +438 -0
- powermem/storage/oceanbase/__init__.py +8 -0
- powermem/storage/oceanbase/constants.py +162 -0
- powermem/storage/oceanbase/oceanbase.py +1384 -0
- powermem/storage/oceanbase/oceanbase_graph.py +1441 -0
- powermem/storage/pgvector/__init__.py +7 -0
- powermem/storage/pgvector/pgvector.py +420 -0
- powermem/storage/sqlite/__init__.py +0 -0
- powermem/storage/sqlite/sqlite.py +218 -0
- powermem/storage/sqlite/sqlite_vector_store.py +311 -0
- powermem/utils/__init__.py +35 -0
- powermem/utils/utils.py +605 -0
- powermem/version.py +23 -0
- powermem-0.1.0.dist-info/METADATA +187 -0
- powermem-0.1.0.dist-info/RECORD +123 -0
- powermem-0.1.0.dist-info/WHEEL +5 -0
- powermem-0.1.0.dist-info/licenses/LICENSE +206 -0
- powermem-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Compatibility Wrapper
|
|
3
|
+
|
|
4
|
+
Provides backward compatibility with the original Memory class and multi_agent
|
|
5
|
+
implementation, ensuring existing code continues to work without changes.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
from typing import Any, Dict, List, Optional
|
|
10
|
+
|
|
11
|
+
from typing import Any, Dict
|
|
12
|
+
from powermem.agent.wrappers.agent_memory_wrapper import AgentMemoryWrapper
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class CompatibilityWrapper:
|
|
18
|
+
"""
|
|
19
|
+
Compatibility wrapper that provides backward compatibility with the original
|
|
20
|
+
Memory class and multi_agent implementation.
|
|
21
|
+
|
|
22
|
+
This wrapper ensures that existing code continues to work without changes
|
|
23
|
+
while providing access to the new agent memory management features.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, config: Dict[str, Any]):
|
|
27
|
+
"""
|
|
28
|
+
Initialize the compatibility wrapper.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
config: Memory configuration object
|
|
32
|
+
"""
|
|
33
|
+
self.config = config
|
|
34
|
+
self.agent_memory_wrapper = AgentMemoryWrapper(config)
|
|
35
|
+
self.initialized = False
|
|
36
|
+
|
|
37
|
+
def initialize(self) -> None:
|
|
38
|
+
"""
|
|
39
|
+
Initialize the compatibility wrapper.
|
|
40
|
+
"""
|
|
41
|
+
try:
|
|
42
|
+
self.agent_memory_wrapper.initialize()
|
|
43
|
+
self.initialized = True
|
|
44
|
+
logger.info("Compatibility wrapper initialized successfully")
|
|
45
|
+
|
|
46
|
+
except Exception as e:
|
|
47
|
+
logger.error(f"Failed to initialize compatibility wrapper: {e}")
|
|
48
|
+
self.initialized = False
|
|
49
|
+
|
|
50
|
+
def is_enabled(self) -> bool:
|
|
51
|
+
"""
|
|
52
|
+
Check if agent memory management is enabled.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
True if enabled, False otherwise
|
|
56
|
+
"""
|
|
57
|
+
return self.agent_memory_wrapper.is_enabled()
|
|
58
|
+
|
|
59
|
+
# Backward compatibility methods for original multi_agent interface
|
|
60
|
+
|
|
61
|
+
def add_agent_memory(
|
|
62
|
+
self,
|
|
63
|
+
content: str,
|
|
64
|
+
agent_id: str,
|
|
65
|
+
context: Optional[Dict[str, Any]] = None,
|
|
66
|
+
metadata: Optional[Dict[str, Any]] = None
|
|
67
|
+
) -> Dict[str, Any]:
|
|
68
|
+
"""
|
|
69
|
+
Add agent memory (backward compatibility method).
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
content: Memory content
|
|
73
|
+
agent_id: ID of the agent
|
|
74
|
+
context: Optional context information
|
|
75
|
+
metadata: Optional metadata
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
Dictionary containing the result
|
|
79
|
+
"""
|
|
80
|
+
return self.agent_memory_wrapper.add_memory(
|
|
81
|
+
content=content,
|
|
82
|
+
agent_id=agent_id,
|
|
83
|
+
context=context,
|
|
84
|
+
metadata=metadata
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def get_agent_memories(
|
|
88
|
+
self,
|
|
89
|
+
agent_id: str,
|
|
90
|
+
query: Optional[str] = None,
|
|
91
|
+
filters: Optional[Dict[str, Any]] = None
|
|
92
|
+
) -> List[Dict[str, Any]]:
|
|
93
|
+
"""
|
|
94
|
+
Get agent memories (backward compatibility method).
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
agent_id: ID of the agent
|
|
98
|
+
query: Optional query string
|
|
99
|
+
filters: Optional filters
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
List of memory dictionaries
|
|
103
|
+
"""
|
|
104
|
+
return self.agent_memory_wrapper.get_memories(
|
|
105
|
+
agent_id=agent_id,
|
|
106
|
+
query=query,
|
|
107
|
+
filters=filters
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
def share_agent_memory(
|
|
111
|
+
self,
|
|
112
|
+
memory_id: str,
|
|
113
|
+
from_agent: str,
|
|
114
|
+
to_agents: List[str],
|
|
115
|
+
permissions: Optional[List[str]] = None
|
|
116
|
+
) -> Dict[str, Any]:
|
|
117
|
+
"""
|
|
118
|
+
Share agent memory (backward compatibility method).
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
memory_id: ID of the memory
|
|
122
|
+
from_agent: ID of the agent sharing
|
|
123
|
+
to_agents: List of agent IDs to share with
|
|
124
|
+
permissions: Optional permissions
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
Dictionary containing the result
|
|
128
|
+
"""
|
|
129
|
+
return self.agent_memory_wrapper.share_memory(
|
|
130
|
+
memory_id=memory_id,
|
|
131
|
+
from_agent=from_agent,
|
|
132
|
+
to_agents=to_agents,
|
|
133
|
+
permissions=permissions
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
def get_agent_context(self, agent_id: str) -> Dict[str, Any]:
|
|
137
|
+
"""
|
|
138
|
+
Get agent context (backward compatibility method).
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
agent_id: ID of the agent
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
Dictionary containing context information
|
|
145
|
+
"""
|
|
146
|
+
return self.agent_memory_wrapper.get_context_info(agent_id=agent_id)
|
|
147
|
+
|
|
148
|
+
def update_agent_memory_decay(self) -> Dict[str, Any]:
|
|
149
|
+
"""
|
|
150
|
+
Update agent memory decay (backward compatibility method).
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
Dictionary containing the result
|
|
154
|
+
"""
|
|
155
|
+
return self.agent_memory_wrapper.update_memory_decay()
|
|
156
|
+
|
|
157
|
+
def cleanup_agent_forgotten_memories(self) -> Dict[str, Any]:
|
|
158
|
+
"""
|
|
159
|
+
Cleanup agent forgotten memories (backward compatibility method).
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
Dictionary containing the result
|
|
163
|
+
"""
|
|
164
|
+
return self.agent_memory_wrapper.cleanup_forgotten_memories()
|
|
165
|
+
|
|
166
|
+
def get_agent_memory_statistics(self) -> Dict[str, Any]:
|
|
167
|
+
"""
|
|
168
|
+
Get agent memory statistics (backward compatibility method).
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
Dictionary containing memory statistics
|
|
172
|
+
"""
|
|
173
|
+
return self.agent_memory_wrapper.get_memory_statistics()
|
|
174
|
+
|
|
175
|
+
def switch_agent_memory_mode(self, new_mode: str) -> Dict[str, Any]:
|
|
176
|
+
"""
|
|
177
|
+
Switch agent memory mode (backward compatibility method).
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
new_mode: New mode to switch to
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
Dictionary containing the result
|
|
184
|
+
"""
|
|
185
|
+
return self.agent_memory_wrapper.switch_mode(new_mode)
|
|
186
|
+
|
|
187
|
+
def get_agent_memory_mode_info(self) -> Dict[str, Any]:
|
|
188
|
+
"""
|
|
189
|
+
Get agent memory mode information (backward compatibility method).
|
|
190
|
+
|
|
191
|
+
Returns:
|
|
192
|
+
Dictionary containing mode information
|
|
193
|
+
"""
|
|
194
|
+
manager_info = self.agent_memory_wrapper.get_manager_info()
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
"current_mode": self.config.agent_memory.mode if hasattr(self.config, 'agent_memory') else None,
|
|
198
|
+
"available_modes": self.agent_memory_wrapper.get_available_modes(),
|
|
199
|
+
"manager_type": manager_info.get("manager_type"),
|
|
200
|
+
"enabled": manager_info.get("enabled", False),
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
# New unified interface methods
|
|
204
|
+
|
|
205
|
+
def add_memory(
|
|
206
|
+
self,
|
|
207
|
+
content: str,
|
|
208
|
+
agent_id: str,
|
|
209
|
+
context: Optional[Dict[str, Any]] = None,
|
|
210
|
+
metadata: Optional[Dict[str, Any]] = None
|
|
211
|
+
) -> Dict[str, Any]:
|
|
212
|
+
"""
|
|
213
|
+
Add memory (unified interface method).
|
|
214
|
+
|
|
215
|
+
Args:
|
|
216
|
+
content: Memory content
|
|
217
|
+
agent_id: ID of the agent/user
|
|
218
|
+
context: Optional context information
|
|
219
|
+
metadata: Optional metadata
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
Dictionary containing the result
|
|
223
|
+
"""
|
|
224
|
+
return self.agent_memory_wrapper.add_memory(
|
|
225
|
+
content=content,
|
|
226
|
+
agent_id=agent_id,
|
|
227
|
+
context=context,
|
|
228
|
+
metadata=metadata
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
def get_memories(
|
|
232
|
+
self,
|
|
233
|
+
agent_id: str,
|
|
234
|
+
query: Optional[str] = None,
|
|
235
|
+
filters: Optional[Dict[str, Any]] = None
|
|
236
|
+
) -> List[Dict[str, Any]]:
|
|
237
|
+
"""
|
|
238
|
+
Get memories (unified interface method).
|
|
239
|
+
|
|
240
|
+
Args:
|
|
241
|
+
agent_id: ID of the agent/user
|
|
242
|
+
query: Optional query string
|
|
243
|
+
filters: Optional filters
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
List of memory dictionaries
|
|
247
|
+
"""
|
|
248
|
+
return self.agent_memory_wrapper.get_memories(
|
|
249
|
+
agent_id=agent_id,
|
|
250
|
+
query=query,
|
|
251
|
+
filters=filters
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
def update_memory(
|
|
255
|
+
self,
|
|
256
|
+
memory_id: str,
|
|
257
|
+
agent_id: str,
|
|
258
|
+
updates: Dict[str, Any]
|
|
259
|
+
) -> Dict[str, Any]:
|
|
260
|
+
"""
|
|
261
|
+
Update memory (unified interface method).
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
memory_id: ID of the memory
|
|
265
|
+
agent_id: ID of the agent/user
|
|
266
|
+
updates: Updates to apply
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
Dictionary containing the result
|
|
270
|
+
"""
|
|
271
|
+
return self.agent_memory_wrapper.update_memory(
|
|
272
|
+
memory_id=memory_id,
|
|
273
|
+
agent_id=agent_id,
|
|
274
|
+
updates=updates
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
def delete_memory(
|
|
278
|
+
self,
|
|
279
|
+
memory_id: str,
|
|
280
|
+
agent_id: str
|
|
281
|
+
) -> Dict[str, Any]:
|
|
282
|
+
"""
|
|
283
|
+
Delete memory (unified interface method).
|
|
284
|
+
|
|
285
|
+
Args:
|
|
286
|
+
memory_id: ID of the memory
|
|
287
|
+
agent_id: ID of the agent/user
|
|
288
|
+
|
|
289
|
+
Returns:
|
|
290
|
+
Dictionary containing the result
|
|
291
|
+
"""
|
|
292
|
+
return self.agent_memory_wrapper.delete_memory(
|
|
293
|
+
memory_id=memory_id,
|
|
294
|
+
agent_id=agent_id
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
def share_memory(
|
|
298
|
+
self,
|
|
299
|
+
memory_id: str,
|
|
300
|
+
from_agent: str,
|
|
301
|
+
to_agents: List[str],
|
|
302
|
+
permissions: Optional[List[str]] = None
|
|
303
|
+
) -> Dict[str, Any]:
|
|
304
|
+
"""
|
|
305
|
+
Share memory (unified interface method).
|
|
306
|
+
|
|
307
|
+
Args:
|
|
308
|
+
memory_id: ID of the memory
|
|
309
|
+
from_agent: ID of the agent/user sharing
|
|
310
|
+
to_agents: List of agent/user IDs to share with
|
|
311
|
+
permissions: Optional permissions
|
|
312
|
+
|
|
313
|
+
Returns:
|
|
314
|
+
Dictionary containing the result
|
|
315
|
+
"""
|
|
316
|
+
return self.agent_memory_wrapper.share_memory(
|
|
317
|
+
memory_id=memory_id,
|
|
318
|
+
from_agent=from_agent,
|
|
319
|
+
to_agents=to_agents,
|
|
320
|
+
permissions=permissions
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
def get_context_info(self, agent_id: str) -> Dict[str, Any]:
|
|
324
|
+
"""
|
|
325
|
+
Get context information (unified interface method).
|
|
326
|
+
|
|
327
|
+
Args:
|
|
328
|
+
agent_id: ID of the agent/user
|
|
329
|
+
|
|
330
|
+
Returns:
|
|
331
|
+
Dictionary containing context information
|
|
332
|
+
"""
|
|
333
|
+
return self.agent_memory_wrapper.get_context_info(agent_id=agent_id)
|
|
334
|
+
|
|
335
|
+
def update_memory_decay(self) -> Dict[str, Any]:
|
|
336
|
+
"""
|
|
337
|
+
Update memory decay (unified interface method).
|
|
338
|
+
|
|
339
|
+
Returns:
|
|
340
|
+
Dictionary containing the result
|
|
341
|
+
"""
|
|
342
|
+
return self.agent_memory_wrapper.update_memory_decay()
|
|
343
|
+
|
|
344
|
+
def cleanup_forgotten_memories(self) -> Dict[str, Any]:
|
|
345
|
+
"""
|
|
346
|
+
Cleanup forgotten memories (unified interface method).
|
|
347
|
+
|
|
348
|
+
Returns:
|
|
349
|
+
Dictionary containing the result
|
|
350
|
+
"""
|
|
351
|
+
return self.agent_memory_wrapper.cleanup_forgotten_memories()
|
|
352
|
+
|
|
353
|
+
def get_memory_statistics(self) -> Dict[str, Any]:
|
|
354
|
+
"""
|
|
355
|
+
Get memory statistics (unified interface method).
|
|
356
|
+
|
|
357
|
+
Returns:
|
|
358
|
+
Dictionary containing memory statistics
|
|
359
|
+
"""
|
|
360
|
+
return self.agent_memory_wrapper.get_memory_statistics()
|
|
361
|
+
|
|
362
|
+
def check_permission(
|
|
363
|
+
self,
|
|
364
|
+
agent_id: str,
|
|
365
|
+
memory_id: str,
|
|
366
|
+
permission: str
|
|
367
|
+
) -> bool:
|
|
368
|
+
"""
|
|
369
|
+
Check permission (unified interface method).
|
|
370
|
+
|
|
371
|
+
Args:
|
|
372
|
+
agent_id: ID of the agent/user
|
|
373
|
+
memory_id: ID of the memory
|
|
374
|
+
permission: Permission to check
|
|
375
|
+
|
|
376
|
+
Returns:
|
|
377
|
+
True if the agent/user has the permission, False otherwise
|
|
378
|
+
"""
|
|
379
|
+
return self.agent_memory_wrapper.check_permission(
|
|
380
|
+
agent_id=agent_id,
|
|
381
|
+
memory_id=memory_id,
|
|
382
|
+
permission=permission
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
def switch_mode(self, new_mode: str) -> Dict[str, Any]:
|
|
386
|
+
"""
|
|
387
|
+
Switch mode (unified interface method).
|
|
388
|
+
|
|
389
|
+
Args:
|
|
390
|
+
new_mode: New mode to switch to
|
|
391
|
+
|
|
392
|
+
Returns:
|
|
393
|
+
Dictionary containing the result
|
|
394
|
+
"""
|
|
395
|
+
return self.agent_memory_wrapper.switch_mode(new_mode)
|
|
396
|
+
|
|
397
|
+
def get_mode_info(self) -> Dict[str, Any]:
|
|
398
|
+
"""
|
|
399
|
+
Get mode information (unified interface method).
|
|
400
|
+
|
|
401
|
+
Returns:
|
|
402
|
+
Dictionary containing mode information
|
|
403
|
+
"""
|
|
404
|
+
return self.agent_memory_wrapper.get_manager_info()
|
|
405
|
+
|
|
406
|
+
def get_available_modes(self) -> List[str]:
|
|
407
|
+
"""
|
|
408
|
+
Get available modes (unified interface method).
|
|
409
|
+
|
|
410
|
+
Returns:
|
|
411
|
+
List of available modes
|
|
412
|
+
"""
|
|
413
|
+
return self.agent_memory_wrapper.get_available_modes()
|
|
414
|
+
|
|
415
|
+
def validate_configuration(self) -> Dict[str, Any]:
|
|
416
|
+
"""
|
|
417
|
+
Validate configuration (unified interface method).
|
|
418
|
+
|
|
419
|
+
Returns:
|
|
420
|
+
Dictionary containing validation results
|
|
421
|
+
"""
|
|
422
|
+
return self.agent_memory_wrapper.validate_configuration()
|
|
423
|
+
|
|
424
|
+
# Utility methods for migration and compatibility
|
|
425
|
+
|
|
426
|
+
def migrate_from_legacy(
|
|
427
|
+
self,
|
|
428
|
+
legacy_memories: List[Dict[str, Any]],
|
|
429
|
+
default_agent_id: str = "legacy_agent"
|
|
430
|
+
) -> Dict[str, Any]:
|
|
431
|
+
"""
|
|
432
|
+
Migrate memories from legacy format.
|
|
433
|
+
|
|
434
|
+
Args:
|
|
435
|
+
legacy_memories: List of legacy memory dictionaries
|
|
436
|
+
default_agent_id: Default agent ID for legacy memories
|
|
437
|
+
|
|
438
|
+
Returns:
|
|
439
|
+
Dictionary containing migration results
|
|
440
|
+
"""
|
|
441
|
+
if not self.is_enabled():
|
|
442
|
+
return {"error": "Agent memory management is not enabled"}
|
|
443
|
+
|
|
444
|
+
try:
|
|
445
|
+
migrated_count = 0
|
|
446
|
+
failed_count = 0
|
|
447
|
+
|
|
448
|
+
for legacy_memory in legacy_memories:
|
|
449
|
+
try:
|
|
450
|
+
# Extract content and metadata
|
|
451
|
+
content = legacy_memory.get('memory', legacy_memory.get('content', ''))
|
|
452
|
+
metadata = legacy_memory.get('metadata', {})
|
|
453
|
+
agent_id = metadata.get('agent_id', default_agent_id)
|
|
454
|
+
|
|
455
|
+
# Add memory using new system
|
|
456
|
+
result = self.add_memory(
|
|
457
|
+
content=content,
|
|
458
|
+
agent_id=agent_id,
|
|
459
|
+
metadata=metadata
|
|
460
|
+
)
|
|
461
|
+
|
|
462
|
+
if 'error' not in result:
|
|
463
|
+
migrated_count += 1
|
|
464
|
+
else:
|
|
465
|
+
failed_count += 1
|
|
466
|
+
|
|
467
|
+
except Exception as e:
|
|
468
|
+
logger.error(f"Failed to migrate legacy memory: {e}")
|
|
469
|
+
failed_count += 1
|
|
470
|
+
|
|
471
|
+
return {
|
|
472
|
+
"success": True,
|
|
473
|
+
"migrated_count": migrated_count,
|
|
474
|
+
"failed_count": failed_count,
|
|
475
|
+
"total_count": len(legacy_memories),
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
except Exception as e:
|
|
479
|
+
logger.error(f"Failed to migrate from legacy: {e}")
|
|
480
|
+
return {"error": str(e)}
|
|
481
|
+
|
|
482
|
+
def get_compatibility_info(self) -> Dict[str, Any]:
|
|
483
|
+
"""
|
|
484
|
+
Get compatibility information.
|
|
485
|
+
|
|
486
|
+
Returns:
|
|
487
|
+
Dictionary containing compatibility information
|
|
488
|
+
"""
|
|
489
|
+
return {
|
|
490
|
+
"backward_compatible": True,
|
|
491
|
+
"legacy_methods_supported": [
|
|
492
|
+
"add_agent_memory",
|
|
493
|
+
"get_agent_memories",
|
|
494
|
+
"share_agent_memory",
|
|
495
|
+
"get_agent_context",
|
|
496
|
+
"update_agent_memory_decay",
|
|
497
|
+
"cleanup_agent_forgotten_memories",
|
|
498
|
+
"get_agent_memory_statistics",
|
|
499
|
+
"switch_agent_memory_mode",
|
|
500
|
+
"get_agent_memory_mode_info",
|
|
501
|
+
],
|
|
502
|
+
"unified_methods_available": [
|
|
503
|
+
"add_memory",
|
|
504
|
+
"get_memories",
|
|
505
|
+
"update_memory",
|
|
506
|
+
"delete_memory",
|
|
507
|
+
"share_memory",
|
|
508
|
+
"get_context_info",
|
|
509
|
+
"update_memory_decay",
|
|
510
|
+
"cleanup_forgotten_memories",
|
|
511
|
+
"get_memory_statistics",
|
|
512
|
+
"check_permission",
|
|
513
|
+
"switch_mode",
|
|
514
|
+
"get_mode_info",
|
|
515
|
+
],
|
|
516
|
+
"migration_tools": [
|
|
517
|
+
"migrate_from_legacy",
|
|
518
|
+
"validate_configuration",
|
|
519
|
+
],
|
|
520
|
+
}
|