Skip to content

Commit ace16e2

Browse files
committed
Build issue resolve
1 parent c9b1e1c commit ace16e2

28 files changed

Lines changed: 267 additions & 146 deletions

multimind/memory/active_learning.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def __init__(
4747
self.reinforcement: Dict[str, List[Dict[str, Any]]] = {} # item_id -> reinforcement data
4848
self.last_analysis = datetime.now()
4949
self.last_optimization = datetime.now()
50-
self.load()
5150

5251
async def add_message(self, message: Dict[str, str]) -> None:
5352
"""Add message and track feedback."""
@@ -210,7 +209,7 @@ async def _remove_item(self, item_id: str) -> None:
210209
if item_id in self.reinforcement:
211210
del self.reinforcement[item_id]
212211

213-
def get_messages(self) -> List[Dict[str, str]]:
212+
async def get_messages(self) -> List[Dict[str, str]]:
214213
"""Get all messages from all items."""
215214
messages = []
216215
for item in self.items:
@@ -241,7 +240,7 @@ async def save(self) -> None:
241240
"last_optimization": self.last_optimization.isoformat()
242241
}, f)
243242

244-
def load(self) -> None:
243+
async def load(self) -> None:
245244
"""Load items and feedback from persistent storage."""
246245
if self.storage_path and self.storage_path.exists():
247246
with open(self.storage_path, 'r') as f:

multimind/memory/associative.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def __init__(
8888
self.last_cluster_update = datetime.now()
8989
self.last_analysis = datetime.now()
9090
self.last_evolution = datetime.now()
91-
self.load()
9291

9392
async def add_message(self, message: Dict[str, str]) -> None:
9493
"""Add message as new association."""
@@ -407,7 +406,7 @@ async def _remove_association(self, association_id: str) -> None:
407406
if association_id in self.learning_history:
408407
del self.learning_history[association_id]
409408

410-
def get_messages(self) -> List[Dict[str, str]]:
409+
async def get_messages(self) -> List[Dict[str, str]]:
411410
"""Get all messages from all associations."""
412411
messages = []
413412
for association in self.associations:
@@ -448,7 +447,7 @@ async def save(self) -> None:
448447
"last_evolution": self.last_evolution.isoformat()
449448
}, f)
450449

451-
def load(self) -> None:
450+
async def load(self) -> None:
452451
"""Load associations from persistent storage."""
453452
if self.storage_path and self.storage_path.exists():
454453
with open(self.storage_path, 'r') as f:

