packages
@loop-engine/adapter-anthropic
Overview
@loop-engine/adapter-anthropic wraps the Anthropic Claude API as a Loop Engine AI actor. It handles prompt construction, response parsing, confidence extraction, and prompt hashing — returning an AIAgentActor and AIAgentSubmission ready for submission to the runtime. Guards run after the adapter returns. The adapter does not call transition() directly.
Installation
1npm install @loop-engine/adapter-anthropic @anthropic-ai/sdkPeer dependencies
1@anthropic-ai/sdk ^0.39.0Basic usage
1import Anthropic from '@anthropic-ai/sdk'2import { createAnthropicActorAdapter } from '@loop-engine/adapter-anthropic'3import { createLoopSystem } from '@loop-engine/sdk'4 5const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })6 7const adapter = createAnthropicActorAdapter(anthropic, {8 modelId: 'claude-opus-4-6',9 confidenceThreshold: 0.75,10})11 12const loopSystem = await createLoopSystem({ loops: [] })13const aggregateId = 'procurement-1'14 15"cmt">// Get the AI actor's decision for the current loop state16const { 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 description: 'Submit a purchase order recommendation',25 allowedActors: ['ai-agent', 'automation'],26 },27 ],28 instruction: 'Analyze the demand data and recommend whether to issue a purchase order.',29 evidence: { demandForecast: 0.89, currentStock: 42, reorderPoint: 50 },30})31 32"cmt">// Submit to the runtime — guards evaluate after this point33const result = await loopSystem.transition({34 aggregateId,35 signal: decision.signalId,36 actor,37 evidence: decision,38})Configuration reference
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| modelId | string | claude-opus-4-6 | Anthropic model to use |
| 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) |
What the adapter produces
The adapter returns an AIAgentActor with:
type: "ai-agent"provider: "anthropic"modelId— the model usedconfidence— extracted from the model responsepromptHash— SHA-256 of the prompt sent (for audit trail)