Create from scratch
Add VoltAgent to an existing TypeScript project. This guide walks through setting up the configuration, installing dependencies, and creating your first agent. To start from scratch, see Create with VoltAgent CLI guide.
Create Project Directory
Create a new project directory and initialize npm:
mkdir my-voltagent-project
cd my-voltagent-project
npm init -y
Configure TypeScript
Create a tsconfig.json file:
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "bundler",
"esModuleInterop": true,
"outDir": "dist",
"strict": true
},
"include": ["src"]
}
Add a tsdown.config.ts alongside tsconfig.json so production builds bundle correctly:
import { defineConfig } from "tsdown";
export default defineConfig({
entry: ["./src/index.ts"],
sourcemap: true,
outDir: "dist",
});
Install Dependencies
Install VoltAgent packages and development tools:
- npm
- yarn
- pnpm
# Install development dependencies
npm install --save-dev typescript tsx tsdown @types/node @voltagent/cli
# Install dependencies
npm install @voltagent/core @voltagent/libsql @voltagent/server-hono @voltagent/logger ai @ai-sdk/openai@^2 zod@3
# Install development dependencies
yarn add --dev typescript tsx tsdown @types/node @voltagent/cli
# Install dependencies
yarn add @voltagent/core @voltagent/libsql @voltagent/server-hono @voltagent/logger ai @ai-sdk/openai@^2 zod@3
# Install development dependencies
pnpm add --save-dev typescript tsx tsdown @types/node @voltagent/cli
# Install dependencies
pnpm add @voltagent/core @voltagent/libsql @voltagent/server-hono @voltagent/logger ai @ai-sdk/openai@^2 zod@3
Create Your Agent
Create the source directory and agent file:
mkdir src
Create src/index.ts:
Configure Environment
Create a .env file and add your API key:
- OpenAI
- Anthropic
- Google Gemini
- Groq
- Mistral
OPENAI_API_KEY=your-api-key-here
ANTHROPIC_API_KEY=your-api-key-here
GOOGLE_GENERATIVE_AI_API_KEY=your-api-key-here
GROQ_API_KEY=your-api-key-here
MISTRAL_API_KEY=your-api-key-here
Add the following to your package.json:
"type": "module",
"scripts": {
"build": "tsdown",
"dev": "tsx watch --env-file=.env ./src",
"start": "node dist/index.js",
"volt": "volt"
}
Your project structure should now look like this:
my-voltagent-project/
├── node_modules/
├── src/
│ └── index.ts
├── package.json
├── tsconfig.json
├── tsdown.config.ts
├── .env
└── .voltagent/ (created automatically when you run the agent)
Run Your Agent
- npm
- yarn
- pnpm
npm run dev
yarn dev
pnpm dev
You should see the VoltAgent server startup message:
══════════════════════════════════════════════════
VOLTAGENT SERVER STARTED SUCCESSFULLY
══════════════════════════════════════════════════
✓ HTTP Server: http://localhost:3141
↪ Share it: pnpm volt tunnel 3141 (secure HTTPS tunnel for teammates)
Docs: https://voltagent.dev/docs/deployment/local-tunnel/
✓ Swagger UI: http://localhost:3141/ui
Test your agents with VoltOps Console: https://console.voltagent.dev
══════════════════════════════════════════════════
Test Your Agent
Open https://console.voltagent.dev and click Agents & Workflows in the sidebar to find your agent.
Select it, click the chat icon in the bottom right corner, and try sending a message like "Hello".
You should receive a response from your AI agent. The dev script uses tsx watch, so it will automatically restart if you make changes to your code.
Next Steps
- Tutorial - Build agents with tools, memory, and integrations
- Agent Configuration - Agent options and settings
- Memory - Conversation history and persistence
- Tools - Create custom tools for your agent