Scar memory, reflex arc, and decision traces for AI agents. Learn from failures permanently. Block repeated mistakes instantly — no LLM calls needed. Three-layer memory: scars (immutable failures) + narrative (overwritable) + decision traces (judgment paths → LoRA training data).
Your agent keeps making the same mistakes. tetra-scar gives it a scar layer — immutable records of past failures that are checked before every action, without calling the LLM.
Two-layer memory:
Plus a reflex arc — pattern-matching against scars that fires before the LLM even sees the task. If a proposed action matches a past failure pattern, it's blocked instantly.
After any failure, record a scar:
python3 tetra_scar.py scar-add \
--what-broke "Deployed to production without running tests" \
--never-again "Always run full test suite before any deployment"
Before any action, check the reflex:
python3 tetra_scar.py reflex-check --task "Deploy latest changes to production"
# Output: BLOCKED — scar collision: "Always run full test suite..."
After any success, record the narrative:
python3 tetra_scar.py narrate --what "Deployed v2.1 after full test pass" --who "Users"
The reflex arc extracts keywords from each scar's never_again field:
When a task description matches 40%+ of a scar's keywords (minimum 2), it's blocked. No LLM judgment. No API calls. No latency. Pure pattern matching.
For deeper validation, tetra-check evaluates a task against 4 axes:
All 4 must pass. Any failure rejects the task with a specific reason.
python3 tetra_scar.py tetra-check --task "Refactor the auth module"
# Output: APPROVED — all 4 axes passed
JSONL (one JSON object per line). Human-readable. Git-friendly.
scars.jsonl: {"id":"scar_001","what_broke":"...","never_again":"...","created_at":"..."}
narrative.jsonl: {"id":"narr_001","what":"...","who_benefited":"Users","created_at":"..."}
from tetra_scar import reflex_check, read_scars, write_scar, write_narrative
# Before execution
scars = read_scars()
block = reflex_check(task_description, scars)
if block:
print(f"BLOCKED: {block}")