Integrations
Vercel AI SDK
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 { streamText, tool } from "ai";2import { wrapTool } from "@loop-engine/adapter-vercel-ai";34const submitPurchaseOrder = wrapTool(5 tool({6 description: "Submit purchase order",7 parameters: z.object({ vendor: z.string(), amount: z.number() }),8 execute: async ({ vendor, amount }) => ({ orderId: "PO-0042", vendor, amount })9 }),10 {11 loopDefinition: purchaseOrderLoop,12 engine,13 requiresApproval: ({ amount }) => amount > 500014 }15); -
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 |
| onApprovalRequired | (loopId, input) => Promise<void> | — | Notification hook |
| actor | Actor | ai-agent | Actor attribution for transition records |
Troubleshooting
- Streaming parse errors — Enforce strict JSON response contracts in tool output.
- Model resolution errors — Verify the selected model provider is available in your AI SDK config.