create-voltagent

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create VoltAgent Skill

创建VoltAgent Skill

Complete guide for creating new VoltAgent projects. Includes the CLI flow and a full manual setup.
Official documentation: https://voltagent.dev/docs/

创建全新VoltAgent项目的完整指南,包含CLI流程与完整手动设置步骤。

Start Here

开始

When a user wants to create a VoltAgent project, ask:
"How would you like to create your VoltAgent project?"
  1. Automatic Setup - run
    npm create voltagent-app@latest
    and handle prompts
  2. Interactive Guide - walk through each step and confirm choices
  3. Manual Installation - set up dependencies and a full working example
Based on their choice:
  • Option 1: run the CLI, capture server and provider choices, and finish setup
  • Option 2: gather server, provider, and API key, then run the CLI
  • Option 3: follow the manual steps below

当用户想要创建VoltAgent项目时,询问:
"你希望通过哪种方式创建VoltAgent项目?"
  1. 自动设置 - 运行
    npm create voltagent-app@latest
    并处理提示
  2. 交互式引导 - 逐步引导并确认各项选择
  3. 手动安装 - 配置依赖并搭建完整可用示例
根据用户选择执行:
  • 选项1:运行CLI,获取服务器与服务商选择,完成设置
  • 选项2:收集服务器、服务商及API密钥信息,再运行CLI
  • 选项3:遵循下方手动步骤操作

Before You Start

准备工作

  • Node.js 20+ (>= 20.19.0 recommended)
  • Git (optional, for auto git init)
  • An API key for your model provider (not needed for Ollama)

  • Node.js 20+(推荐版本 ≥ 20.19.0)
  • Git(可选,用于自动初始化git仓库)
  • 模型服务商的API密钥(使用Ollama时无需提供)

Fast Path

快速路径

Create a new VoltAgent project with one command:
bash
npm create voltagent-app@latest
Other package managers:
bash
pnpm create voltagent-app@latest
yarn create voltagent-app@latest
bun create voltagent-app@latest

通过一条命令创建新的VoltAgent项目:
bash
npm create voltagent-app@latest
其他包管理器命令:
bash
pnpm create voltagent-app@latest
yarn create voltagent-app@latest
bun create voltagent-app@latest

CLI Flow

CLI流程

The create-voltagent-app command:
  1. Asks for a project name (default:
    my-voltagent-app
    )
  2. Prompts for a server framework (Hono or Elysia)
  3. Prompts for an AI provider (OpenAI, Anthropic, Google, Groq, Mistral, Ollama)
  4. Prompts for an API key when required
  5. Installs dependencies and scaffolds the project
  6. Writes
    .env
    ,
    README.md
    ,
    tsconfig.json
    ,
    tsdown.config.ts
    , and Docker files
  7. Initializes a git repo when available

