refactor(brain): Fast-Path als Skill-Capability — fast_patterns im Manifest
Frueher: Spotify-spezifische Patterns hardcoded in agent.py — jeder neue
Steuer-Skill haette wieder Brain-Code-Aenderungen gebraucht.
Jetzt: jeder Skill deklariert seine eigenen Patterns im Manifest unter
fast_patterns: [{match, args, reply}]. Brain iteriert generisch, kein
Skill bekommt Sonderbehandlung.
- agent.py: _try_skill_fast_path liest aus skills.list_skills(), keine
Spotify-Konstanten mehr. skill_create/skill_update Tool-Schema kennt
fast_patterns (mit Beispiel + Wann-nutzen-Hinweis).
- skills.py: _normalize_fast_patterns validiert Regex + filtert kaputte
Eintraege; create_skill/update_skill akzeptieren das Feld.
- main.py: einmalige Lifespan-Migration — wenn spotify-Skill existiert
und kein fast_patterns hat, werden die alten Hardcoded-Patterns
rueberkopiert. Idempotent, laeuft bei jedem Restart sicher mehrfach.
- seed_rules.py: neue Regel `seed/skill-rule/fast-patterns-for-control`
erklaert ARIA wann sie das Feature nutzen soll (reines Steuern: ja,
kreativer Output / Parametrisierung: nein) — mit Beispiel.
Trade-off: Volume-Patterns (lauter/leiser) fallen aus dem Fast-Path raus,
weil die Multi-Step-Logik (GET state → compute → PUT) sich nicht
deklarativ ausdruecken laesst. Wer das zurueck will: Spotify-Skill um
einen action=volume_relative-Arg erweitern der die Mathe intern macht.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -164,6 +164,7 @@ def create_skill(
|
||||
pip_packages: Optional[list[str]] = None,
|
||||
author: str = "aria",
|
||||
config_schema: Optional[list] = None,
|
||||
fast_patterns: Optional[list] = None,
|
||||
) -> dict:
|
||||
"""Legt einen neuen Skill an. Wirft ValueError bei ungueltigen Inputs.
|
||||
|
||||
@@ -213,6 +214,7 @@ def create_skill(
|
||||
"version": "1.0",
|
||||
"author": author,
|
||||
"config_schema": _normalize_config_schema(config_schema),
|
||||
"fast_patterns": _normalize_fast_patterns(fast_patterns),
|
||||
"version_history": [],
|
||||
}
|
||||
write_manifest(name, manifest)
|
||||
@@ -261,6 +263,38 @@ def _normalize_config_schema(schema: Optional[list]) -> list:
|
||||
return out
|
||||
|
||||
|
||||
def _normalize_fast_patterns(patterns: Optional[list]) -> list:
|
||||
"""Filter + Normalisiert fast_patterns. Erwartet Liste von Dicts mit:
|
||||
- match (str) : Regex, wird gegen normalisierten User-Text (lowercase,
|
||||
Endsatzzeichen weg, Whitespace gestrafft) gematched.
|
||||
Sollte mit ^...$ anchored sein damit keine Teilmatches
|
||||
reinrutschen. re.IGNORECASE wird automatisch gesetzt.
|
||||
- args (dict?): Args fuer run_skill — leerer Dict wenn weggelassen.
|
||||
- reply (str) : Fixe Antwort die ohne Claude an den User geht.
|
||||
|
||||
Patterns mit kaputter Regex werden ausgefiltert + geloggt — sonst wuerde
|
||||
der ganze Fast-Path-Pass jedes Mal crashen wenn ARIA mal ein Pattern
|
||||
falsch baut."""
|
||||
if not patterns:
|
||||
return []
|
||||
out = []
|
||||
for p in patterns:
|
||||
if not isinstance(p, dict):
|
||||
continue
|
||||
match = (p.get("match") or "").strip()
|
||||
reply = (p.get("reply") or "").strip()
|
||||
if not match or not reply:
|
||||
continue
|
||||
try:
|
||||
re.compile(match)
|
||||
except re.error as exc:
|
||||
logger.warning("fast_patterns: Regex %r kaputt — geskippt: %s", match, exc)
|
||||
continue
|
||||
args = p.get("args") if isinstance(p.get("args"), dict) else {}
|
||||
out.append({"match": match, "args": args, "reply": reply[:300]})
|
||||
return out
|
||||
|
||||
|
||||
def _setup_venv(skill_dir: Path, pip_packages: list[str]) -> None:
|
||||
venv = skill_dir / "venv"
|
||||
logger.info("venv erstellen: %s", venv)
|
||||
@@ -307,6 +341,8 @@ def update_skill(name: str, patch: dict) -> dict:
|
||||
manifest[k] = v
|
||||
if "config_schema" in patch:
|
||||
manifest["config_schema"] = _normalize_config_schema(patch["config_schema"])
|
||||
if "fast_patterns" in patch:
|
||||
manifest["fast_patterns"] = _normalize_fast_patterns(patch["fast_patterns"])
|
||||
|
||||
# Code austauschen
|
||||
if "entry_code" in patch and patch["entry_code"]:
|
||||
|
||||
Reference in New Issue
Block a user