Rapports et gestion des erreurs

- skills/reporting.py : REPORT: / REPORT_ERRORS: avec historique SQLite
- skills/delegate.py : log des exécutions + détection erreurs + notification MQTT
- skills/schedule_tasks.py : log des tâches planifiées
- agent1.py : abonnement agents/errors + agents/scheduler/notifications → alerte XMPP
- cli.py : commandes /report et /errors
- system_prompt.txt : REPORT: et REPORT_ERRORS: ajoutés

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 13:20:32 +00:00
parent 305999d8bf
commit 144f481320
6 changed files with 245 additions and 23 deletions
+41 -3
View File
@@ -102,6 +102,37 @@ def on_mqtt_message(client, userdata, msg):
mqtt_publish(reply_to, reply)
print("[MQTT] Réponse envoyée sur {}".format(reply_to))
def on_mqtt_error(client, userdata, msg):
"""Reçoit les erreurs des agents et notifie l'utilisateur via XMPP."""
try:
data = json.loads(msg.payload.decode(errors="replace"))
agent = data.get("agent", "?")
task = data.get("task", "?")
error = data.get("error", "?")
source = data.get("source", "?")
notif = "[ERREUR][{}] Agent : {}\nTâche : {}\nErreur : {}".format(
source.upper(), agent, task[:100], error[:300])
print(notif)
if xmpp_bot:
xmpp_bot.send_message(mto=ADMIN_JID, mbody=notif, mtype='chat')
except Exception as e:
print("[MQTT] Erreur parsing notification : {}".format(e))
def on_mqtt_notification(client, userdata, msg):
"""Reçoit les notifications du scheduler."""
try:
data = json.loads(msg.payload.decode(errors="replace"))
status = data.get("status", "?")
agent = data.get("agent", "?")
task = data.get("task", "?")[:80]
ts = data.get("timestamp", "?")
# Notifier XMPP seulement en cas d'erreur ou de succès important
if status == "error" and xmpp_bot:
notif = "[PLANIF ERREUR] {} | {}{}\nStatut : {}".format(ts, agent, task, status)
xmpp_bot.send_message(mto=ADMIN_JID, mbody=notif, mtype='chat')
except Exception as e:
print("[MQTT] Erreur parsing notification scheduler : {}".format(e))
def start_mqtt_listener():
global mqtt_pub_client
@@ -111,10 +142,17 @@ def start_mqtt_listener():
mqtt_pub_client.loop_start()
sub = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id="agent1_sub")
sub.on_message = on_mqtt_message
sub.message_callback_add("agents/agent1/inbox", on_mqtt_message)
sub.message_callback_add("agents/errors", on_mqtt_error)
sub.message_callback_add("agents/scheduler/notifications", on_mqtt_notification)
sub.on_message = on_mqtt_message # fallback
sub.connect(MQTT_HOST, MQTT_PORT)
sub.subscribe(MQTT_INBOX)
print("[MQTT] Agent1 écoute sur {}".format(MQTT_INBOX))
sub.subscribe([
(MQTT_INBOX, 0),
("agents/errors", 0),
("agents/scheduler/notifications", 0),
])
print("[MQTT] Agent1 écoute sur {}, agents/errors, agents/scheduler/notifications".format(MQTT_INBOX))
sub.loop_forever()
# ── BOT XMPP ─────────────────────────────────────────────────────────────