create-voltagent-app命令执行步骤:
  1. 询问项目名称(默认值:
    my-voltagent-app
  2. 提示选择服务器框架(Hono或Elysia)
  3. 提示选择AI服务商(OpenAI、Anthropic、Google、Groq、Mistral、Ollama)
  4. 必要时提示输入API密钥
  5. 安装依赖并生成项目骨架
  6. 写入
    .env
    README.md
    tsconfig.json
    tsdown.config.ts
    及Docker相关文件
  7. 若Git可用则初始化git仓库

CLI Walkthrough

CLI操作指引

  1. Run:
    bash
    npm create voltagent-app@latest
  2. When prompted:
    • Choose a server (Hono recommended or Elysia)
    • Choose an AI provider
    • Enter your API key (skip if using Ollama)
  3. Start the dev server:
    bash
    cd <your-project-directory>
    npm run dev
  4. If you chose Ollama:
    bash
    ollama pull llama3.2

  1. 运行命令:
    bash
    npm create voltagent-app@latest
  2. 出现提示时:
    • 选择服务器框架(推荐Hono或Elysia)
    • 选择AI服务商
    • 输入API密钥(使用Ollama可跳过)
  3. 启动开发服务器:
    bash
    cd <你的项目目录>
    npm run dev
  4. 若选择Ollama,需执行:
    bash
    ollama pull llama3.2

CLI Flags and Examples

CLI参数与示例

Create in a specific directory:
bash
npm create voltagent-app@latest my-voltagent-app
Download an example from the VoltAgent repo:
bash
npm create voltagent-app@latest -- --example with-workflow
pnpm / yarn / bun equivalents:
bash
pnpm create voltagent-app@latest -- --example with-workflow
yarn create voltagent-app@latest -- --example with-workflow
bun create voltagent-app@latest -- --example with-workflow
Notes:

在指定目录创建项目:
bash
npm create voltagent-app@latest my-voltagent-app
从VoltAgent仓库下载示例项目:
bash
npm create voltagent-app@latest -- --example with-workflow
pnpm / yarn / bun对应命令:
bash
pnpm create voltagent-app@latest -- --example with-workflow
yarn create voltagent-app@latest -- --example with-workflow
bun create voltagent-app@latest -- --example with-workflow
注意事项:

Generated Layout

生成的项目结构

my-voltagent-app/
|-- src/
|   |-- index.ts
|   |-- tools/
|   |   |-- index.ts
|   |   `-- weather.ts
|   `-- workflows/
|       `-- index.ts
|-- .env
|-- .voltagent/
|-- Dockerfile
|-- .dockerignore
|-- .gitignore
|-- README.md
|-- package.json
|-- tsconfig.json
`-- tsdown.config.ts
If you run the docs sync script in this repo, you may also see
packages/core/docs
generated.

my-voltagent-app/
|-- src/
|   |-- index.ts
|   |-- tools/
|   |   |-- index.ts
|   |   `-- weather.ts
|   `-- workflows/
|       `-- index.ts
|-- .env
|-- .voltagent/
|-- Dockerfile
|-- .dockerignore
|-- .gitignore
|-- README.md
|-- package.json
|-- tsconfig.json
`-- tsdown.config.ts
若运行仓库中的文档同步脚本,还会生成
packages/core/docs
目录。

Env Keys

环境变量密钥

The CLI writes
.env
with your provider key (or a placeholder). Common keys:
env
OPENAI_API_KEY=...
ANTHROPIC_API_KEY=...
GOOGLE_GENERATIVE_AI_API_KEY=...
GROQ_API_KEY=...
MISTRAL_API_KEY=...
OLLAMA_HOST=http://localhost:11434

VOLTAGENT_PUBLIC_KEY=...
VOLTAGENT_SECRET_KEY=...

CLI会在
.env
文件中写入服务商密钥(或占位符)。常见密钥如下:
env
OPENAI_API_KEY=...
ANTHROPIC_API_KEY=...
GOOGLE_GENERATIVE_AI_API_KEY=...
GROQ_API_KEY=...
MISTRAL_API_KEY=...
OLLAMA_HOST=http://localhost:11434

VOLTAGENT_PUBLIC_KEY=...
VOLTAGENT_SECRET_KEY=...

Manual Setup (Full)

完整手动设置

If you prefer not to use the CLI, follow these steps:
若不想使用CLI,可遵循以下步骤:

Step 1: Create the project directory

步骤1:创建项目目录

bash
mkdir my-voltagent-app && cd my-voltagent-app
npm init -y
mkdir -p src/tools src/workflows .voltagent
bash
mkdir my-voltagent-app && cd my-voltagent-app
npm init -y
mkdir -p src/tools src/workflows .voltagent

Step 2: Install dependencies

步骤2:安装依赖

Choose one server package:
bash
npm install @voltagent/core @voltagent/libsql @voltagent/logger @voltagent/server-hono @voltagent/cli ai zod dotenv
or
bash
npm install @voltagent/core @voltagent/libsql @voltagent/logger @voltagent/server-elysia @voltagent/cli ai zod dotenv
Dev dependencies:
bash
npm install -D typescript tsx tsdown @types/node @biomejs/biome
选择一款服务器包:
bash
npm install @voltagent/core @voltagent/libsql @voltagent/logger @voltagent/server-hono @voltagent/cli ai zod dotenv
bash
npm install @voltagent/core @voltagent/libsql @voltagent/logger @voltagent/server-elysia @voltagent/cli ai zod dotenv
开发依赖:
bash
npm install -D typescript tsx tsdown @types/node @biomejs/biome

Step 3: Add scripts to package.json

步骤3:为package.json添加脚本

json
{
  "scripts": {
    "dev": "tsx watch --env-file=.env ./src",
    "build": "tsdown",
    "start": "node dist/index.js",
    "lint": "biome check ./src",
    "lint:fix": "biome check --write ./src",
    "typecheck": "tsc --noEmit",
    "volt": "volt"
  }
}
volt
is the VoltAgent CLI. Use it for project utilities (for example
init
,
deploy
,
eval
,
prompts
,
tunnel
,
update
).
json
{
  "scripts": {
    "dev": "tsx watch --env-file=.env ./src",
    "build": "tsdown",
    "start": "node dist/index.js",
    "lint": "biome check ./src",
    "lint:fix": "biome check --write ./src",
    "typecheck": "tsc --noEmit",
    "volt": "volt"
  }
}
volt
是VoltAgent的CLI工具,可用于项目实用功能(例如
init
deploy
eval
prompts
tunnel
update
)。

Step 4: Configure TypeScript

步骤4:配置TypeScript

Create
tsconfig.json
:
json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "moduleResolution": "bundler",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "outDir": "dist",
    "skipLibCheck": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "dist"]
}
创建
tsconfig.json
文件:
json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "moduleResolution": "bundler",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "outDir": "dist",
    "skipLibCheck": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "dist"]
}

