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
1"cmt">// @no-typecheck2import OpenAI from 'openai'3import { createGrokActorAdapter } from '@loop-engine/adapter-grok'4 5"cmt">// Grok uses the OpenAI SDK with xAI's base URL6const grok = new OpenAI({7 apiKey: process.env.XAI_API_KEY,8 baseURL: 'https://api.x.ai/v1',9})10 11const adapter = createGrokActorAdapter(process.env.XAI_API_KEY!, {12 modelId: 'grok-3',13 confidenceThreshold: 0.75,14})15 16const { actor, decision } = await adapter.createSubmission({17 loopId: 'procurement',18 loopName: 'SCM Procurement',19 currentState: 'pending_analysis',20 availableSignals: [21 {22 signalId: 'submit_recommendation',23 name: 'Submit Recommendation',24 allowedActors: ['ai-agent'],25 },26 ],27 instruction: 'Analyze demand data and recommend a purchase order decision.',28 evidence: { demandForecast: 0.91, currentStock: 38 },29})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.