multimind/memory/base.py

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"""
44

55
from abc import ABC, abstractmethod
6-
import inspect
7-
from typing import List, Dict, Any, Optional, Union
6+
from typing import List, Dict, Any
87
from datetime import datetime
98

109
class BaseMemory(ABC):
@@ -14,17 +13,6 @@ def __init__(self, memory_key: str = "chat_history"):
1413
self.memory_key = memory_key
1514
self.created_at = datetime.now()
1615

17-
def __init_subclass__(cls, **kwargs):
18-
"""Auto-wrap sync overrides so BaseMemory API stays async."""
19-
super().__init_subclass__(**kwargs)
20-
for method_name in ("add_message", "get_messages", "clear", "save", "load"):
21-
method = cls.__dict__.get(method_name)
22-
if method is None:
23-
continue
24-
if inspect.iscoroutinefunction(method):
25-
continue
26-
setattr(cls, method_name, BaseMemory._make_async_wrapper(method))
27-
2816
@abstractmethod
2917
async def add_message(self, message: Dict[str, str]) -> None:
3018
"""Add a message to memory."""
@@ -48,40 +36,4 @@ async def save(self) -> None:
4836
@abstractmethod
4937
async def load(self) -> None:
5038
"""Load memory from persistent storage."""
51-
pass
52-
53-
@staticmethod
54-
async def _maybe_await(value: Any) -> Any:
55-
"""Await value when needed; otherwise return directly."""
56-
if inspect.isawaitable(value):
57-
return await value
58-
return value
59-
60-
@staticmethod
61-
def _make_async_wrapper(sync_method):
62-
"""Wrap a synchronous method with an async callable."""
63-
async def _wrapped(self, *args, **kwargs):
64-
return sync_method(self, *args, **kwargs)
65-
_wrapped.__name__ = sync_method.__name__
66-
_wrapped.__doc__ = sync_method.__doc__
67-
return _wrapped
68-
69-
async def add_message_async(self, message: Dict[str, str]) -> None:
70-
"""Backward-compatible alias for async add_message()."""
71-
await self.add_message(message)
72-
73-
async def get_messages_async(self) -> List[Dict[str, str]]:
74-
"""Backward-compatible alias for async get_messages()."""
75-
return await self.get_messages()
76-
77-
async def clear_async(self) -> None:
78-
"""Backward-compatible alias for async clear()."""
79-
await self.clear()
80-
81-
async def save_async(self) -> None:
82-
"""Backward-compatible alias for async save()."""
83-
await self.save()
84-
85-
async def load_async(self) -> None:
86-
"""Backward-compatible alias for async load()."""
87-
await self.load()
39+
pass

multimind/memory/buffer.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def __init__(
5050
self.last_backup = datetime.now()
5151
self.backup_history: List[Dict[str, Any]] = []
5252

53-
# Load if storage path exists
54-
if self.storage_path and self.storage_path.exists():
55-
self.load()
53+
# Load explicitly via await memory.load() when needed.
5654

5755
async def add_message(
5856
self,
@@ -94,7 +92,7 @@ async def add_message(
9492
if self.enable_backup and (datetime.now() - self.last_backup).total_seconds() >= self.backup_interval:
9593
await self._backup()
9694

97-
def get_messages(self) -> List[Dict[str, str]]:
95+
async def get_messages(self) -> List[Dict[str, str]]:
9896
"""Get all messages from the buffer."""
9997
return self.messages
10098

@@ -108,7 +106,7 @@ def get_messages_with_metadata(self) -> List[Dict[str, Any]]:
108106
for i, msg in enumerate(self.messages)
109107
]
110108

111-
def clear(self) -> None:
109+
async def clear(self) -> None:
112110
"""Clear all messages from the buffer."""
113111
self.messages = []
114112
self.message_tokens = []
@@ -117,7 +115,7 @@ def clear(self) -> None:
117115
if self.storage_path and self.storage_path.exists():
118116
self.storage_path.unlink()
119117

120-
def save(self) -> None:
118+
async def save(self) -> None:
121119
"""Save buffer to persistent storage."""
122120
if not self.storage_path:
123121
return
@@ -135,7 +133,7 @@ def save(self) -> None:
135133
with open(self.storage_path, "w") as f:
136134
json.dump(data, f)
137135

138-
def load(self) -> None:
136+
async def load(self) -> None:
139137
"""Load buffer from persistent storage."""
140138
if not self.storage_path or not self.storage_path.exists():
141139
return
@@ -152,7 +150,7 @@ def load(self) -> None:
152150
self.backup_history = data["backup_history"]
153151
except Exception as e:
154152
print(f"Error loading buffer: {e}")
155-
self.clear()
153+
await self.clear()
156154

157155
def _remove_oldest(self) -> None:
158156
"""Remove the oldest message based on strategy."""
@@ -263,7 +261,7 @@ async def _backup(self) -> None:
263261

264262
# Save to disk if storage path exists
265263
if self.storage_path:
266-
self.save()
264+
await self.save()
267265

268266
def get_stats(self) -> Dict[str, Any]:
269267
"""Get buffer statistics."""

multimind/memory/cognitive_scratchpad.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def __init__(
4747
self.reasoning_chains: Dict[str, List[Dict[str, Any]]] = {} # chain_id -> chain data
4848
self.last_analysis = datetime.now()
4949
self.last_optimization = datetime.now()
50-
self.load()
5150

5251
async def add_message(self, message: Dict[str, str]) -> None:
5352
"""Add message and track reasoning steps."""
@@ -206,7 +205,7 @@ async def _remove_item(self, item_id: str) -> None:
206205
s for s in chain_data if s["item_id"] != item_id
207206
]
208207

209-
def get_messages(self) -> List[Dict[str, str]]:
208+
async def get_messages(self) -> List[Dict[str, str]]:
210209
"""Get all messages from all items."""
211210
messages = []
212211
for item in self.items:
@@ -237,7 +236,7 @@ async def save(self) -> None:
237236
"last_optimization": self.last_optimization.isoformat()
238237
}, f)
239238

240-
def load(self) -> None:
239+
async def load(self) -> None:
241240
"""Load items and steps from persistent storage."""
242241
if self.storage_path and self.storage_path.exists():
243242
with open(self.storage_path, 'r') as f:

multimind/memory/combined.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,30 @@ def __init__(
2020
async def add_message(self, message: Dict[str, str]) -> None:
2121
"""Add message to all memory types."""
2222
for memory in self.memories:
23-
await BaseMemory._maybe_await(memory.add_message(message))
23+
await memory.add_message(message)
2424

2525
async def get_messages(self) -> List[Dict[str, str]]:
2626
"""Get messages from all memory types."""
2727
all_messages = []
2828
for memory in self.memories:
29-
msgs = await BaseMemory._maybe_await(memory.get_messages())
29+
msgs = await memory.get_messages()
3030
all_messages.extend(msgs)
3131
return all_messages
3232

3333
async def clear(self) -> None:
3434
"""Clear all memory types."""
3535
for memory in self.memories:
36-
await BaseMemory._maybe_await(memory.clear())
36+
await memory.clear()
3737

3838
async def save(self) -> None:
3939
"""Save all memory types."""
4040
for memory in self.memories:
41-
await BaseMemory._maybe_await(memory.save())
41+
await memory.save()
4242

4343
async def load(self) -> None:
4444
"""Load all memory types."""
4545
for memory in self.memories:
46-
await BaseMemory._maybe_await(memory.load())
46+
await memory.load()
4747

4848
def get_memory(self, memory_type: type) -> Optional[BaseMemory]:
4949
"""Get a specific memory type instance."""

multimind/memory/contextual.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def __init__(
6464
self.context_summaries: Dict[str, str] = {} # context_id -> summary
6565
self.context_evolution: Dict[str, List[Dict[str, Any]]] = {} # context_id -> evolution history
6666
self.last_summarization = datetime.now()
67-
self.load()
6867

6968
async def add_message(self, message: Dict[str, str]) -> None:
7069
"""Add message to the appropriate context."""
@@ -423,7 +422,7 @@ async def _remove_context(self, context_id: str) -> None:
423422
del self.context_metadata[context_id]
424423
del self.context_weights[context_id]
425424

426-
def get_messages(self) -> List[Dict[str, str]]:
425+
async def get_messages(self) -> List[Dict[str, str]]:
427426
"""Get all messages from all contexts."""
428427
messages = []
429428
for context in self.contexts:
@@ -465,7 +464,7 @@ async def save(self) -> None:
465464
"last_summarization": self.last_summarization.isoformat()
466465
}, f)
467466

468-
def load(self) -> None:
467+
async def load(self) -> None:
469468
"""Load contexts from persistent storage."""
470469
if self.storage_path and self.storage_path.exists():
471470
with open(self.storage_path, 'r') as f:
@@ -540,9 +539,10 @@ async def traverse(current_id: str, depth: int) -> None:
540539

541540
async def get_context_stats(self) -> Dict[str, Any]:
542541
"""Get statistics about contexts."""
542+
messages = await self.get_messages()
543543
stats = {
544544
"total_contexts": len(self.contexts),
545-
"total_messages": len(self.get_messages()),
545+
"total_messages": len(messages),
546546
"relationship_types": {
547547
rel_type: 0 for rel_type in self.relationship_types
548548
},

multimind/memory/declarative.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ def __init__(
130130
self.last_temporal = datetime.now()
131131
self.last_causal = datetime.now()
132132
self.last_graph_update = datetime.now()
133-
self.load()
134133

135134
async def add_message(self, message: Dict[str, str]) -> None:
136135
"""Add message and analyze factual information."""
@@ -649,7 +648,7 @@ async def _remove_fact(self, fact_id: str) -> None:
649648
if fact_id in self.validation_history:
650649
del self.validation_history[fact_id]
651650

652-
def get_messages(self) -> List[Dict[str, str]]:
651+
async def get_messages(self) -> List[Dict[str, str]]:
653652
"""Get all messages from all facts."""
654653
messages = []
655654
for fact in self.facts:
@@ -706,7 +705,7 @@ async def save(self) -> None:
706705
"last_graph_update": self.last_graph_update.isoformat()
707706
}, f)
708707

709-
def load(self) -> None:
708+
async def load(self) -> None:
710709
"""Load facts from persistent storage."""
711710
if self.storage_path and self.storage_path.exists():
712711
with open(self.storage_path, 'r') as f:

multimind/memory/dnc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def __init__(
8787
self.last_optimization = datetime.now()
8888
self.last_analysis = datetime.now()
8989
self.last_backup = datetime.now()
90-
self.load()
9190

9291
async def add_message(self, message: Dict[str, str]) -> None:
9392
"""Add message to DNC memory."""
@@ -368,7 +367,7 @@ async def _create_backup(self) -> None:
368367
except Exception as e:
369368
print(f"Error creating backup: {e}")
370369

371-
def get_messages(self) -> List[Dict[str, str]]:
370+
async def get_messages(self) -> List[Dict[str, str]]:
372371
"""Get all messages from memory."""
373372
messages = []
374373
for item in self.items:
@@ -426,7 +425,7 @@ async def save(self) -> None:
426425
"last_backup": self.last_backup.isoformat()
427426
}, f)
428427

429-
def load(self) -> None:
428+
async def load(self) -> None:
430429
"""Load memory from persistent storage."""
431430
if self.storage_path and self.storage_path.exists():
432431
with open(self.storage_path, 'r') as f:

0 commit comments

Comments
 (0)