Step 5: Add tsdown config

步骤5:添加tsdown配置

Create
tsdown.config.ts
:
typescript
import { defineConfig } from "tsdown";

export default defineConfig({
  entry: ["./src/index.ts"],
  sourcemap: true,
  outDir: "dist",
});
创建
tsdown.config.ts
文件:
typescript
import { defineConfig } from "tsdown";

export default defineConfig({
  entry: ["./src/index.ts"],
  sourcemap: true,
  outDir: "dist",
});

Step 6: Create .env

步骤6:创建.env文件

env
OPENAI_API_KEY=your-api-key-here
VOLTAGENT_PUBLIC_KEY=your-public-key
VOLTAGENT_SECRET_KEY=your-secret-key
NODE_ENV=development
For Ollama:
env
OLLAMA_HOST=http://localhost:11434
env
OPENAI_API_KEY=your-api-key-here
VOLTAGENT_PUBLIC_KEY=your-public-key
VOLTAGENT_SECRET_KEY=your-secret-key
NODE_ENV=development
使用Ollama时的配置:
env
OLLAMA_HOST=http://localhost:11434

Step 7: Create a tool

步骤7:创建工具

Create
src/tools/weather.ts
:
typescript
import { createTool } from "@voltagent/core";
import { z } from "zod";

export const weatherTool = createTool({
  name: "getWeather",
  description: "Get the current weather for a specific location",
  parameters: z.object({
    location: z.string().describe("City or location to get weather for"),
  }),
  execute: async ({ location }) => {
    return {
      weather: {
        location,
        temperature: 21,
        condition: "Sunny",
        humidity: 45,
        windSpeed: 8,
      },
      message: `Current weather in ${location}: 21 C and sunny.`,
    };
  },
});
Create
src/tools/index.ts
:
typescript
export { weatherTool } from "./weather";
创建
src/tools/weather.ts
文件:
typescript
import { createTool } from "@voltagent/core";
import { z } from "zod";

