text stringlengths 0 59.1k |
|---|
#### Key Additions |
- **Typed chat messages** β `UIMessage` vs. `ModelMessage`. Convert UI messages to model messages before streaming for persistence and type safety. |
- **Agentic Loop Control** β fine-tune or stop multi-step tool calls using `stopWhen` and `prepareStep`. Includes a lightweight `Agent` class that wraps `generateText` and `streamText`. |
- **SSE-based Streaming** β Server-Sent Events replace WebSockets for stable real-time responses and partial data streaming. |
- **Dynamic Tooling** β define tools dynamically with `inputSchema` and `outputSchema` instead of `parameters` and `result`. Runtime-defined tools and improved schema validation. |
- **Speech & Audio APIs** β experimental text-to-speech and transcription support for OpenAI, ElevenLabs, Deepgram. |
- **Global Provider System** β models can be referenced simply as `"openai/gpt-4o"`; provider setup is handled automatically. |
- **Zod 4 + MCP V2 Support** β upgraded schema and protocol for reasoning, sources, and image generation. |
<ZoomableMermaid chart={`graph LR |
VAISDK[Vercel AI SDK v5] --> MODELS[Model Providers] |
VAISDK --> FEATURES[Features] |
VAISDK --> UI[UI Hooks] |
MODELS --> OPENAI[OpenAI] |
MODELS --> ANTHROPIC[Anthropic] |
MODELS --> GOOGLE[Google Gemini] |
MODELS --> HF[Hugging Face] |
FEATURES --> STREAM[Streaming] |
FEATURES --> TOOLS[Dynamic Tools] |
FEATURES --> SPEECH[Speech APIs] |
FEATURES --> AGENTIC[Agentic Loop Control] |
FEATURES --> GLOBAL[Global Provider] |
FEATURES --> SCHEMA[Zod 4 Schema] |
UI --> USECHAT[useChat] |
UI --> USECOMPLETION[useCompletion] |
style VAISDK fill:#121E1B,stroke:#50C878,stroke-width:2px,color:#50C878 |
style MODELS fill:#0F1A15,stroke:#50C878,stroke-width:2px,color:#50C878 |
style FEATURES fill:#0F1A15,stroke:#50C878,stroke-width:2px,color:#50C878 |
style UI fill:#0F1A15,stroke:#50C878,stroke-width:2px,color:#50C878`} /> |
#### Core SDK Functions |
**Model Provider Support** |
The SDK supports multiple model providers (OpenAI, Anthropic, Google Gemini, Hugging Face) through a single API. This eliminates provider-specific integration code for each model. |
**Streaming** |
The SDK supports streaming responses for both text and structured data (JSON). For Next.js applications, React hooks like `useChat` and `useCompletion` handle common UI patterns. |
**Additional Components:** |
- **`generateText` / `streamText`**: Functions for text generation with streaming support. |
- **`generateObject` / `streamObject`**: Generate structured data (JSON) with schema validation using Zod. Model output conforms to the defined schema structure. Model support for structured output varies by provider. |
- **Function Calling**: Models can invoke predefined functions or tools. An agent can fetch data from an API or execute actions during conversation. |
- **Multi-modal Support**: Process inputs beyond text, such as images. The SDK passes multi-modal messages to models that support this capability. |
- **Provider-Specific Options**: Pass provider-specific parameters directly to underlying SDK functions through the `provider` object for model-specific features. |
:::important Performance Note |
When using `streamObject()` with large response structures, implement progressive UI rendering to maintain responsiveness. Schema validation can introduce delays with complex nested structures. |
::: |
--- |
### Example Code (AI SDK 5) |
```typescript |
import { generateText } from "ai"; |
import { openai } from "@ai-sdk/openai"; |
const result = await generateText({ |
model: openai("gpt-4o"), |
prompt: "Explain what an agentic loop is in one sentence.", |
}); |
console.log(result.text); |
``` |
This structure now supports typed responses, streamed outputs, and custom data chunks. |
:::note API Key Management |
The SDK looks for environment variables like `OPENAI_API_KEY` or `ANTHROPIC_API_KEY`. Set these in your development environment or deployment configuration. |
::: |
--- |
## VoltAgent: Building Autonomous AI Agents |
VoltAgent is a TypeScript framework for creating autonomous AI agents. While Vercel AI SDK focuses on model communication, VoltAgent provides the agent architecture tools, memory, reasoning, and coordination. |
Refer to [Vercel AI SDK docs](https://voltagent.dev/docs/integrations/vercel-ai/) on Voltagent. |
### Core VoltAgent Concepts |
- **Instructions** β define behavior and purpose |
- **Tools** β external actions or APIs |
- **Memory** β state and context |
- **Sub-agents** β task delegation |
- **Providers** β model connection layer |
--- |
### Integration with Vercel AI SDK |
VoltAgent integrates with AI SDK 5 through the `@voltagent/vercel-ai` provider. This allows agents to use Vercel's model APIs (`generateText`, `streamText`, `generateObject`) directly. |
```typescript |
import { Agent } from "@voltagent/core"; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.