packages
@loop-engine/adapter-grok
Overview
@loop-engine/adapter-grok wraps xAI's Grok API as a Loop Engine AI actor. Grok uses an OpenAI-compatible API, and this adapter uses the openai npm package pointed at https://api.x.ai/v1. It follows the same governance model as adapter-anthropic and adapter-openai: identical guard enforcement and the same audit trail shape.
Installation
1npm install @loop-engine/adapter-grok openaiPeer dependencies
1openai ^4.0.0Basic usage
1import OpenAI from 'openai'2import { createGrokActorAdapter } from '@loop-engine/adapter-grok'3 4"cmt">// Grok uses the OpenAI SDK with xAI's base URL5const grok = new OpenAI({6 apiKey: process.env.XAI_API_KEY,7 baseURL: 'https://api.x.ai/v1',8})9 10const adapter = createGrokActorAdapter(process.env.XAI_API_KEY!, {11 modelId: 'grok-3',12 confidenceThreshold: 0.75,13})14 15const { actor, decision } = await adapter.createSubmission({16 loopId: 'procurement',17 loopName: 'SCM Procurement',18 currentState: 'pending_analysis',19 availableSignals: [20 {21 signalId: 'submit_recommendation',22 name: 'Submit Recommendation',23 allowedActors: ['ai-agent'],24 },25 ],26 instruction: 'Analyze demand data and recommend a purchase order decision.',27 evidence: { demandForecast: 0.91, currentStock: 38 },28})Configuration reference
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| modelId | string | grok-3 | Grok model to use (grok-2, grok-2-mini, grok-3, grok-3-mini) |
| maxTokens | number | 1024 | Max tokens in response |
| systemPrompt | string | — | Optional system prompt prepended to loop context |
| confidenceThreshold | number | 0.7 | Minimum confidence required (0-1) |
| baseURL | string | https://api.x.ai/v1 | xAI API endpoint (override for testing) |
What the adapter produces
The adapter returns an AIAgentActor with:
type: "ai-agent"provider: "grok"modelId— the model usedconfidence— extracted from the model responsepromptHash— SHA-256 of the prompt sent (for audit trail)
Guard enforcement note
The confidence guard runs at the runtime level — not inside the adapter. If you configure a confidence-threshold guard on the transition, the runtime will block the transition if the model's confidence falls below the threshold regardless of what the adapter returns.