Ajouter skill prompt_memory (ChromaDB Phase 1) + loader générique multi-triggers

This commit is contained in:
2026-03-07 10:56:53 +00:00
parent 9f45e4a2d6
commit 30f3d00bec
3 changed files with 128 additions and 17 deletions
+22 -16
View File
@@ -7,21 +7,28 @@ Format attendu dans la réponse du LLM :
READ: <url>
REMEMBER: <clé> | <valeur>
RECALL: <clé>
PROMPT_SAVE: <nom> | <texte>
PROMPT_GET: <nom>
PROMPT_LIST:
PROMPT_DEL: <nom>
Interface d'un skill :
- Trigger unique → TRIGGER = "CMD:" + execute(args) -> str
- Multi-triggers → TRIGGERS = {"CMD1:": "fn1", "CMD2:": "fn2"}
"""
import importlib
import re
from pathlib import Path
SKILLS_DIR = Path(__file__).parent
# Map trigger -> fonction d'exécution
# Map trigger (uppercase) -> callable
_REGISTRY: dict = {}
def load_skills():
"""Charge tous les skills disponibles dans le dossier skills/."""
_REGISTRY.clear()
for py_file in SKILLS_DIR.glob("*.py"):
for py_file in sorted(SKILLS_DIR.glob("*.py")):
if py_file.name.startswith("_") or py_file.name == "loader.py":
continue
module_name = "skills.{}".format(py_file.stem)
@@ -31,19 +38,18 @@ def load_skills():
print("[Skills] Impossible de charger {} : {}".format(py_file.name, e))
continue
# Skill avec un seul trigger (ex: SEARCH:, READ:)
# Skill avec trigger unique : TRIGGER = "CMD:" + execute()
if hasattr(mod, "TRIGGER") and mod.TRIGGER and hasattr(mod, "execute"):
_REGISTRY[mod.TRIGGER] = mod.execute
_REGISTRY[mod.TRIGGER.upper()] = mod.execute
print("[Skills] Chargé : {}".format(mod.TRIGGER))
# Skill memory : deux triggers
if py_file.stem == "memory":
if hasattr(mod, "remember"):
_REGISTRY["REMEMBER:"] = mod.remember
print("[Skills] Chargé : REMEMBER:")
if hasattr(mod, "recall"):
_REGISTRY["RECALL:"] = mod.recall
print("[Skills] Chargé : RECALL:")
# Skill avec plusieurs triggers : TRIGGERS = {"CMD1:": "fn_name", ...}
if hasattr(mod, "TRIGGERS") and isinstance(mod.TRIGGERS, dict):
for trigger, fn_name in mod.TRIGGERS.items():
fn = getattr(mod, fn_name, None)
if fn:
_REGISTRY[trigger.upper()] = fn
print("[Skills] Chargé : {}".format(trigger))
def run_skills(llm_response: str) -> tuple[bool, str]:
"""
@@ -52,10 +58,10 @@ def run_skills(llm_response: str) -> tuple[bool, str]:
Sinon retourne (False, réponse originale).
"""
for line in llm_response.splitlines():
line = line.strip()
stripped = line.strip()
for trigger, fn in _REGISTRY.items():
if line.upper().startswith(trigger):
args = line[len(trigger):].strip()
if stripped.upper().startswith(trigger):
args = stripped[len(trigger):].strip()
result = fn(args)
return True, result
return False, llm_response