Skip to content

Commit 0a0161a

Browse files
committed
chore: refactor tool definitions and update documentation for VoltAgent 3.x
1 parent 3cc7d86 commit 0a0161a

56 files changed

Lines changed: 1619 additions & 472 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/voltagent-3-next.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pnpm add zod@^4
107107

108108
### Agent usage
109109

110-
The object-style call shape is the preferred API. AI SDK generation options stay at the top level, while VoltAgent runtime concerns live under `voltagent`.
110+
The object-style call shape is the preferred API. VoltAgent 3 derives agent generation options from AI SDK v7 `generateText` and `streamText`, so AI SDK settings stay at the top level while VoltAgent runtime concerns live under `voltagent`.
111111

112112
```ts
113113
const result = await agent.generateText({
@@ -126,6 +126,33 @@ const result = await agent.generateText({
126126
});
127127
```
128128

129+
AI SDK v7 options such as `timeout`, `headers`, `include`, `activeTools`, `toolOrder`, `experimental_download`, `onChunk`, and stream lifecycle callbacks can be used directly on VoltAgent calls:
130+
131+
```ts
132+
const result = await agent.streamText({
133+
prompt: "Write a release note for this changelog",
134+
timeout: {
135+
totalMs: 30_000,
136+
chunkMs: 5_000,
137+
},
138+
include: {
139+
rawChunks: true,
140+
},
141+
onChunk: async ({ chunk }) => {
142+
console.log(chunk.type);
143+
},
144+
voltagent: {
145+
context: {
146+
requestId: "req-789",
147+
},
148+
},
149+
});
150+
```
151+
152+
VoltAgent composes the fields it must own for framework behavior: `model`, `prompt`/`messages`, `tools`, `abortSignal`, `maxRetries`, `onStepEnd`, `onEnd`/`onFinish`, and `onError`. User callbacks are still accepted at the top level and are invoked after VoltAgent memory, guardrails, hooks, tracing, and recovery handling.
153+
154+
Top-level AI SDK `runtimeContext`, `toolsContext`, `telemetry`, and `experimental_telemetry` are intentionally not exposed. Use `voltagent.context` for per-call application context, VoltAgent tool context/hooks for tool execution context, and VoltAgent observability/OpenTelemetry configuration for telemetry.
155+
129156
The same shape works for streaming:
130157

