toAiSdk() method, which exports both system prompts and tools in a single, ready-to-use configuration object.
Installation
Basic Integration
The simplest way to use PromptSmith with Vercel AI SDK is through thetoAiSdk() method, which returns a configuration object that can be spread directly into AI SDK functions.
Integration with Tools
PromptSmith automatically converts tool definitions to Vercel AI SDK format. Define tools once with full type safety, and they’re ready to use.Streaming Responses
UsestreamText for real-time streaming responses:
Advanced: Multi-Step Tool Usage
The Vercel AI SDK supports multi-step tool execution. Here’s an example with multiple tools that work together:Next.js Integration
Use PromptSmith in Next.js API routes for production applications:app/api/chat/route.ts
Type Safety
PromptSmith provides full type inference for tool parameters:What’s Exported
ThetoAiSdk() method returns an object with two properties:
Alternative: Export Separately
You can also export the system prompt and tools separately:Best Practices
Use type-safe tool definitions
Use type-safe tool definitions
Always use Zod schemas with
.describe() for full type safety and automatic documentation:Enable security guardrails
Enable security guardrails
Always enable guardrails for production agents:
Add usage examples
Add usage examples
Provide examples to guide the model’s behavior:
Test before deploying
Test before deploying
Use the built-in testing framework:
Next Steps
Mastra Integration
Learn how to use PromptSmith with Mastra
Other Frameworks
Integrate with other AI frameworks