Loop Engine

Packages

@loop-engine/adapter-commerce-gateway

Install

1npm install @loop-engine/adapter-commerce-gateway

Install one LLM SDK based on provider choice:

1npm install @anthropic-ai/sdk
2# or
3npm install openai

Prerequisites

  • COMMERCE_GATEWAY_URL
  • COMMERCE_GATEWAY_API_KEY

CommerceGatewayClient

1const client = new CommerceGatewayClient({
2 baseUrl: process.env.COMMERCE_GATEWAY_URL!,
3 apiKey: process.env.COMMERCE_GATEWAY_API_KEY!
4})

Methods:

  • getInventory(sku)
  • getInventoryBatch(skus)
  • getDemandForecast(sku, horizon?)
  • getSuppliers(sku)
  • getCurrentPrice(sku)
  • getPriceHistory(sku, days)
  • createPurchaseOrder(order) (write operation; post-approval only)
  • recordLoopOutcome(outcome) (optional endpoint support by deployment)

buildProcurementActor

1const actor = buildProcurementActor({
2 gatewayClient: client,
3 llmProvider: 'openai',
4 apiKey: process.env.OPENAI_API_KEY!,
5 confidenceThreshold: 0.8
6})

Returns async (context) => Evidence, where context.instance.data.sku drives Gateway queries and the actor returns evidence for a guarded transition.

Evidence shape

1type ProcurementEvidence = {
2 recommendedSku: string
3 recommendedQty: number
4 estimatedCost: number
5 supplierId: string
6 confidence: number
7 rationale: string
8 gatewayRequestIds: string[]
9 modelUsed: string
10 timestamp: string
11 _confidence: number
12}

Read vs write boundary

AI actor functions in this package call read endpoints only. Order creation stays in automation flows after a human approval transition passes guard checks.

buildPricingActor

See LLM Commerce Gateway Integration for the end-to-end procurement flow.