text stringlengths 0 59.1k |
|---|
## Prerequisites |
- Node.js 20+ |
- `pnpm` or `npm` |
- Netlify account and the `netlify` CLI (`npm install -g netlify-cli`) |
- OpenAI API key (VoltOps keys optional) |
## 1. Generate project files |
### Option A: VoltAgent CLI |
```bash |
npm run volt deploy --target netlify |
``` |
The command scaffolds a `netlify.toml` file with function defaults. Add `netlify/functions/voltagent.ts` and a VoltAgent entry file (`src/index.ts`) following the example below. |
### Option B: Manual setup |
1. Create `netlify.toml` (see sample in step 4). |
2. Add `netlify/functions/voltagent.ts` with the Netlify handler. |
3. Configure VoltAgent in `src/index.ts` and import it from the handler. |
## 2. Environment variables |
Netlify Functions expose secrets through `process.env`, so you can rely on VoltAgent's default environment detection. Use the CLI to define keys: |
```bash |
netlify secrets:set OPENAI_API_KEY |
netlify secrets:set VOLTAGENT_PUBLIC_KEY |
netlify secrets:set VOLTAGENT_SECRET_KEY |
``` |
## 3. VoltAgent setup |
Create the agent once and reuse it across invocations. The example keeps the serverless Hono provider so the same HTTP routes (agents, workflows, observability) stay available. |
```ts title="src/index.ts" |
import { Agent, VoltAgent } from "@voltagent/core"; |
import { serverlessHono } from "@voltagent/serverless-hono"; |
import { openai } from "@ai-sdk/openai"; |
import { weatherTool } from "./tools"; |
const assistant = new Agent({ |
name: "netlify-function-agent", |
instructions: "Answer user questions and call tools when needed.", |
model: openai("gpt-4o-mini"), |
tools: [weatherTool], |
}); |
const voltAgent = new VoltAgent({ |
agents: { assistant }, |
serverless: serverlessHono(), |
}); |
export function getVoltAgent() { |
return voltAgent; |
} |
``` |
## 4. Netlify function handler |
Use the helper exported from `@voltagent/serverless-hono` to convert Lambda events into Fetch requests automatically. |
```ts title="netlify/functions/voltagent.ts" |
import { createNetlifyFunctionHandler } from "@voltagent/serverless-hono"; |
import { getVoltAgent } from "../src/index"; |
const voltAgent = getVoltAgent(); |
export const handler = createNetlifyFunctionHandler(voltAgent); |
``` |
## 5. `netlify.toml` |
```toml |
[functions] |
node_bundler = "esbuild" |
directory = "netlify/functions" |
[[redirects]] |
from = "/*" |
to = "/.netlify/functions/voltagent/:splat" |
status = 200 |
force = true |
``` |
The redirect sends every HTTP route (`/agents`, `/observability`, `/workflows`, …) to the same function, mimicking the Cloudflare Workers routing behaviour. |
## 6. Run locally |
```bash |
pnpm install |
pnpm netlify dev |
``` |
Use `curl` against `http://localhost:8888/agents` or other routes to validate. |
## 7. Deploy |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.