""" Skill : REMEMBER / RECALL Mémorise et récupère des informations dans une base SQLite. """ import sqlite3 from pathlib import Path SKILL_NAME = "memory" TRIGGER = None # Géré via REMEMBER: et RECALL: séparément dans le loader DB_PATH = Path("/opt/agent/memory.db") def _get_conn(): conn = sqlite3.connect(DB_PATH) conn.execute(""" CREATE TABLE IF NOT EXISTS memory ( key TEXT PRIMARY KEY, value TEXT NOT NULL ) """) conn.commit() return conn def remember(args: str) -> str: if "|" not in args: return "Erreur : format attendu → REMEMBER: | " key, _, value = args.partition("|") key, value = key.strip(), value.strip() if not key or not value: return "Erreur : clé ou valeur vide." try: with _get_conn() as conn: conn.execute("INSERT OR REPLACE INTO memory (key, value) VALUES (?, ?)", (key, value)) return "Mémorisé : «{}» = «{}»".format(key, value) except Exception as e: return "Erreur mémoire : {}".format(e) def recall(args: str) -> str: key = args.strip() if not key: return "Erreur : clé vide." try: with _get_conn() as conn: row = conn.execute("SELECT value FROM memory WHERE key = ?", (key,)).fetchone() if row: return "Mémoire «{}» : {}".format(key, row[0]) return "Aucune information mémorisée pour «{}».".format(key) except Exception as e: return "Erreur mémoire : {}".format(e)