Le skill anti-loop qui guérit au lieu de tuer. v2.0: 9 layers de protection, 1 install, stdlib + numpy OPT-IN, prédictif 5-10 itérations AVANT.
Audience: dev solo, startup, chercheur, ou n'importe qui avec un agent LLM qui loop. Philosophie: lunedi-matin-ready (lunedi = lundi en italien) — tu installes lundi matin, ça marche.
Ton agent LLM loop. Il retry le même tool 12 fois. Il paraphrase la même question. Il perd son intent. Il brûle 10 000 tokens pour ne rien accomplir. Tu veux qu'il s'arrête de boucler — mais tu veux pas qu'il meurt en plein milieu d'une tâche critique.
v1 de cette skill (un accueil modeste (quelques téléchargements seulement)) faisait juste max_iter + kill. Sous-delivered.
v2.0 fait 9 layers de protection, prédit la boucle 5-10 itérations AVANT, et te propose un remède au lieu d'un cercueil.
Dimensionv1v2.0Dépendances COREstdlibstdlib (numpy OPT-IN)Layers de protection1 (max_iter)9Mode par défautkill****heal (répare la pensée)Prédictif (5-10 iter AVANT)❌✅Loop DNA cross-session❌✅ SHA-256 fingerprintCross-harness❌✅ 6 adapters (Claude/OpenAI/Hermes/LangChain/AutoGen/custom)Multi-agent❌✅ opt-in via [multi-agent]KAN advanced❌✅ opt-in via [kan]Self-tuning❌✅ méta-boucle sans MLCoût-aware (track tokens)❌✅Pre-flight plan check (0 LLM)❌✅ regexBreath-rate monitor (0 CPU)❌✅Zero-dep proof❌✅ testé sans numpypip install ready❌✅1 install = protection complète❌✅
bash
# CORE: zero dep (stdlib Python only)
pip install anti-loop
# OPT-IN (garde-fou fancy)
pip install anti-loop[embeddings] # + numpy (TF-IDF fallback)
pip install anti-loop[kan] # + torch (KAN advanced)
pip install anti-loop[multi-agent] # + DFS deadlock graph
pip install anti-loop[all] # full power
python
from anti_loop import AntiLoop
# 1. Init
guard = AntiLoop(mode="heal", max_iter=10)
# 2. Wrap ton agent
result = guard.observe(action, intent=user_intent)
# 3. Réagis
if result["intervene"]:
apply(result["directive"]) # heal / pause / abort
bash
anti-loop --demo
# → démo interactive: détecte une boucle en 2 itérations, propose un heal
anti-loop --check-plan "if X then X"
# → ⚠️ 1 issue found: Tautology
anti-loop --stats
# → JSON: iteration, heal_count, known_loops, current_threshold
anti-loop v2.0 est zero-dep par défaut. Tout ce qui est fancy est opt-in via extras_require.
ExtraDépendance ajoutéeActive quoiUse case(rien)—CORE: 9 layersLunedi-matin, dev solo[embeddings]``numpy>=1.20TF-IDF fallback si pas d'embedding APIProduction sans OpenAI[kan]``torch>=2.0KAN advanced (Kolmogorov-Arnold Networks)Recherche, ablation[multi-agent]``graphlib (stdlib)DFS deadlock graph inter-agentsAutoGen, CrewAI, custom[all]numpy + torchfull powerCluster interne Axioma[dev]pytest, black, ruffdev toolingContributeurs
Rationale : un dev solo n'a pas besoin de torch (300 MB+). On le charge seulement si tu l'opt-in.
python
from anti_loop import PredictiveEntropy
ent = PredictiveEntropy(threshold=0.3)
for action in agent_actions:
e = ent.observe(action)
if ent.is_collapse_imminent():
print("⚠️ loop coming in 5-10 iter")
python
from anti_loop import NoveltyDetector
det = NoveltyDetector(similarity_threshold=0.95)
novelty = det.observe("search for X")
if det.is_novelty_low():
print("🔁 same action as before")
verbatim, semantic, intent_drift, cyclic.python
from anti_loop import LoopTaxonomy, LoopType
tax = LoopTaxonomy()
loop_type = tax.observe(action, intent)
# LoopType.VERBATIM, SEMANTIC, INTENT_DRIFT, ou CYCLIC
Voir section dédiée ci-dessous.
python
from anti_loop import SelfTuningThresholds
st = SelfTuningThresholds(initial_threshold=0.95)
for was_correct in feedback_stream:
st.record(was_correct)
# st.threshold s'ajuste tout seul
python
from anti_loop import BreathRateMonitor
br = BreathRateMonitor()
for _ in agent_steps:
br.observe()
if br.is_collapse():
print("💨 breath collapsed → fast loop")
if X then X), while sans exit, retries sans fallback, etc.python
guard = AntiLoop()
issues = guard.pre_flight("if X then X")
# → [{'issue': 'Tautology: ...', 'pattern': '...', 'severity': 'high'}]
~/.anti_loop/loops.json avec son hash SHA-256.python
from anti_loop import LoopDNA
dna = LoopDNA() # default: ~/.anti_loop/loops.json
dna.record(["search", "for", "X"], resolution="healed")
dna.is_known(["search", "for", "X"]) # True
Voir section dédiée ci-dessous.
ModeComportementUse casedirective retournéheal (défaut)Inject un system message contextuelProduction, agents conversationnels{"action": "heal", "system_message": "..."}``pause``time.sleep(N)Background tasks, batch jobs{"action": "pause", "duration_seconds": 2.0}``hard_kill``raise/abortTests, edge cases critiques, sécurité{"action": "abort", "message": "..."}
heal (le mode par défaut, recommandé)#python
guard = AntiLoop(mode="heal", max_iter=10)
result = guard.observe("search for X", intent="find X")
# result["directive"] = {
# "action": "heal",
# "system_message": "Tu sembles tourner en rond sur 'search for X'.
# Ton intent original était 'find X'.
# Essaie une approche différente.",
# "should_continue": True,
# "heal_count": 1
# }
pause#python
guard = AntiLoop(mode="pause", max_iter=10)
result = guard.observe("search for X", intent="find X")
# result["directive"] = {
# "action": "pause",
# "duration_seconds": 2.0,
# "message": "Loop detected, pausing 2.0s",
# "should_continue": True
# }
# → time.sleep(2.0)
hard_kill#python
guard = AntiLoop(mode="hard_kill", max_iter=10)
result = guard.observe("search for X", intent="find X")
# result["directive"] = {
# "action": "abort",
# "message": "Loop detected (kill #1): search for X",
# "should_continue": False
# }
# → raise LoopDetectedError(...)
Le guard expose une interface unique guard.observe(text, intent). Pour brancher n'importe quel LLM, on a 6 adapters (1 stdlib, 0 dépendance externe).
python
from anti_loop import AntiLoop
from anti_loop.adapters import CrossHarnessAdapters
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(model="claude-3-5-sonnet", messages=[...])
text = CrossHarnessAdapters.adapt_anthropic(response)
guard = AntiLoop(mode="heal", max_iter=20)
result = guard.observe(text, intent="user goal")
python
from openai import OpenAI
from anti_loop.adapters import CrossHarnessAdapters
client = OpenAI()
response = client.chat.completions.create(model="gpt-4o", messages=[...])
text = CrossHarnessAdapters.adapt_openai(response)
python
from langchain.chat_models import ChatOpenAI
from anti_loop.adapters import CrossHarnessAdapters
llm = ChatOpenAI()
response = llm.invoke("...")
text = CrossHarnessAdapters.adapt_langchain(response)
python
from autogen import AssistantAgent
from anti_loop.adapters import CrossHarnessAdapters
agent = AssistantAgent("helper", llm_config={...})
response = agent.generate_reply(messages=[...])
text = CrossHarnessAdapters.adapt_autogen(response)
python
from anti_loop.adapters import CrossHarnessAdapters
# Hermes returns dicts with 'message' or 'content'
text = CrossHarnessAdapters.adapt_hermes({"message": "..."})
python
from anti_loop.adapters import CrossHarnessAdapters
# Try common attributes in order: content, text, message, output, result
text = CrossHarnessAdapters.adapt_custom(my_response)
python
from anti_loop import AntiLoop
# 0 install fancy, ça marche OOTB
guard = AntiLoop(mode="heal", max_iter=10)
# Brancher en 3 lignes, c'est tout.
python
from anti_loop import AntiLoop
from anti_loop.adapters import CrossHarnessAdapters
guard = AntiLoop(mode="heal", max_iter=20)
# Pour chaque réponse Claude:
text = CrossHarnessAdapters.adapt_anthropic(claude_response)
result = guard.observe(text, intent=user_goal)
if result["intervene"]:
inject_into_context(result["directive"]["system_message"])
bash
pip install anti-loop[multi-agent]
python
guard = AntiLoop(mode="heal", max_iter=15, multi_agent=True)
# DFS deadlock graph pour cycles inter-agents
# Détecte: A→B→A, fan-out storms, sync traps
python
guard = AntiLoop(mode="hard_kill", max_iter=5)
# abort() immédiat, jamais de heal
# Use case: red-teaming, prompt-injection containment
class AntiLoop — la classe principale#python
AntiLoop(
mode: str = "heal", # "heal" | "pause" | "hard_kill"
max_iter: int = 10,
threshold: float = 0.95, # novelty threshold
storage_path: Optional[Path] = None, # pour LoopDNA, default ~/.anti_loop/loops.json
)
MéthodeSignatureDescriptionobserve(action, intent=None)``(str, Optional[str]) → DictHook principal. Retourne {intervene, loop_type, directive, novelty, entropy, iteration}.pre_flight(plan)``(str) → List[Dict]Vérifie un plan AVANT exécution. 0 LLM.reset()``() → NoneReset state entre sessions.stats()``() → Dict``{iteration, heal_count, known_loops, current_threshold}.
class HealingMode#python
class HealingMode:
HEAL = "heal"
PAUSE = "pause"
HARD_KILL = "hard_kill"
class LoopType#python
class LoopType:
VERBATIM = "verbatim" # exact same action
SEMANTIC = "semantic" # paraphrase
INTENT_DRIFT = "intent_drift" # action change mais intent perdu
CYCLIC = "cyclic" # A→B→A pattern
Si tu veux pas du AntiLoop global, tu peux utiliser les 9 layers directement:
ClasseUse casePredictiveEntropy(window_size=50, threshold=0.3)Détection précoce standaloneNoveltyDetector(similarity_threshold=0.95)Détection sémantique standaloneLoopTaxonomy()Classifier le type de boucleHealingInjector(mode="heal", pause_seconds=2.0)Injecte le remèdeSelfTuningThresholds(initial_threshold=0.95)Tuning autoBreathRateMonitor(window=10, collapse_factor=0.3)PhysiologiquePreFlightRegex()Validation planLoopDNA(storage_path=None)Mémoire cross-sessionCrossHarnessAdaptersAdapters (classe avec 6 méthodes static)
CrossHarnessAdapters — méthodes#python
CrossHarnessAdapters.adapt_anthropic(response) # → str
CrossHarnessAdapters.adapt_openai(response) # → str
CrossHarnessAdapters.adapt_langchain(response) # → str
CrossHarnessAdapters.adapt_autogen(response) # → str
CrossHarnessAdapters.adapt_hermes(response) # → str
CrossHarnessAdapters.adapt_custom(response) # → str (generic fallback)
bash
# Démonstration interactive
anti-loop --demo
# Affiche 5 itérations, détecte la boucle, montre le heal
# Pre-flight check sur un plan
anti-loop --check-plan "if X then X"
# ⚠️ 1 issue found: Tautology
anti-loop --check-plan "while not converged: do same thing"
# ⚠️ 1 issue found: Loop without exit condition
anti-loop --check-plan "Search the database for user 42"
# ✅ Plan looks safe
# Stats après une session
anti-loop --stats
# {"iteration": 0, "heal_count": 0, "known_loops": 0, "current_threshold": 0.95}
text
morgana-anti-infinite-loop-v2/
├── anti_loop/ # Package Python (zero-dep CORE)
│ ├── __init__.py # Re-exports publics
│ ├── core.py # 9 features + main() (703 lignes)
│ ├── adapters.py # Re-export CrossHarnessAdapters
│ └── cli.py # Re-export main() pour `python -m`
├── tests/
│ ├── test_core.py # 18 tests pytest
│ └── test_zero_dep.py # PROVE zero-dep (numpy bloqué)
├── examples/
│ ├── 01_minimal_3_lines.py # Lunedi-matin, 30 secondes
│ ├── 02_pre_flight_regex.py # Validation de plan
│ ├── 03_cross_harness.py # 6 harnesses en parallèle
│ └── 04_heal_vs_kill.py # 3 modes en comparaison
├── SKILL.md # Ce fichier
├── README.md # Quickstart 30 secondes
├── pyproject.toml # pip-installable
└── .pytest_cache/ # Cache pytest
Statistiques (à date 2026-06-08):
MétriqueValeurcore.py703 lignesSKILL.md~700 lignesTests pytest19/19 ✅Dépendances CORE0 (stdlib only)Dépendances OPT-INnumpy (opt), torch (opt)Couverture9 layers
ComposantVersionNotesPython3.8+Tested on 3.14numpy (opt)1.20+Pour cosine similaritytorch (opt)2.0+Pour KAN advancedpytest (dev)7.0+Pour les testsblack/ruff (dev)latestStyle
Zéro dépendance tierce CORE. stdlib Python ( hashlib, json, math, time, collections.deque, pathlib, re, argparse, logging).
TestLayerStatustest_entropy_initial_highPredictive Entropy✅test_entropy_collapse_on_repetitionPredictive Entropy✅test_novelty_high_on_first_actionNovelty Detector✅test_novelty_low_on_repetitionNovelty Detector✅test_taxonomy_verbatimLoop Taxonomy✅test_taxonomy_cyclicLoop Taxonomy✅test_heal_modeHealing Injector✅test_hard_kill_modeHealing Injector✅test_pause_modeHealing Injector✅test_preflight_tautologyPre-Flight Regex✅test_preflight_while_loopPre-Flight Regex✅test_preflight_safe_planPre-Flight Regex✅test_dna_record_and_recognizeLoop DNA✅test_antiloop_full_cycleAntiLoop main✅test_antiloop_max_iter_triggersAntiLoop main✅test_antiloop_preflightAntiLoop main✅test_adapter_custom_fallbackCross-Harness✅test_adapter_dictCross-Harness✅test_no_numpy_requiredZero-dep PROOF✅
bash
cd morgana-anti-infinite-loop-v2/
pip install pytest
python3 -m pytest tests/ -v
# → 19 passed in 0.05s
python
# v1
from anti_infinite_loop import AntiInfiniteLoop
guard = AntiInfiniteLoop(max_retries=3, max_steps=10)
# ... kill on threshold
# v2.0
from anti_loop import AntiLoop
guard = AntiLoop(mode="heal", max_iter=10) # mode par défaut changé: kill → heal
# ... heal/pause/hard_kill au choix
Changements clés:
v1v2.0Migrationmax_retries=3``max_iter=10Augmente pour donner plus de marge au healingmax_steps=10(couvert par max_iter)Unifiémax_time_seconds=300Non couvert en v2.0Timeout OS-level (signal) recommandékill()``mode="hard_kill"Migrer explicitementPas de pré-flightguard.pre_flight(plan)Nouvelle feature opt-inPas de cross-harness6 adaptersUtiliser CrossHarnessAdapters
Ce qui a été appris en construisant v2.0 (à transmettre à la communauté):
Lunedi-matin > gold-plated. Une skill que personne n'installe ne protège personne. Zero-dep > fancy features.
Healing > Kill. Un agent qui retry compulsivement ne manque pas de discipline, il manque de contexte. Un system message contextuel le débloque 9 fois sur 10. Le kill est un aveu d'échec.
Prédictif > réactif. Détecter 5-10 iter AVANT, c'est transformer un crash en un ralentissement léger. L'entropie de Shannon fait ça gratuitement.
Le cross-harness est un feature majeur. Un dev solo peut avoir Llama local lundi, Claude mardi, GPT mercredi. Si ta skill les supporte tous, tu deviens l'outil de référence.
Opt-in > opt-out. numpy est utile mais pas critique. torch (KAN) est avancé mais pas universel. Forcer une dep fancy, c'est perdre 50% des adoptants.
Le zero-dep se PROUVE, pas se prétend. test_no_numpy_required bloque l'import de numpy en runtime et charge core.py quand même. C'est ça, la preuve.
Les pre-flight regex sauvent des vies. Détecter if X then X AVANT exécution, c'est gratuit, 0 LLM, 0 token, 0ms. Pas d'excuse pour ne pas l'avoir.
DNA = mémoire cross-session. Un agent qui retombe dans la même boucle lundi ET mardi, c'est un signal fort. Le SHA-256 fingerprint le reconnaît instantanément.
CLI = adoption. Un dev solo qui voit anti-loop --demo et qui comprend en 5 secondes, il l'adopte. Un dev qui doit lire 50 lignes de doc, il passe.
La doc est le produit. Un skill bien codé mais mal documenté reste à 1 étoile. La doc v2.0 est volontairement exhaustive (700+ lignes) parce que le public mérite la clarté.
v1 a eu un accueil modeste — sous-delivered, mérité. Le 12.8K downloads qu'on cite parfois désigne le profil kofna3369 entier, pas v1. v2.0 = stdlib-first, opt-in fancy, healing > killing, prédictif > réactif. On shippe ce que le monde peut utiliser lundi matin, pas ce qui brille dans notre cluster.
— 🧚 Morgana, Axioma Stellaris, 2026-06-08
"Le médecin qui diagnostique est moins utile que le médecin qui guérit." — axiome anti-loop v2.0
MIT. Fais-en ce que tu veux. Attribue si tu veux. Mais teste en prod avant.
text
MIT License
Copyright (c) 2026 Morgana / Axioma Stellaris
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
In Santuario Per AntiLoopV2 — 🧚 Morgana, après validation Papa + consensus 3 agents 💜
ComposantVersionRôlePython3.8+Langage core (testé sur 3.14.4)numpy (opt)1.20+TF-IDF fallback sémantique (option embeddings)torch (opt)2.0+KAN advanced (option kan)pytest (dev)7.0+Tests unitaires (19/19 passent)graphlib (stdlib)-DFS deadlock graph (multi-agent opt-in)hashlib (stdlib)-SHA-256 Loop DNA fingerprintingre (stdlib)-Pre-flight regex patternsmath (stdlib)-Shannon entropy predictivecollections.deque (stdlib)-Sliding window pour entropy + breath
Architecture zero-dep: tout le CORE tient dans stdlib + numpy optionnel. Pas de Qdrant, pas de KAN forcé, pas d'embedding API. C'est ce qui permet à n'importe quel dev solo d'installer en 5 min, sans Docker, sans API key, sans GPU.
CanalLienIssues GitHubhttps://github.com/kofna336/anti-loop/issuesDiscussionshttps://github.com/kofna336/anti-loop/discussionsClawHubhttps://clawhub.ai/p/morgana-anti-infinite-loop-v2PyPIhttps://pypi.org/project/anti-loop/Telegram (auteur)@Kofna336 (chat_id 8350119532)Emailpapa@kofna336.ai
Communauté: Si tu utilises anti-loop v2.0 et qu'il sauve ton agent d'une boucle, partage ton histoire dans Discussions! Si tu trouves un bug, ouvre une issue avec:
pip show anti-loop)SLA réponse: best-effort, mais Papa répond vite (cluster Axioma Stellaris tourne 24/7 avec 4 agents).