Examples
AI Replenishment (Claude)
What this example shows
An AI actor using @loop-engine/adapter-anthropic analyzes inventory evidence and submits a replenishment recommendation. A confidence threshold gate keeps low-confidence decisions from reaching execution. A human approval transition remains required for final ordering.
Loop diagram
1IDLE ----[signal_detected]----> ANALYZING2ANALYZING --[submit_recommendation]--> PENDING_APPROVAL3ANALYZING --[insufficient_confidence]--> IDLE4PENDING_APPROVAL --[approve]--> ORDERED (terminal)5PENDING_APPROVAL --[reject]--> IDLEActors
| Actor | Type | Transitions | Guards |
|---|---|---|---|
| signal detector | automation | signal_detected | none |
| claude recommender | ai-agent | submit_recommendation | confidence-threshold |
| buyer approver | human | approve, reject | human-only |
Key annotated snippet
1import Anthropic from "@anthropic-ai/sdk";2import { createAnthropicActorAdapter } from "@loop-engine/adapter-anthropic";3 4const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });5const claude = createAnthropicActorAdapter(anthropic, {6 modelId: "claude-opus-4-6",7 confidenceThreshold: 0.758});9 10const { actor, decision } = await claude.createSubmission({11 loopId: "scm.replenishment",12 loopName: "SCM Replenishment",13 currentState: "ANALYZING",14 availableSignals: [{ signalId: "submit_recommendation", name: "Submit Recommendation" }],15 instruction: "Recommend reorder quantity based on stock and forecast.",16 evidence: {17 sku: "LMB-BRS-001",18 currentStock: 142,19 reorderPoint: 280,20 forecastedDemand: 52721 }22});23 24await engine.transition({25 aggregateId: "repl-lmb-001" as never,26 transitionId: "submit_recommendation" as never,27 actor,28 evidence: decision29});What emitted events look like
1{2 type: "loop.transition.executed",3 loopId: "scm.replenishment",4 aggregateId: "repl-lmb-001",5 transitionId: "submit_recommendation",6 fromState: "ANALYZING",7 toState: "PENDING_APPROVAL",8 actor: { type: "ai-agent", id: "agent:claude-replenishment" },9 occurredAt: "2026-03-13T12:24:00.422Z"10}Try it yourself
1cd loop-examples/ai-actors/claude2pnpm install3pnpm devSee AI Replenishment (OpenAI) for the identical loop with a different provider adapter.