import json import sys from sqlalchemy import text from app.config.database import get_agent_engine hours = int(sys.argv[1]) if len(sys.argv) > 1 else 3 e = get_agent_engine() with e.connect() as c: rows = c.execute( text( """ SELECT created_at, trace_id, event_type, agent_type, actor_id, decision, input_summary FROM audit_log WHERE created_at >= NOW() - INTERVAL :h HOUR ORDER BY created_at DESC LIMIT 60 """ ), {"h": hours}, ).mappings().all() for row in rows: d = dict(row) s = d.get("input_summary") if isinstance(s, str): try: s = json.loads(s) except json.JSONDecodeError: pass d["input_summary"] = s print(json.dumps(d, ensure_ascii=False, default=str))