PromptSmith offers multiple strategies to optimize token usage and reduce AI API costs, including TOON format - a token-optimized alternative to markdown that can reduce prompt size by 30-60%.
# IdentityYou are a customer service assistant# Capabilities1. Process returns and exchanges2. Track order status3. Answer product questions# Available Tools## track_orderLook up order status by order number**Parameters:**- `order_number` (string, required): Order number to track
const devBuilder = createPromptBuilder() .withFormat('markdown') // Default, most readable .withIdentity('You are a helpful assistant');// Easy to read, review, and debug
const stagingBuilder = createPromptBuilder() .withFormat('compact') .withIdentity('You are a helpful assistant');// 10-20% token reduction, still readable
// ❌ Too many examples.withExamples([ { user: 'Hi', assistant: 'Hello!' }, { user: 'Hey', assistant: 'Hi there!' }, { user: 'Hello', assistant: 'Hello! How can I help?' }, // 10 more greeting examples...])// ✅ One comprehensive example.withExamples([ { user: 'Hello', assistant: 'Hi! How can I help you today?', explanation: 'Greet users warmly and offer assistance' }])
// ❌ Verbose.withTool({ name: 'search', description: 'This tool allows you to search through our entire product catalog by providing keywords, product names, categories, or SKU numbers. You should use this tool whenever a customer is looking for a product or wants to know if we have something in stock.', schema: z.object({ query: z.string().describe('The search keywords that the user wants to look for') })})// ✅ Concise.withTool({ name: 'search', description: 'Search product catalog by keyword, name, category, or SKU. Use when customer asks about product availability.', schema: z.object({ query: z.string().describe('Search keywords') })})
function createAgent(features: string[]) { const builder = createPromptBuilder() .withIdentity('You are an assistant'); // Only add tools user has access to if (features.includes('database')) { builder.withTool(/* database tool */); } if (features.includes('email')) { builder.withTool(/* email tool */); } return builder;}// Basic user gets smaller promptconst basicAgent = createAgent(['email']);// Premium user gets full promptconst premiumAgent = createAgent(['database', 'email']);
const builder = createPromptBuilder() .withIdentity('You are a helpful assistant');// First call: builds and cachesconst prompt1 = builder.build();// Second call: returns cached result (instant)const prompt2 = builder.build();// Cache invalidates on changesbuilder.withCapability('Answer questions');const prompt3 = builder.build(); // Rebuilds and caches new version
Over-Optimization: Don’t sacrifice clarity for minimal savings:
// ❌ Too abbreviated.withIdentity('CS asst').withCapability('Proc ret')// ✅ Clear and concise.withIdentity('You are a customer service assistant').withCapability('Process returns')
Premature Optimization: Optimize after validating prompt behavior: