Loop Engine

Examples

OpenClaw Integration

Overview

OpenClaw handles delivery and replies across messaging channels, while Loop Engine owns state transitions, actor constraints, and guard decisions.

Approval gates are runtime policy checks, not prompt conventions. Even if an agent asks to self-approve, a transition with allowedActors: ['human'] rejects non-human actors.

Architecture

1User (WhatsApp)
2 |
3 | "approve rpl-001"
4 v
5OpenClaw Gateway ------------------------------------.
6 | |
7 | engine.transition('approve', humanActor) |
8 v |
9Loop Engine |
10 | |
11 |- guard: approval_obtained ✅ |
12 |- allowedActors: ['human'] ✅ |
13 v |
14PENDING_BUYER_APPROVAL -> PO_TRIGGERED |
15 | |
16 '--- loop.transitioned --------------------------'
17 "✅ Approved. Loop closed."

Using @loop-engine/adapter-openclaw

1import { createLoopSystem } from '@loop-engine/sdk'
2import { OpenClawEventBus } from '@loop-engine/adapter-openclaw'
3import { replenishmentLoop } from './loops/replenishment'
4 
5const eventBus = new OpenClawEventBus({
6 channel: 'whatsapp',
7 target: '+15551234567',
8 events: ['loop.transition.executed', 'loop.completed', 'loop.guard.failed'],
9 approvalStates: ['PENDING_BUYER_APPROVAL']
10})
11 
12const system = await createLoopSystem({
13 loops: [replenishmentLoop],
14 eventBus
15})

The approval flow

  1. Demand spike detection starts the loop with loop.started.
  2. The AI analysis transition moves from AI_ANALYSIS to PENDING_BUYER_APPROVAL.
  3. OpenClaw receives forwarded loop events and sends: ⚠️ Approval required: rpl-dc-east-001 ... Reply: approve rpl-dc-east-001 | reject rpl-dc-east-001.
  4. A buyer replies approve rpl-dc-east-001 from a phone.
  5. The OpenClaw skill calls engine.transition with a human actor.
  6. approval_obtained passes and the loop advances to PO_TRIGGERED.
  7. OpenClaw sends ✅ Approved. Loop advanced to: PO_TRIGGERED.

Why guards beat prompts

allowedActors and guard evaluation happen in the runtime transition engine, not in the language model output path. That keeps approval logic deterministic and testable.

Prompt injection can change model text, but it cannot bypass transition authorization or guard failures. This is the security boundary for agentic operations.

Installing the OpenClaw skill

1git clone https:"cmt">//github.com/loopengine/loop-examples
2cp -r loop-examples/openclaw-skill ~/.openclaw/skills/loop-engine

The skill supports:

  • start loop [loop-id]
  • transition [instance-id] [transition-id]
  • approve [instance-id]
  • reject [instance-id]
  • status [instance-id]
  • list loops

Source: loop-examples/openclaw-skill

Resources