Vercel AI SDK Integration
Use @sequenceware/vercel-ai to enforce Sequenceware policies on every Vercel AI SDK tool execution.
1. Install packages
npm install @sequenceware/sdk @sequenceware/vercel-ai ai
2. Create an Sequenceware client and run
import { SequencewareClient } from '@sequenceware/sdk';
const client = new SequencewareClient({
baseUrl: 'http://localhost:3000',
apiKey: process.env.SEQUENCEWARE_API_KEY!,
agentId: 'vercel-ai-agent',
});
const runId = await client.startRun(undefined, {
source: 'vercel-ai',
task: 'governed tool execution',
});
3. Wrap tools with sequencewareMiddleware
import { generateText, tool } from 'ai';
import { openai } from '@ai-sdk/openai';
import { sequencewareMiddleware, isSequencewareBlockingError } from '@sequenceware/vercel-ai';
import { z } from 'zod';
try {
const result = await generateText({
model: openai('gpt-4.1'),
prompt: 'Create a deployment plan and store it in infra/plan.md',
...sequencewareMiddleware({
client,
runId,
tools: {
write_file: tool({
inputSchema: z.object({
path: z.string(),
content: z.string(),
}),
execute: async ({ path, content }) => {
// perform the side effect
return { ok: true, path, bytes: content.length };
},
}),
},
}),
});
console.log(result.text);
} catch (error) {
if (isSequencewareBlockingError(error)) {
console.error('Blocked by Sequenceware:', error.message);
} else {
throw error;
}
} finally {
await client.completeRun(runId);
}
Behavior
allowed/warn: tool executes and result is tracked.blocked: throwsSequencewareToolBlockedError.awaiting_approval: throwsSequencewareApprovalRequiredError.
Notes
- The integration expects an explicit
runId; it does not auto-manage runs. - By default it fails open if Sequenceware is unreachable (
onCheckError: 'allow'). - Set
onCheckError: 'block'to fail closed.