Examples
Demand Signal
Demand signal detection connects observed loop behavior to explicit follow-up actions without letting signal rules mutate state directly.
Detection flow
Signals are detections, not actors. Runtime callers decide whether to start a new loop from the emitted signal.
Signal rule usage
1import { createSignalEngine, thresholdBreachRule } from "@loop-engine/signals"2 3const signalEngine = createSignalEngine()4signalEngine.registerRule(5 thresholdBreachRule({6 field: "demandChange",7 operator: "gt",8 threshold: 0.759 })10)Lumebondé detection example
1const events = [2 {3 type: "loop.transition.executed",4 loopId: "scm.replenishment",5 aggregateId: "repl-lmb-001",6 orgId: "lumebonde",7 occurredAt: new Date().toISOString(),8 correlationId: "corr-1",9 eventId: "evt-1",10 fromState: "SIGNAL_DETECTED",11 toState: "AI_ANALYSIS",12 transitionId: "start_analysis",13 actor: { type: "automation", id: "system:router" },14 evidence: { demandChange: 0.89, sku: "LMB-BRS-001", currentStock: 142, reorderPoint: 280 }15 }16] as any17 18const signals = signalEngine.process(events)19"cmt">// signals[0]?.type === "THRESHOLD_BREACH"Triggering loop start
1signalEngine.subscribe(async (signal) => {2 await engine.start({3 loopId: "scm.replenishment",4 aggregateId: aggregateId(`repl-${Date.now()}`),5 orgId: "lumebonde",6 actor: { type: "system", id: "system:signal-engine" },7 metadata: { sourceSignalType: signal.type, sourceSignalId: signal.id }8 })9})Full source
- https://github.com/loopengine/loop-examples/tree/main/demand-signal