Spaces:
Running
Running
File size: 1,300 Bytes
c119621 ae7e237 2fe5352 ae7e237 c119621 ae7e237 c119621 ae7e237 2fe5352 ae7e237 2fe5352 ae7e237 2fe5352 ae7e237 2fe5352 ae7e237 2fe5352 c119621 ae7e237 2fe5352 ae7e237 2fe5352 ae7e237 2fe5352 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# ./core/memory_store.py
import json
import os
from datetime import datetime
MEMORY_DIR = "data/memory"
if not os.path.exists(MEMORY_DIR):
#os.makedirs(MEMORY_DIR)
os.makedirs(MEMORY_DIR, exist_ok=True)
def generate_label(history):
"""
Simple label generator (can upgrade later with LLM)
"""
for msg in history:
if msg["role"] == "client":
return msg["content"][:40]
return "Conversation"
def save_state(session_id, state):
filepath = os.path.join(MEMORY_DIR, f"{session_id}.json")
data = {
"session_id": session_id,
"created_at": getattr(state, "created_at", datetime.now().isoformat()),
"last_updated": datetime.now().isoformat(),
"label": generate_label(state.history),
"history": state.history,
"agents": getattr(state, "agent_logs", {})
}
with open(filepath, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2)
print(f"📁 MEMORY DIR: {os.path.abspath(MEMORY_DIR)}\n💾 SAVED SESSION: {session_id} at {filepath}")
def load_state(session_id):
filepath = os.path.join(MEMORY_DIR, f"{session_id}.json")
if not os.path.exists(filepath):
return None
with open(filepath, "r", encoding="utf-8") as f:
return json.load(f) |