export const weatherTool = createTool({
  name: "getWeather",
  description: "Get the current weather for a specific location",
  parameters: z.object({
    location: z.string().describe("City or location to get weather for"),
  }),
  execute: async ({ location }) => {
    return {
      weather: {
        location,
        temperature: 21,
        condition: "Sunny",
        humidity: 45,
        windSpeed: 8,
      },
      message: `Current weather in ${location}: 21 C and sunny.`,
    };
  },
});
创建
src/tools/index.ts
文件:
typescript
export { weatherTool } from "./weather";

Step 8: Create a workflow

步骤8:创建工作流

Create
src/workflows/index.ts
:
typescript
import { createWorkflowChain } from "@voltagent/core";
import { z } from "zod";

export const expenseApprovalWorkflow = createWorkflowChain({
  id: "expense-approval",
  name: "Expense Approval Workflow",
  purpose: "Process expense reports with manager approval for high amounts",
  input: z.object({
    employeeId: z.string(),
    amount: z.number(),
    category: z.string(),
    description: z.string(),
  }),
  result: z.object({
    status: z.enum(["approved", "rejected"]),
    approvedBy: z.string(),
    finalAmount: z.number(),
  }),
})
  .andThen({
    id: "check-approval-needed",
    resumeSchema: z.object({
      approved: z.boolean(),
      managerId: z.string(),
      comments: z.string().optional(),
      adjustedAmount: z.number().optional(),
    }),
    execute: async ({ data, suspend, resumeData }) => {
      if (resumeData) {
        return {
          ...data,
          approved: resumeData.approved,
          approvedBy: resumeData.managerId,
          finalAmount: resumeData.adjustedAmount || data.amount,
          managerComments: resumeData.comments,
        };
      }

      if (data.amount > 500) {
        await suspend("Manager approval required", {
          employeeId: data.employeeId,
          requestedAmount: data.amount,
          category: data.category,
        });
      }

      return {
        ...data,
        approved: true,
        approvedBy: "system",
        finalAmount: data.amount,
      };
    },
  })
  .andThen({
    id: "process-decision",
    execute: async ({ data }) => {
      return {
        status: data.approved ? "approved" : "rejected",
        approvedBy: data.approvedBy,
        finalAmount: data.finalAmount,
      };
    },
  });
创建
src/workflows/index.ts
文件:
typescript
import { createWorkflowChain } from "@voltagent/core";
import { z } from "zod";

export const expenseApprovalWorkflow = createWorkflowChain({
  id: "expense-approval",
  name: "Expense Approval Workflow",
  purpose: "Process expense reports with manager approval for high amounts",
  input: z.object({
    employeeId: z.string(),
    amount: z.number(),
    category: z.string(),
    description: z.string(),
  }),
  result: z.object({
    status: z.enum(["approved", "rejected"]),
    approvedBy: z.string(),
    finalAmount: z.number(),
  }),
})
  .andThen({
    id: "check-approval-needed",
    resumeSchema: z.object({
      approved: z.boolean(),
      managerId: z.string(),
      comments: z.string().optional(),
      adjustedAmount: z.number().optional(),
    }),
    execute: async ({ data, suspend, resumeData }) => {
      if (resumeData) {
        return {
          ...data,
          approved: resumeData.approved,
          approvedBy: resumeData.managerId,
          finalAmount: resumeData.adjustedAmount || data.amount,
          managerComments: resumeData.comments,
        };
      }

      if (data.amount > 500) {
        await suspend("Manager approval required", {
          employeeId: data.employeeId,
          requestedAmount: data.amount,
          category: data.category,
        });
      }

      return {
        ...data,
        approved: true,
        approvedBy: "system",
        finalAmount: data.amount,
      };
    },
  })
  .andThen({
    id: "process-decision",
    execute: async ({ data }) => {
      return {
        status: data.approved ? "approved" : "rejected",
        approvedBy: data.approvedBy,
        finalAmount: data.finalAmount,
      };
    },
  });

Step 9: Create the entry point

步骤9:创建入口文件

