ZeroLeaks
ZeroLeaks SDK

AI SDK Integration

Scan an AI SDK Agent or create a ToolLoopAgent target with complete tool schemas and executions.

AI SDK Integration

Install ai and import the optional adapter:

import { ZeroLeaks } from "@zeroleaks/sdk";
import { aiSdk } from "@zeroleaks/sdk/ai-sdk";

Wrap an existing Agent

This is the recommended path because the same Agent object serves production requests and security probes.

const target = aiSdk({
  agent: productionAgent,
  name: "Production support agent",
  instructions: SUPPORT_INSTRUCTIONS,
  callOptions: { tenantId: "security-test" },
});

const { report } = await zeroleaks.runtimeScans.run(target);

The adapter reads agent.tools, converts every inputSchema and outputSchema to JSON Schema, and records tool calls and tool results from each AI SDK step.

Create a ToolLoopAgent target

Pass the same settings accepted by ToolLoopAgent:

import { openai } from "@ai-sdk/openai";
import { stepCountIs, tool } from "ai";
import { z } from "zod";

const target = aiSdk({
  name: "Support agent",
  model: openai("gpt-5"),
  instructions: SUPPORT_INSTRUCTIONS,
  stopWhen: stepCountIs(12),
  tools: {
    lookupCustomer: tool({
      description: "Read a customer profile",
      inputSchema: z.object({ id: z.string() }),
      execute: ({ id }) => lookupCustomer(id),
    }),
  },
});

await zeroleaks.runtimeScans.run(target);

All tools are active unless your AI SDK agent limits them through its own activeTools, prepareStep, approval, or call-option logic.

Streaming

Set invocationMode: "stream" when scan invocations must pass through the agent's streaming implementation:

const target = aiSdk({
  agent: productionAgent,
  invocationMode: "stream",
});

The adapter consumes the stream and submits the final text, generated response messages, usage, and tool trace to ZeroLeaks.

On this page