data_analysis_agent / services /memory_manager.py
Shrouk04's picture
Upload 16 files
0fe6e4d verified
Raw
History Blame Contribute Delete
699 Bytes
import json
import os
def load_memory(agent_id):
path = f"agents/{agent_id}/memory.json"
if not os.path.exists(path):
return []
with open(path, "r", encoding="utf-8") as f:
return json.load(f)
def save_memory(agent_id, memory):
path = f"agents/{agent_id}/memory.json"
with open(path, "w", encoding="utf-8") as f:
json.dump(
memory,
f,
indent=2
)
def add_message(agent_id, role, content):
memory = load_memory(agent_id)
memory.append({
"role": role,
"content": content
})
memory = memory[-10:]
save_memory(agent_id, memory)