Examples
LLM Commerce Gateway Integration
Overview
LLM Commerce Gateway exposes inventory, pricing, suppliers, and order operations as structured tool interfaces for LLM-driven workflows. Loop Engine governs the workflow state around those tools so recommendations and actions happen through explicit transitions.
The boundary is strict: Commerce Gateway handles commerce data access and operation execution, while Loop Engine handles state, actor attribution, guard enforcement, approval gates, and audit records.
Architecture
1Demand Spike Signal2 |3 v4Loop Engine -------------------- engine.start('procurement.loop')5 | state: GATEWAY_QUERY6 |7 v8AI Actor ----------------------- GET /inventory/:sku9 | GET /demand-forecast/:sku Commerce10 | GET /suppliers/:sku ----> Gateway API11 | (read only)12 |13 v14Loop Engine -------------------- guard: confidence_threshold >= 0.8015 | state: PENDING_APPROVAL16 |17 v18Human Approves ----------------- engine.transition('approve_order', humanActor)19 |20 v21Automation Actor --------------- POST /purchase-orders Commerce22 | (write post-approval only) ---> Gateway API23 |24 v25Loop Engine -------------------- transition('place_order') -> engine.close(outcome: 'po_created')Three governed workflows
| Loop | Trigger | AI queries | Guard | Write operation | |------|---------|------------|-------|-----------------| | Procurement | Demand spike / low stock | Inventory, forecast, suppliers | confidence >= 0.80 + human approval | createPurchaseOrder | | Price change | Competitor price, margin alert | Price history, demand elasticity | confidence >= 0.85 + human approval | updatePrice | | Inventory adjustment | Expiry, damage, shrink | Current lots, expiry dates | human approval | writeDownInventory |
Using @loop-engine/adapter-commerce-gateway
1import { createLoopSystem } from '@loop-engine/sdk'2import { CommerceGatewayClient, buildProcurementActor } from '@loop-engine/adapter-commerce-gateway'3 4const gatewayClient = new CommerceGatewayClient({5 baseUrl: process.env.COMMERCE_GATEWAY_URL!,6 apiKey: process.env.COMMERCE_GATEWAY_API_KEY!7})8 9const procurementActor = buildProcurementActor({10 gatewayClient,11 llmProvider: 'claude', "cmt">// switch to 'openai' for GPT-4o12 apiKey: process.env.ANTHROPIC_API_KEY!,13 confidenceThreshold: 0.814})15 16const { engine } = await createLoopSystem({ loops: [procurementLoop] })17const evidence = await procurementActor({ instance: { data: { sku: 'LMB-BRS-001' } } })The governance boundary
Commerce Gateway owns structured commerce data and operation APIs. It executes reads and writes for inventory, demand, suppliers, pricing, and orders.
Loop Engine owns workflow progression, actor attribution, guard outcomes, human approval transitions, transition history, and learning feedback from outcomes.
Full procurement walkthrough
DEMAND_SPIKEstartsprocurement.loopand moves toGATEWAY_QUERY.- AI actor reads
inventory,demand-forecast, andsuppliersfrom Commerce Gateway. - LLM emits recommendation evidence (
recommendedQty,supplierId,confidence,rationale). confidence_thresholdpasses and loop moves toPENDING_APPROVAL.- Human approves; automation actor calls
createPurchaseOrder; loop executesplace_orderand closes withpo_created.