AgentOS-Core-V2 / memory.py
Tpayne101's picture
Create memory.py
486a373 verified
raw
history blame contribute delete
662 Bytes
import json
import os
class MemoryManager:
def __init__(self, agent_id):
self.agent_id = agent_id
self.file_path = f"memory_{agent_id}.json"
self._init_memory()
def _init_memory(self):
if not os.path.exists(self.file_path):
with open(self.file_path, "w") as f:
json.dump({"history": []}, f)
def save(self, data):
with open(self.file_path, "r") as f:
memory = json.load(f)
memory["history"].append(data)
with open(self.file_path, "w") as f:
json.dump(memory, f, indent=2)
os.sync() # Ensures the file actually saves on Hugging Face