Spaces:
Build error
Build error
| # memory_core.py | |
| import json | |
| import os | |
| MEMORY_FILE = "agent_memory.json" | |
| def load_memory(): | |
| """Load stored agent memory if it exists.""" | |
| if not os.path.exists(MEMORY_FILE): | |
| return {} | |
| with open(MEMORY_FILE, "r") as f: | |
| return json.load(f) | |
| def save_memory(memory): | |
| """Save updated memory.""" | |
| with open(MEMORY_FILE, "w") as f: | |
| json.dump(memory, f, indent=2) | |
| def update_memory(agent_id, key, value): | |
| """Store learning or result per agent.""" | |
| memory = load_memory() | |
| if agent_id not in memory: | |
| memory[agent_id] = {} | |
| memory[agent_id][key] = value | |
| save_memory(memory) | |
| print(f"[Memory] {agent_id} learned {key}: {value}") |