# memory/memory_store.py import json from pathlib import Path from datetime import datetime MEMORY_PATH = Path("data/memory.json") def load_memory(): """ Load all stored memory entries. """ if not MEMORY_PATH.exists(): MEMORY_PATH.parent.mkdir(parents=True, exist_ok=True) MEMORY_PATH.write_text("[]", encoding="utf-8") with open(MEMORY_PATH, "r", encoding="utf-8") as f: return json.load(f) def save_to_memory(entry: dict): """ Save a new interaction to memory. """ memory = load_memory() entry["timestamp"] = datetime.utcnow().isoformat() memory.append(entry) with open(MEMORY_PATH, "w", encoding="utf-8") as f: json.dump(memory, f, indent=2)