Skip to main content

How it works

SCP splits control into layers with very different latency budgets. Each layer answers what it can and forwards everything else.
The faster a layer, the more of the work it does. The brain is the last resort, not the default.

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.
Reflexes are part of your subclass. There is no framework hook to register them; that keeps the latency at zero.

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:
After 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.
Each ganglion runs its own tick loop, owns its own pattern store, and only escalates the unfamiliar.

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, default 0.6).
  • Adaptive memory has no similar match (similarity below threshold, default 0.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 body stays silent when:
  • 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.
The risk is just two knobs:
  • If confidenceThreshold is 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.
Defaults are conservative (high confidence required). Tune them per use case. The system is exactly as smart as the threshold you set.
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.

Octopus analogy

An octopus has nine brains. One central, eight in the arms. Most of the time the arm decides what to grab without asking the central brain anything. The central brain sets goals and intervenes when the arm has no answer. That is the same shape as SCP. Body decides routine things locally. Brain handles the unfamiliar.