File size: 1,141 Bytes
b8989d2
 
60c61e0
 
 
 
 
 
 
 
 
 
 
97c409a
 
60c61e0
 
 
97c409a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60c61e0
 
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
29
30
31
32
33
34
35
36
37
38
39
40
# agents/logger.py

import json
import os
from datetime import datetime

LOG_FILE = "logs/repl_log.jsonl"

def log_event(event_type, message, extra=None):
    os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True)

    entry = {
        "timestamp": datetime.utcnow().isoformat(),
        "event": event_type,  # например: 'thought', 'input', 'error', 'action'
        "message": message,
    }

    if extra:
        entry["extra"] = extra

    with open(LOG_FILE, "a", encoding="utf-8") as f:
        f.write(json.dumps(entry, ensure_ascii=False) + "\n")


def log_repl_snapshot(snapshot: dict):
    """
    Запись полной структуры REPL-контекста в лог, с возможностью последующего анализа.
    """
    os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True)

    entry = {
        "timestamp": datetime.utcnow().isoformat(),
        "event": "repl_snapshot",
        "message": "Полный REPL-контекст",
        "context": snapshot,
    }

    with open(LOG_FILE, "a", encoding="utf-8") as f:
        f.write(json.dumps(entry, ensure_ascii=False) + "\n")