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
1"cmt">// @no-typecheck2import Anthropic from '@anthropic-ai/sdk'3import { createAnthropicActorAdapter } from '@loop-engine/adapter-anthropic'4import { createLoopSystem } from '@loop-engine/sdk'5 6const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })7 8const adapter = createAnthropicActorAdapter(anthropic, {9 modelId: 'claude-opus-4-6',10 confidenceThreshold: 0.75,11})12 13const loopSystem = await createLoopSystem({ loops: [] })14const aggregateId = 'procurement-1'15 16"cmt">// Get the AI actor's decision for the current loop state17const { actor, decision } = await adapter.createSubmission({18 loopId: 'procurement',19 loopName: 'SCM Procurement',20 currentState: 'pending_analysis',21 availableSignals: [22 {23 signalId: 'submit_recommendation',24 name: 'Submit Recommendation',25 description: 'Submit a purchase order recommendation',26 allowedActors: ['ai-agent', 'automation'],27 },28 ],29 instruction: 'Analyze the demand data and recommend whether to issue a purchase order.',30 evidence: { demandForecast: 0.89, currentStock: 42, reorderPoint: 50 },31})32 33"cmt">// Submit to the runtime — guards evaluate after this point34const result = await loopSystem.engine.transition({35 aggregateId,36 transitionId: decision.transitionId,37 actor,38 evidence: decision,39})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)