47e93c2afa
- agent2_ansible.py : script principal (XMPP + MQTT) - config/system_prompt.txt : prompt spécialisé Ansible - skills/ansible_exec.py : ANSIBLE: (ad-hoc) + PLAYBOOK: (playbooks) - skills/memory.py, prompt_memory.py : chemins corrigés pour agent2_ansible - ansible/ansible.cfg + inventory/hosts : configuration de base Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""
|
|
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
|
|
TRIGGERS = {"REMEMBER:": "remember", "RECALL:": "recall"}
|
|
|
|
DB_PATH = Path("/opt/agent2_ansible/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: <clé> | <valeur>"
|
|
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)
|