Integrations
Vercel AI SDK
Official · StableBuilt-innpm: @loop-engine/adapter-vercel-ai
What it does
Vercel AI SDK handles streaming and model access. Loop Engine governs when and whether model-requested tool actions are authorized. Use Vercel AI SDK for model execution; use Loop Engine for guard enforcement, actor attribution, and audit trails.
Quick setup
-
Install
1npm install @loop-engine/adapter-vercel-ai ai -
Wrap a tool with governance
1import { z } from "zod";2import { streamText, tool } from "ai";3import { actorId, type ActorRef } from "@loop-engine/core";4import { wrapTool, type CoreTool } from "@loop-engine/adapter-vercel-ai";56"cmt">// `wrapTool` expects the adapter's `CoreTool` shape; bridge the Vercel AI `tool()` helper7"cmt">// by wrapping a thin CoreTool that delegates to the same work unit.8const baseTool = tool({9 description: "Submit purchase order",10 inputSchema: z.object({ vendor: z.string(), amount: z.number() }),11 execute: async ({ vendor, amount }) => ({ orderId: "PO-0042", vendor, amount })12});13const submitPurchaseOrder = wrapTool(baseTool as unknown as CoreTool<{ vendor: string; amount: number }, { orderId: string; vendor: string; amount: number }>, {14 loopDefinition: purchaseOrderLoop,15 engine,16 actor: {17 type: "ai-agent",18 id: actorId("ai:vercel-tool"),19 modelId: "gpt-4o",20 provider: "openai"21 } as ActorRef,22 requiresApproval: (input) => input.amount > 500023}); -
Run with streaming
1await streamText({2 model: openai("gpt-4o"),3 tools: { submitPurchaseOrder },4 prompt: "Submit a PO to Acme Medical for $9,200"5});
How it works
- Model requests tool invocation
- Adapter starts and advances loop transitions
- Approval gates hold high-impact actions
- Human decision unblocks execution
- Execution and evidence are appended to history
Configuration reference
| Option | Type | Default | Description |
|---|---|---|---|
| loopDefinition | LoopDefinition | required | Governance state machine for the tool |
| engine | LoopEngine | required | Runtime instance |
| requiresApproval | (input) => boolean | — | Predicate for human checkpointing |
| | | — | Notification hook |
| | | | Actor attribution for transition records |