How it works
SCP splits control into layers with very different latency budgets. Each layer answers what it can and forwards everything else.Reflex
Reflexes are sync rules inside the body class. They fire before any cache lookup. Use them for things that must never block on a network call.Muscle (PatternStore)
The pattern store is a feature-keyed cache. It hashes the feature vector you build, looks for an exact match, and falls back to k-nearest similarity over numeric and string fields.lookup returns { decision, confidence, source } or null. source is "exact" or "similar".
When you observe an outcome, report it back so the cache can self-correct:
failureThreshold consecutive failures the entry is purged and the brain is consulted fresh.
Brain (LLM)
The brain is whichever bridge you wired in. It runs only when the lower layers had nothing.learnFromBrain writes through to both the pattern store (for exact replay) and the adaptive memory (for generalization). The next similar situation is answered locally.
The ganglion pattern
A ganglion is a cluster of nerve cells outside the brain. In SCP, every body is a ganglion: a small, fast decision unit that handles routine work without consulting the central brain.When does the brain wake?
This is the question every reviewer asks first. The answer is not magic. It is a configurable confidence gate. The body wakes the brain when:- The pattern store has no confident match (confidence below
confidenceThreshold, default0.6). - Adaptive memory has no similar match (similarity below
threshold, default0.8). - A reflex fires an emergency event with priority
CRITICAL. - The developer explicitly calls
this.emit("stuck", state)or any other event the orchestrator routes to the brain.
- The pattern store has an exact-hash match above the confidence threshold.
- Adaptive memory finds a similar past situation that scores above its threshold.
- A reflex handles the situation locally and no event is emitted.
- If
confidenceThresholdis too high, the brain is called too often and cost stays high. - If it is too low, the body executes stale decisions in genuinely novel situations.
explorationRate is the safety valve against drift: even confident cache hits are occasionally returned as misses so the brain can re-validate. Set to 0 for fully deterministic behavior.