-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.py
More file actions
28 lines (21 loc) · 829 Bytes
/
memory.py
File metadata and controls
28 lines (21 loc) · 829 Bytes
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
import json
LOG_FILE = "logs.jsonl"
def log(entry: dict):
"""Append one interaction record to disk."""
with open(LOG_FILE, "a", encoding="utf-8") as f:
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
def read_logs(limit: int = 60) -> list:
"""Read the last N log entries from disk."""
try:
with open(LOG_FILE, "r", encoding="utf-8") as f:
lines = f.readlines()[-limit:]
return [json.loads(l.strip()) for l in lines if l.strip()]
except Exception:
return []
def build_history(limit: int = 5) -> list:
"""
Return a list of (payload, response) tuples from recent logs.
Passed to the advisor so it has conversational context.
"""
logs = read_logs(limit=limit)
return [(e.get("payload", ""), e.get("response", "")) for e in logs]