File size: 691 Bytes
d67d436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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}")