131158
```ts
@@ -151,7 +178,7 @@ for await (const part of result.stream) {
151178

152179
### Tool usage
153180

154-
VoltAgent now accepts AI SDK-style tool sets directly, so projects can use `tool()` without wrapping every tool in `createTool`.
181+
VoltAgent now accepts AI SDK-style tool sets directly. The recommended custom tool API is `tool()` from `@voltagent/core`, extended with VoltAgent-specific metadata under the `voltagent` namespace.
155182

156183
```ts
157184
import { Agent, tool } from "@voltagent/core";
@@ -188,13 +215,29 @@ const refundCustomer = tool({
188215
return issueRefund(orderId, reason);
189216
},
190217
voltagent: {
191-
name: "refundCustomer",
218+
name: "Refund Customer",
192219
purpose: "Issue customer refunds",
193220
},
194221
});
195222
```
196223

197-
`createTool` remains available for existing tools and for codebases that prefer the VoltAgent-native helper.
224+
Register the tool under the canonical name the model should call:
225+
226+
```ts
227+
const agent = new Agent({
228+
name: "Support Agent",
229+
model,
230+
tools: {
231+
refundCustomer,
232+
},
233+
});
234+
```
235+
236+
The ToolSet key remains the canonical `tool.name` used for tool calls, approval, routing, and telemetry correlation. `voltagent.name` is display metadata and is emitted as `tool.display_name` for Console and observability consumers.
237+
238+
VoltAgent `tool()` intentionally does not expose AI SDK `contextSchema`, `runtimeContext`, `toolsContext`, `telemetry`, or `experimental_telemetry`. Use `voltagent.context` on the agent call for per-request application context, `voltagent` tool hooks for VoltAgent lifecycle context, and VoltAgent observability/OpenTelemetry configuration for telemetry.
239+
240+
`createTool` is now a legacy compatibility helper for existing class-style tools. New code should use `tool()`.
198241

199242
### Tool approval
200243

docs/ai-sdk-first-vnext-plan.md

Lines changed: 260 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,263 @@ Exit criteria:
838838
- Users can follow the migration guide from VoltAgent 2.x/AI SDK 6 to vNext/AI SDK 7.
839839
- Website build succeeds.
840840

841+
#### 9.6.1 Follow-up Audit: Remaining v2 Usage in Examples and website/docs
842+
843+
Audit scope:
844+
845+
- `examples`
846+
- `website/docs`
847+
- Exclude historical `CHANGELOG.md` files unless they are copied into live docs.
848+
849+
Current finding: the first migration pass updated the core API docs and migration guide, but many live examples and topic docs still show v2-era usage. These should be cleaned before promoting the 3.x next release beyond early validation.
850+
851+
1. Replace preferred tool examples from `createTool` to AI SDK-style `tool()`.
852+
853+
Update live docs and examples so new code imports `tool` from `@voltagent/core`, uses `inputSchema`, and registers tools as a `ToolSet` object:
854+
855+
```ts
856+
import { Agent, tool } from "@voltagent/core";
857+
import { z } from "zod";
858+
859+
const tools = {
860+
getWeather: tool({
861+
description: "Get the weather for a city",
862+
inputSchema: z.object({
863+
city: z.string(),
864+
}),
865+
execute: async ({ city }) => ({ city, temperature: 72 }),
866+
voltagent: {
867+
tags: ["weather"],
868+
},
869+
}),
870+
};
871+
872+
const agent = new Agent({
873+
name: "assistant",
874+
model: "openai/gpt-4o-mini",
875+
tools,
876+
});
877+
```
878+
879+
Keep `createTool` only in migration/deprecation sections that explicitly explain legacy compatibility.
880+
881+
Priority docs:
882+
- `website/docs/agents/overview.md`
883+
- `website/docs/agents/tools.md`
884+
- `website/docs/tools/overview.md`
885+
- `website/docs/tools/tool-routing.md`
886+
- `website/docs/agents/context.md`
887+
- `website/docs/agents/hooks.md`
888+
- `website/docs/agents/cancellation.md`
889+
- `website/docs/agents/dynamic-agents.md`
890+
- `website/docs/agents/plan-agent.md`
891+
- `website/docs/agents/mcp/mcp-server.md`
892+
- `website/docs/integrations/nextjs.md`
893+
- `website/docs/ui/assistant-ui.md`
894+
- `website/docs/ui/copilotkit.md`
895+
- `website/docs/workspaces/overview.md`
896+
- `website/docs/workflows/steps/and-agent.md`
897+
- `website/docs/workflows/steps/and-then.md`
898+
- `website/docs/observability/logging.md`
899+
900+
Priority examples:
901+
- `examples/with-tools`
902+
- `examples/with-tool-routing`
903+
- `examples/with-client-side-tools`
904+
- `examples/next-js-chatbot-starter-template`
905+
- `examples/with-nextjs`
906+
- `examples/with-nextjs-resumable-stream`
907+
- `examples/with-assistant-ui`
908+
- `examples/with-copilotkit`
909+
- `examples/with-mcp-server`
910+
- `examples/with-mcp-elicitation`
911+
- `examples/with-a2a-server`
912+
- `examples/with-playwright`
913+
- `examples/with-whatsapp`
914+
- `examples/with-ad-creator`
915+
- `examples/github-repo-analyzer`
916+
- `examples/github-star-stories`
917+
- `examples/with-voltagent-exporter`
918+
- `examples/with-langfuse`
919+
- `examples/with-voltagent-actions`
920+
921+
2. Update old tool field names in docs and examples.
922+
923+
Replace v2-style tool fields in preferred examples:
924+
- `parameters` -> `inputSchema`
925+
- `name` inside the tool definition -> object key in the `tools` object
926+
- VoltAgent-only tool metadata -> `voltagent`
927+
- tool execution context access from `execute` -> AI SDK execution options or `voltagent.hooks`
928+
929+
Do not rewrite workflow step schemas that intentionally use `inputSchema`; those are not tool API leftovers.
930+
931+
Code/API follow-up found during audit:
932+
- `ToolRoutingConfig.pool` and `ToolRoutingConfig.expose` currently accept arrays of class-style tools/toolkits/provider tools, but not named AI SDK `ToolSet` records. Do not convert tool-routing docs to `tool()` + object syntax until the type/runtime support exists.
933+
- `createToolkit` can type-accept AI SDK tool objects, but array registration cannot infer names from a `ToolSet` key. Keep toolkit docs marked as compatibility-only until toolkit APIs support named AI SDK tools directly.
934+
935+
3. Update agent docs for AI SDK compatibility boundaries.
936+
937+
Add or expand a short section in agent docs explaining:
938+
- AI SDK generation settings mostly pass through.
939+
- VoltAgent owns `runtimeContext`, `toolsContext`, `telemetry`, `experimental_telemetry`, `maxRetries`, `abortSignal`, lifecycle callback composition, model resolution, messages, tools, and structured output wiring.
940+
- Use VoltAgent `context`, `memory`, `voltagent` runtime options, hooks, and OpenTelemetry instead of AI SDK `runtimeContext`, `toolsContext`, or `telemetry`.
941+
942+
Priority docs:
943+
- `website/docs/agents/overview.md`
944+
- `website/docs/agents/context.md`
945+
- `website/docs/agents/hooks.md`
946+
- `website/docs/getting-started/migration-guide.md`
947+
- `website/docs/agents/tools.md` should link back to the agent-level ownership section.
948+
949+
4. Normalize memory examples to the 3.x preferred envelope.
950+
951+
Preferred new-code shape:
952+
953+
```ts
954+
await agent.generateText("Continue the conversation", {
955+
memory: {
956+
userId: "user-123",
957+
conversationId: "thread-456",
958+
options: {
959+
contextLimit: 10,
960+
},
961+
},
962+
});
963+
```
964+
965+
Update user-facing examples that still show top-level `userId`, `conversationId`, `contextLimit`, `semanticMemory`, `conversationPersistence`, or `messageMetadataPersistence`. Keep top-level fields only in migration sections, compatibility notes, REST API schema examples, or UI request payload examples where the HTTP contract still uses those names.
966+
967+
Priority docs:
968+
- `website/docs/agents/overview.md`
969+
- `website/docs/agents/context.md`
970+
- `website/docs/agents/memory.md`
971+
- `website/docs/agents/memory/overview.md`
972+
- `website/docs/agents/memory/in-memory.md`
973+
- `website/docs/agents/memory/working-memory.md`
974+
- `website/docs/agents/memory/semantic-search.md`
975+
- `website/docs/agents/message-types.md`
976+
- `website/docs/agents/resumable-streaming.md`
977+
- `website/docs/rag/custom-retrievers.md`
978+
979+
Priority examples:
980+
- `examples/with-mcp-elicitation/src/index.ts`
981+
- `examples/with-nextjs-resumable-stream`
982+
- `examples/with-assistant-ui/app/api/chat/route.ts`
983+
- `examples/with-whatsapp`
984+
- `examples/with-vector-search/src/index.ts`
985+
- `examples/with-workflow/src/index.ts`
986+
- `examples/with-workflow-chain/src/index.ts`
987+
988+
5. Update structured-output language and examples for VoltAgent 3.x.
989+
990+
Replace live docs that say "`generateObject` and `streamObject` are deprecated in VoltAgent 2.x" with 3.x wording:
991+
- `generateObject` and `streamObject` remain deprecated compatibility wrappers in 3.x.
992+
- New code should use `generateText` or `streamText` with `output: Output.object(...)`.
993+
994+
Priority files:
995+
- `website/docs/agents/overview.md`
996+
- `website/docs/agents/structured-output.md`
997+
- `website/docs/agents/multi-modal.md`
998+
- `website/docs/agents/hooks.md`
999+
- `website/docs/agents/middleware.md`
1000+
- `website/docs/agents/subagents.md`
1001+
- `website/docs/agents/providers.md`
1002+
- `examples/with-live-evals/src/index.ts`
1003+
- `examples/with-offline-evals/src/experiments/scorers.ts`
1004+
1005+
Do not change direct AI SDK `generateObject` calls used for dataset generation unless they are intended to demonstrate VoltAgent agent APIs.
1006+
1007+
6. Update Node.js, ESM, and package version references.
1008+
1009+
Replace Node.js 18/20 requirements in live examples and docs with Node.js 22+ for VoltAgent 3.x.
1010+
1011+
Priority files found by audit:
1012+
- `website/docs/getting-started/quick-start.md`
1013+
- `website/docs/rag/pinecone.md`
1014+
- `website/docs/rag/qdrant.md`
1015+
- `website/docs/rag/chroma.md`
1016+
- `website/docs/rag/lancedb.md`
1017+
- `examples/with-zapier-mcp/README.md`
1018+
- `examples/with-mcp-server/README.md`
1019+
- `examples/with-amazon-bedrock/README.md`
1020+
- `examples/with-recipe-generator/README.md`
1021+
- `examples/with-planagents/README.md`
1022+
- `examples/with-anthropic/README.md`
1023+
- `examples/with-a2a-server/README.md`
1024+
- `examples/with-cerbos/README.md`
1025+
- `examples/with-chat-sdk/README.md`
1026+
- `examples/with-research-assistant/README.md`
1027+
- `examples/with-hugging-face-mcp/README.md`
1028+
- `examples/with-cloudflare-workers/README.md`
1029+
- `examples/with-voltagent-managed-memory/README.md`
1030+
- `examples/with-lancedb/README.md`
1031+
- `examples/with-nestjs/README.md`
1032+
- `examples/with-ad-creator/README.md`
1033+
- `examples/with-summarization/README.md`
1034+
- `examples/with-composio-mcp/README.md`
1035+
- `examples/with-netlify-functions/README.md`
1036+
- `examples/with-openrouter/README.md`
1037+
- `examples/with-mcp-elicitation/README.md`
1038+
1039+
Package/version cleanup found by audit:
1040+
- `examples/with-client-side-tools/package.json` uses legacy `@voltagent/vercel-ai` and `@voltagent/vercel-ui`. These can be removed immediately because the example does not import them.
1041+
- `examples/with-a2a-server/package.json` uses `@voltagent/internal@^2.0.0-next.0`.
1042+
- `examples/with-airtable/package.json` uses `@voltagent/internal@^2.0.0-next.0`.
1043+
- `examples/with-nextjs-resumable-stream/package.json` uses `@voltagent/internal@^2.0.0-next.0`.
1044+
- `examples/with-copilotkit/server/package.json` uses `@voltagent/ag-ui@^2.0.0-next.0`.
1045+
- `examples/with-voltagent-managed-memory/package.json` uses `@voltagent/voltagent-memory@^2.0.0-next.0`.
1046+
- Keep workspace package ranges that still point at local `2.0.0-next.0` packages until the changeset version step bumps those packages. Moving them to `^3.0.0-next.0` before versioning breaks local `pnpm install` because the workspace package versions do not satisfy the range yet.
1047+
- `examples/with-playwright/tsconfig.json` still sets `"module": "CommonJS"`.
1048+
1049+
7. Review legacy provider documentation.
1050+
1051+
`website/docs/getting-started/providers-models.md` still contains an older native-provider migration section. Keep it only as a clearly labeled historical migration note and make the current 3.x recommendation direct AI SDK providers/model strings.
1052+
1053+
`website/docs/community/contributing.md` mentions deprecated provider packages; verify the wording still matches the 3.x package policy.
1054+
1055+
8. Telemetry docs cleanup.
1056+
1057+
Ensure live docs do not imply AI SDK `telemetry` can be passed through `Agent` or `tool()`. The correct 3.x guidance is:
1058+
- Use VoltAgent OpenTelemetry/observability for Agent calls and VoltAgent-managed tools.
1059+
- Use AI SDK telemetry only when calling AI SDK directly outside VoltAgent.
1060+
- Provider-defined tools are passed through and may have provider-owned observability semantics.
1061+
1062+
Priority docs:
1063+
- `website/docs/observability/overview.md`
1064+
- `website/docs/observability/logging.md`
1065+
- `website/docs/integrations/vercel-ai.md`
1066+
- `website/docs/agents/overview.md`
1067+
- `website/docs/agents/tools.md`
1068+
1069+
Validation search gates after cleanup:
1070+
1071+
```bash
1072+
rg -n "createTool" examples website/docs --glob '!**/CHANGELOG.md'
1073+
rg -n "parameters:\\s*z\\." examples website/docs --glob '!**/CHANGELOG.md'
1074+
rg -n "deprecated in VoltAgent 2\\.x|AI SDK v6|vNext|vnext" website/docs examples --glob '!**/CHANGELOG.md'
1075+
rg -n "Node\\.js 18|Node\\.js 20|Node 18|Node 20|v18 or|v20 or" website/docs examples --glob '!**/CHANGELOG.md'
1076+
rg -n "@voltagent/(internal|ag-ui|voltagent-memory|vercel-ai|vercel-ui).*\\\"[~^]?[12]\\." examples/**/package.json
1077+
rg -n "\"module\": \"CommonJS\"" examples/**/tsconfig.json
1078+
```
1079+
1080+
Expected exceptions:
1081+
1082+
- `website/docs/getting-started/migration-guide.md` may intentionally contain legacy before/after snippets.
1083+
- Historical changelogs should not be rewritten.
1084+
- Direct AI SDK examples can still use AI SDK-native APIs when they are not demonstrating VoltAgent agent wrappers.
1085+
- REST API schema examples may still expose `userId` and `conversationId` if those are part of the HTTP contract.
1086+
1087+
Exit criteria:
1088+
1089+
- Preferred docs use `tool()` plus `inputSchema`.
1090+
- New examples do not recommend `createTool`.
1091+
- Agent docs clearly explain VoltAgent-owned AI SDK fields and telemetry ownership.
1092+
- New-code memory examples use the `memory` envelope.
1093+
- Structured-output docs say 3.x compatibility wrappers, not 2.x deprecation.
1094+
- Live prerequisites say Node.js 22+ for VoltAgent 3.x.
1095+
- Example package manifests do not depend on old VoltAgent 1.x/2.x companion packages.
1096+
- Website build succeeds after the cleanup.
1097+
8411098
#### 9.7 Validation Gates for AI SDK 7
8421099

8431100
Run these after the v7 migration work, even though Phase 8 was already green before this new scope:
@@ -877,7 +1134,9 @@ Progress:
8771134
- [x] Added AI SDK-style `tool()` support with a VoltAgent metadata namespace and direct `ToolSet` support.
8781135
- [x] Added native AI SDK `toolApproval` pass-through and tool routing policy enforcement.
8791136
- [x] Server/protocol/ecosystem packages updated.
880-
- [x] Docs, examples, and templates updated for AI SDK 7, Node.js 22, and ESM-only.
1137+
- [x] Initial migration guide, core docs, and templates updated for AI SDK 7, Node.js 22, and ESM-only.
1138+
- [x] Follow-up audit cleanup started: core agent/tool docs, selected safe ToolSet examples, Node.js 22 README/docs references, and legacy `@voltagent/vercel-*` example dependencies.
1139+
- [ ] Follow-up audit cleanup for remaining v2-era examples and website docs is complete.
8811140
- [x] `pnpm --filter @voltagent/core typecheck` passes.
8821141
- [x] `pnpm --filter @voltagent/core test` passes.
8831142
- [x] `pnpm --filter @voltagent/e2e exec vitest run --config vitest.config.mts src/agent-runtime.e2e.spec.ts` passes.

examples/next-js-chatbot-starter-template/lib/tools/calculator.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { createTool } from "@voltagent/core";
1+
import { tool } from "@voltagent/core";
22
import { z } from "zod";
33

44
/**
55
* Calculator Tool
66
* Performs basic arithmetic calculations
77
*/
8-
export const calculatorTool = createTool({
9-
name: "calculator",
8+
export const calculatorTool = tool({
109
description:
1110
"Perform basic arithmetic calculations (addition, subtraction, multiplication, division, exponents, etc.)",
12-
parameters: z.object({
11+
inputSchema: z.object({
1312
expression: z
1413
.string()
1514
.describe("Mathematical expression to evaluate (e.g., '2 + 2', '10 * 5', '2 ** 8')"),

examples/next-js-chatbot-starter-template/lib/tools/datetime.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { createTool } from "@voltagent/core";
1+
import { tool } from "@voltagent/core";
22
import { z } from "zod";
33

44
/**
55
* Date Time Tool
66
* Gets current date and time information
77
*/
8-
export const dateTimeTool = createTool({
9-
name: "getDateTime",
8+
export const dateTimeTool = tool({
109
description: "Get the current date, time, and timezone information",
11-
parameters: z.object({
10+
inputSchema: z.object({
1211
timezone: z
1312
.string()
1413
.optional()

0 commit comments

Comments
 (0)