43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
"""Dump agent_message + recent audit for a session id (local debug)."""
|
|||
|
|
import sys
|
||
|
|
from sqlalchemy import text
|
||
|
|
|
||
|
|
from app.config.database import get_agent_session_local
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> None:
|
||
|
|
sid = sys.argv[1] if len(sys.argv) > 1 else "sess-16d0331d027"
|
||
|
|
Session = get_agent_session_local()
|
||
|
|
with Session() as s:
|
||
|
|
rows = s.execute(
|
||
|
|
text(
|
||
|
|
"SELECT seq_no, role, intent, content FROM agent_message "
|
||
|
|
"WHERE session_id=:sid ORDER BY seq_no"
|
||
|
|
),
|
||
|
|
{"sid": sid},
|
||
|
|
).fetchall()
|
||
|
|
print(f"session={sid} messages={len(rows)}")
|
||
|
|
for seq, role, intent, content in rows:
|
||
|
|
print(f"\n=== seq={seq} role={role} intent={intent} ===")
|
||
|
|
print(content[:2000] if content else "")
|
||
|
|
try:
|
||
|
|
audits = s.execute(
|
||
|
|
text(
|
||
|
|
"SELECT id, created_at, event_type, path, status_code, "
|
||
|
|
"LEFT(COALESCE(payload,''), 600) "
|
||
|
|
"FROM audit_log WHERE session_id=:sid "
|
||
|
|
"ORDER BY id DESC LIMIT 20"
|
||
|
|
),
|
||
|
|
{"sid": sid},
|
||
|
|
).fetchall()
|
||
|
|
except Exception as e:
|
||
|
|
print("audit_log query failed:", e)
|
||
|
|
audits = []
|
||
|
|
print(f"\naudit rows={len(audits)}")
|
||
|
|
for row in audits:
|
||
|
|
print(row)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|