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
+16 -9
View File
@@ -47,23 +47,30 @@ def _get_scheduler():
def _run_delegated_task(agent: str, task: str):
"""Exécutée par le scheduler : délègue la tâche à l'agent."""
import time as _time
from skills.delegate import execute as delegate_exec
from skills.reporting import log_execution
import paho.mqtt.publish as publish
import json as _json
start = _time.time()
result = delegate_exec("{} | {}".format(agent, task))
print("[SCHEDULE] Tâche exécutée [{}{}] : {}".format(
datetime.now().strftime("%Y-%m-%d %H:%M"), agent, task[:60]))
duration = _time.time() - start
ts = datetime.now().strftime("%Y-%m-%d %H:%M")
# Notifier via MQTT sur le topic de notification
status = "error" if "erreur" in result.lower() or "timeout" in result.lower() else "success"
log_execution("schedule", agent, task, status, result, duration)
print("[SCHEDULE] Tâche exécutée [{}{}] statut={} : {}".format(ts, agent, status, task[:60]))
# Notifier via MQTT
try:
cfg = _json.loads(Path("/opt/agent/config/config.json").read_text())
publish.single(
"agents/scheduler/notifications",
payload="[{}] {}\n{}".format(agent, task, result),
hostname=cfg.get("mqtt_host", "localhost"),
port=int(cfg.get("mqtt_port", 1883))
)
host = cfg.get("mqtt_host", "localhost")
port = int(cfg.get("mqtt_port", 1883))
payload = _json.dumps({"agent": agent, "task": task, "status": status,
"result": result[:500], "timestamp": ts})
publish.single("agents/scheduler/notifications", payload=payload,
hostname=host, port=port)
except Exception:
pass