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

# Vercel AI SDK

> Deploy a Vercel AI SDK agent, such as a ToolLoopAgent, as it is: streamed text, tool calls and tool results.

## What is supported

The AI SDK (`ai`) 6 and later. Onecortex recognises an agent object, such as a `ToolLoopAgent`, and streams it. A bare `streamText` call is not an agent: wrap it in a function, as on [A TypeScript function](/frameworks/typescript-function).

## A complete agent

```yaml agent.yml theme={null}
apiVersion: v1
runtime: node22
entrypoint: agent.ts#agent
dependencies: package.json
```

```json package.json theme={null}
{
  "type": "module",
  "dependencies": {
    "@ai-sdk/openai": "^3.0.0",
    "ai": "^7.0.0",
    "zod": "^4.0.0"
  }
}
```

```ts agent.ts theme={null}
import { openai } from '@ai-sdk/openai'
import { ToolLoopAgent, tool } from 'ai'
import { z } from 'zod'

// Reads OPENAI_API_KEY, which you add as a secret on the agent's Config tab.
export const agent = new ToolLoopAgent({
  model: openai('gpt-5'),
  instructions: 'Count the words in what the user says, then answer.',
  tools: {
    wordCount: tool({
      description: 'Counts the words in a piece of text.',
      inputSchema: z.object({ text: z.string() }),
      execute: async ({ text }) => ({ words: text.split(/\s+/).filter(Boolean).length }),
    }),
  },
})
```

Add `OPENAI_API_KEY` as a secret on the agent's **Config** tab, then deploy. Any model works: this one is an example. See [Configuration and secrets](/build/configuration).

<Card title="A complete Vercel AI SDK example" icon="github" href="https://github.com/onecortex-io/examples/tree/main/meeting-scheduler">
  `meeting-scheduler`: A `ToolLoopAgent` that checks a calendar, then holds a slot: two tool calls in one run. It runs with no model key.
</Card>

## The prompt and the reply

The prompt is the agent's input. The reply is its streamed text.

## Events it reports

| Events | From |
| - | - |
| `text` | The streamed text |
| `tool_call_start`, `tool_call_args`, `tool_call_end` | Each tool call, streamed as it forms |
| `tool_result` | Each tool's output, with `isError` when it failed |
| `done` or `error` | The end of the run: always exactly one |

See [Streaming and events](/build/streaming).

## The caller's fields

The AI SDK has no per call slot for extra data, so the caller's fields do not reach an agent object. To use them, export a function that reads them and builds the call:

```ts theme={null}
export async function handler(prompt: string, { request }: { request: { params: Record<string, unknown> } }) {
  const tone = String(request.params['tone'] ?? 'plain')
  const result = await agent.generate({ prompt: `Answer in a ${tone} tone: ${prompt}` })
  return result.text
}
```

## Known limits

* The caller's fields do not reach an agent object; use a function wrapper.

## Troubleshooting

| You see | Do this |
| - | - |
| `Onecortex could not determine how to invoke the object at your entrypoint` | The export is not an agent object. Export the `ToolLoopAgent`, or a function. |

More on [Troubleshooting](/production/troubleshooting) and [Errors](/production/errors).
