Examples
Loading
Loading
Examples
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.
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')| 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 |
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' } } })Commerce Gateway handles data access and commerce operations. Loop Engine governs the workflow around those operations.
| System | Owns | |------|------| | Commerce Gateway | Commerce data (inventory, pricing, orders, catalog), LLM tool definitions for commerce operations, and commerce API execution | | Loop Engine | Workflow state, actor attribution, guard enforcement, human approval gates, transition audit trail, and learning signals |
Neither system needs to know the internal workings of the other. The adapter is the only coupling point.
DEMAND_SPIKE starts procurement.loop and moves to GATEWAY_QUERY.inventory, demand-forecast, and suppliers from Commerce Gateway.recommendedQty, supplierId, confidence, rationale).confidence_threshold passes and loop moves to PENDING_APPROVAL.createPurchaseOrder; loop executes place_order and closes with po_created.