> ## Documentation Index
> Fetch the complete documentation index at: https://trytilde.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Vercel AI SDK

> Run a Vercel AI SDK agent on Tilde with the @trytilde/sdk-vercel-ai-node adapter.

The Vercel AI SDK adapter runs an AI SDK `ToolLoopAgent`, or plain `generateText` and `streamText` calls, on Tilde. It works with AI SDK 6.

<Card title="Example agent" icon="github" href="https://github.com/trytilde/tilde/tree/main/sdk/ts/examples/vercel-ai-example-agent" horizontal>
  A complete Vercel AI SDK agent with bundled tools, in the Tilde open-source repository.
</Card>

## Install

```bash theme={"system"}
npm i @trytilde/sdk @trytilde/sdk-vercel-ai-node ai @ai-sdk/openai
```

## How it works

AI SDK 6 agents take no per-call tools. The adapter uses the agent's call options instead. Spread `tildeCallOptions` into the agent once, then pass `tildeAiSdk(ctx)` on each call. The adapter then adds the channel's tools, the agent's Tilde and bundled tools, skills, and new user input to that call.

```typescript src/agent.ts theme={"system"}
import { inference, type AgentContext } from "@trytilde/sdk";
import {
  convertToAiSdkMessages,
  tildeAiSdk,
  tildeCallOptions,
} from "@trytilde/sdk-vercel-ai-node";
import { createOpenAI } from "@ai-sdk/openai";
import { ToolLoopAgent, convertToModelMessages, stepCountIs } from "ai";
import { bundledTools } from "./bundled-tools.js";

// Model calls go through Tilde's inference gateway.
const openai = createOpenAI(inference("default"));

// At module scope, so `tilde deploy` registers its instructions.
export const agent = new ToolLoopAgent({
  id: "support-agent",
  instructions: "You are a support assistant. Reply with the channel tools.",
  model: openai.responses("gpt-4o-mini"),
  stopWhen: stepCountIs(8),
  experimental_telemetry: { isEnabled: true, functionId: "support-agent" },
  ...tildeCallOptions,
});

export async function respond(ctx: AgentContext) {
  const history = await ctx.message.history();
  const messages = await convertToAiSdkMessages({
    messages: history.items,
    context: ctx,
  });
  await agent.generate({
    messages: await convertToModelMessages(messages),
    ...tildeAiSdk(ctx, { bundled: bundledTools }),
  });
}
```

For plain `generateText` or `streamText` calls, use `prepareTildeCall`, or convert tools yourself with `convertToAiSdkTools`.

## Feature compatibility

| Feature | Support | Notes |
| - | - | - |
| Inference gateway | Yes | Build the provider with `createOpenAI(inference(name))`, or the equivalent for your provider. |
| Framework trace spans | Yes | Set `experimental_telemetry` to record model calls, with token usage, in the trace. |
| Tilde and channel tools | Yes | |
| Bundled tools | Yes | Write AI SDK `tool()` values, with a summary in `metadata.tilde`. |
| Prompt versioning | Partial | Registers a `ToolLoopAgent`'s `instructions` as `<id>/instructions`. |
| Native skills | No | Skills arrive as `list_skills` and `read_skill` tools, with a summary in the instructions. |
| New input during a run | Yes | |

## Limitations

* **Static instructions only.** The AI SDK accepts only a string for `instructions`, so there is no dynamic prompt to version. Use [`definePrompt`](/docs/prompts/overview#declare-a-prompt) for templates.
* **Custom `prepareCall`.** If your agent defines its own `prepareCall`, discovery warns, because the adapter relies on it.
* **Provider-defined tools.** Provider-defined tools, and tools without an `execute` function, are not published to Tilde.
* **Tool names.** Bundled tool names must match `^[a-zA-Z0-9_-]{1,64}$`, and must not clash with other tools.
* **No native skills.** The AI SDK has no skills concept. Deploy-time skills come from `defineSkills`.
* **Private settings.** The adapter reads the agent's instructions from settings outside the AI SDK's public API. It is tested against AI SDK 6.0.280.
