packages
@loop-engine/adapter-gemini
Overview
@loop-engine/adapter-gemini wraps Google's Gemini API as a Loop Engine AI actor using the @google/generative-ai SDK. Unlike OpenAI-compatible adapters, Gemini uses Google's native SDK and response shape. The adapter applies the same governance model as other Loop Engine AI adapters: guard enforcement in runtime and consistent actor audit fields.
Installation
1npm install @loop-engine/adapter-gemini @google/generative-aiPeer dependencies
1@google/generative-ai ^0.21.0Basic usage
1import { createGeminiActorAdapter } from '@loop-engine/adapter-gemini'2 3const adapter = createGeminiActorAdapter(process.env.GOOGLE_AI_API_KEY!, {4 modelId: 'gemini-1.5-pro',5 confidenceThreshold: 0.75,6})7 8const { actor, decision } = await adapter.createSubmission({9 loopId: 'procurement',10 loopName: 'SCM Procurement',11 currentState: 'pending_analysis',12 availableSignals: [13 {14 signalId: 'submit_recommendation',15 name: 'Submit Recommendation',16 allowedActors: ['ai-agent'],17 },18 ],19 instruction: 'Analyze demand data and recommend a purchase order decision.',20 evidence: { demandForecast: 0.87, currentStock: 45 },21})Configuration reference
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| modelId | string | gemini-1.5-pro | Gemini model (gemini-1.5-pro, gemini-1.5-flash, gemini-2.0-flash) |
| maxOutputTokens | number | 1024 | Max tokens in response |
| systemPrompt | string | — | Prepended to the system instruction |
| confidenceThreshold | number | 0.7 | Minimum confidence required (0-1) |
What the adapter produces
The adapter returns an AIAgentActor with:
type: "ai-agent"provider: "gemini"modelId— the model usedconfidence— extracted from the model responsepromptHash— SHA-256 of the prompt sent (for audit trail)
Note on JSON parsing
Gemini 1.5 occasionally wraps JSON responses in markdown code fences despite system instructions. The adapter strips these automatically before parsing. This cleanup becomes unnecessary in a later version that switches to responseMimeType: "application/json".
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.