import { PromptSmith } from 'promptsmith';// Use TOON format for token optimizationconst prompt = new PromptSmith() .withIdentity("Research Assistant") .withFormat('toon');// Use standard markdown (default)const prompt2 = new PromptSmith() .withIdentity("Research Assistant") .withFormat('markdown');// Use compact markdownconst prompt3 = new PromptSmith() .withIdentity("Research Assistant") .withFormat('compact');
Configuration object returned by .toAiSdk() for Vercel AI SDK integration. This interface defines the structure of the object that includes both the system prompt and tools formatted for use with Vercel’s AI SDK.The object can be spread directly into generateText, streamText, or other AI SDK function calls for seamless integration.
The system prompt string generated by the builder. This is the same string returned by .build(), containing the complete markdown-formatted system prompt with identity, capabilities, tools documentation, constraints, and formatting guidelines.
Optional execution function. Tools without an execute function will have this set to undefined, allowing for documentation-only tools or client-side tool handling.
import { generateText } from 'ai';import { openai } from '@ai-sdk/openai';import { PromptSmith } from 'promptsmith';import { z } from 'zod';// Create prompt with toolsconst builder = new PromptSmith() .withIdentity("Weather Assistant") .withTool({ name: "get_weather", description: "Get current weather for a location", schema: z.object({ location: z.string().describe("City name") }), execute: async ({ location }) => { const response = await fetch(`https://api.weather.com/${location}`); return response.json(); } });// Get AI SDK configconst config = builder.toAiSdk();// Use with Vercel AI SDKconst response = await generateText({ model: openai('gpt-4'), ...config, // Spreads system and tools prompt: "What's the weather in Paris?"});
const builder = new PromptSmith() .withTool({ name: "search_database", description: "Search the product database", schema: z.object({ query: z.string() }) // No execute function });const config = builder.toAiSdk();// Tool will be in config.tools but execute will be undefinedconsole.log(config.tools['search_database'].execute); // undefined
This is useful when:
You want to document available tools in the prompt
Tool execution happens client-side or through a different mechanism