Create
src/index.ts
:
typescript
import "dotenv/config";
import {
  Agent,
  Memory,
  VoltAgent,
  VoltAgentObservability,
  VoltOpsClient,
} from "@voltagent/core";
import { LibSQLMemoryAdapter, LibSQLObservabilityAdapter } from "@voltagent/libsql";
import { createPinoLogger } from "@voltagent/logger";
import { honoServer } from "@voltagent/server-hono";
import { expenseApprovalWorkflow } from "./workflows";
import { weatherTool } from "./tools";

const logger = createPinoLogger({ name: "my-voltagent-app", level: "info" });

const memory = new Memory({
  storage: new LibSQLMemoryAdapter({
    url: "file:./.voltagent/memory.db",
    logger: logger.child({ component: "libsql" }),
  }),
});

const observability = new VoltAgentObservability({
  storage: new LibSQLObservabilityAdapter({
    url: "file:./.voltagent/observability.db",
  }),
});

const agent = new Agent({
  name: "my-voltagent-app",
  instructions: "A helpful assistant that can check weather and help with various tasks",
  model: "openai/gpt-4o-mini",
  tools: [weatherTool],
  memory,
});

new VoltAgent({
  agents: { agent },
  workflows: { expenseApprovalWorkflow },
  server: honoServer(),
  logger,
  observability,
  voltOpsClient: new VoltOpsClient({
    publicKey: process.env.VOLTAGENT_PUBLIC_KEY || "",
    secretKey: process.env.VOLTAGENT_SECRET_KEY || "",
  }),
});
Model format is
provider/model
. Examples:
  • openai/gpt-4o-mini
  • anthropic/claude-3-5-sonnet
  • google/gemini-2.0-flash
  • groq/llama-3.3-70b-versatile
  • mistral/mistral-large-latest
  • ollama/llama3.2
If you chose Elysia, replace
honoServer
with
elysiaServer
and update the import.
创建
src/index.ts
文件:
typescript
import "dotenv/config";
import {
  Agent,
  Memory,
  VoltAgent,
  VoltAgentObservability,
  VoltOpsClient,
} from "@voltagent/core";
import { LibSQLMemoryAdapter, LibSQLObservabilityAdapter } from "@voltagent/libsql";
import { createPinoLogger } from "@voltagent/logger";
import { honoServer } from "@voltagent/server-hono";
import { expenseApprovalWorkflow } from "./workflows";
import { weatherTool } from "./tools";

const logger = createPinoLogger({ name: "my-voltagent-app", level: "info" });

const memory = new Memory({
  storage: new LibSQLMemoryAdapter({
    url: "file:./.voltagent/memory.db",
    logger: logger.child({ component: "libsql" }),
  }),
});

const observability = new VoltAgentObservability({
  storage: new LibSQLObservabilityAdapter({
    url: "file:./.voltagent/observability.db",
  }),
});

const agent = new Agent({
  name: "my-voltagent-app",
  instructions: "A helpful assistant that can check weather and help with various tasks",
  model: "openai/gpt-4o-mini",
  tools: [weatherTool],
  memory,
});

new VoltAgent({
  agents: { agent },
  workflows: { expenseApprovalWorkflow },
  server: honoServer(),
  logger,
  observability,
  voltOpsClient: new VoltOpsClient({
    publicKey: process.env.VOLTAGENT_PUBLIC_KEY || "",
    secretKey: process.env.VOLTAGENT_SECRET_KEY || "",
  }),
});
模型格式为
provider/model
,示例:
  • openai/gpt-4o-mini
  • anthropic/claude-3-5-sonnet
  • google/gemini-2.0-flash
  • groq/llama-3.3-70b-versatile
  • mistral/mistral-large-latest
  • ollama/llama3.2
若选择Elysia服务器,需将
honoServer
替换为
elysiaServer
并更新导入语句。

Step 10: Run the dev server

步骤10:启动开发服务器

bash
npm run dev
bash
npm run dev