Examples
AI Replenishment
AI replenishment shows model-swappable actor wiring with identical loop constraints and deterministic approval policy.
Loop behavior
- States:
SIGNAL_DETECTED -> AI_ANALYSIS -> PENDING_BUYER_APPROVAL -> PO_TRIGGERED - AI actor transition:
recommend_replenishment - Hard guards:
confidence_threshold,approval_obtained - Human-only transition:
approve_replenishment
Scenario
Lumebondé Bond Repair Serum (LMB-BRS-001) spikes +89% at DC-East with currentStock=142, reorderPoint=280, forecastedDemand=527, and leadTimeDays=14.
Loop definition
1"cmt">// @no-typecheck2import { LoopBuilder } from "@loop-engine/sdk"3 4const replenishmentLoop = LoopBuilder5 .create("scm.replenishment", "scm")6 .version("1.0.0")7 .description("Triggered replenishment from demand signal")8 .state("SIGNAL_DETECTED")9 .state("AI_ANALYSIS")10 .state("PENDING_BUYER_APPROVAL")11 .state("PO_TRIGGERED", { isTerminal: true })12 .state("DEFERRED", { isTerminal: true })13 .initialState("SIGNAL_DETECTED")14 .transition({ id: "start_analysis", from: "SIGNAL_DETECTED", to: "AI_ANALYSIS", actors: ["automation"] })15 .transition({16 id: "recommend_replenishment",17 from: "AI_ANALYSIS",18 to: "PENDING_BUYER_APPROVAL",19 actors: ["ai-agent", "automation"],20 guards: [21 {22 id: "confidence_threshold" as never,23 description: "AI confidence >= 0.75",24 failureMessage: "Confidence below threshold",25 severity: "hard",26 evaluatedBy: "external"27 }28 ]29 })30 .transition({ id: "approve_replenishment", from: "PENDING_BUYER_APPROVAL", to: "PO_TRIGGERED", actors: ["human"] })31 .outcome({32 id: "replenishment_triggered",33 description: "PO submitted",34 valueUnit: "replenishment_triggered",35 businessMetrics: [36 { id: "m_replenishment", label: "Replenishment triggered", unit: "count" }37 ]38 })39 .build()Anthropic and OpenAI actors
Both providers create the same AIAgentActor shape and submit evidence with identical keys.
1"cmt">// @no-typecheck2import { actorId } from "@loop-engine/core"3import type { AIAgentActor } from "@loop-engine/actors"4 5const claudeActor: AIAgentActor = {6 type: "ai-agent",7 id: actorId("agent:demand-forecaster"),8 agentId: "claude-sonnet-4-20250514",9 gatewaySessionId: "claude-session-001"10}11 12const openAiActor: AIAgentActor = {13 type: "ai-agent",14 id: actorId("agent:demand-forecaster"),15 agentId: "gpt-4o",16 gatewaySessionId: "openai-session-001"17}Guard outcomes
1"cmt">// confidence 0.58 -> held at AI_ANALYSIS2const lowConfidence = await engine.transition({3 aggregateId,4 transitionId: transitionId("recommend_replenishment"),5 actor: claudeActor,6 evidence: { ai_confidence: 0.58, ai_reasoning: "Insufficient certainty" }7})8"cmt">// lowConfidence.status === "guard_failed"9 10"cmt">// confidence 0.82 -> advances to PENDING_BUYER_APPROVAL11const highConfidence = await engine.transition({12 aggregateId,13 transitionId: transitionId("recommend_replenishment"),14 actor: openAiActor,15 evidence: { ai_confidence: 0.82, ai_reasoning: "Demand spike sustained" }16})17"cmt">// highConfidence.status === "executed"Human approval gate
1"cmt">// AI tries to execute human-only transition2const rejected = await engine.transition({3 aggregateId,4 transitionId: transitionId("approve_replenishment"),5 actor: claudeActor,6 evidence: { approval_obtained: true }7})8"cmt">// rejected.status === "rejected"9 10"cmt">// Human executes approval path11await engine.transition({12 aggregateId,13 transitionId: transitionId("approve_replenishment"),14 actor: { type: "human", id: "buyer@lumebonde.com" },15 evidence: { approved: true, approval_obtained: true }16})Provider parity
The loop definition, transition IDs, guards, and state progression remain identical across Anthropic and OpenAI implementations.
- https://github.com/loopengine/loop-examples/tree/main/ai-actors/claude
- https://github.com/loopengine/loop-examples/tree/main/ai-actors/openai