text stringlengths 0 59.1k |
|---|
return await prompts.getPrompt({ |
promptName: "customer-support-prompt", |
label: label, |
}); |
}, |
}); |
``` |
### Available Labels |
| Label | Purpose | |
| ------------- | ----------------------- | |
| `production` | Live production traffic | |
| `staging` | Pre-production testing | |
| `development` | Active development | |
| `testing` | QA environments | |
| `latest` | Most recent version | |
You can also use custom labels (e.g., `beta`, `canary`, `region-eu`). |
## Template Variables |
Pass dynamic values to replace template variables in prompts: |
```typescript |
const agent = new Agent({ |
name: "DynamicAgent", |
model: openai("gpt-4o-mini"), |
instructions: async ({ prompts, context }) => { |
return await prompts.getPrompt({ |
promptName: "customer-support-prompt", |
label: "production", |
variables: { |
companyName: "VoltAgent Corp", |
userName: context.get("userName") || "Guest", |
tier: context.get("subscriptionTier") || "free", |
}, |
}); |
}, |
}); |
``` |
### Using with Agent Context |
```typescript |
const userContext = new Map(); |
userContext.set("userName", "Alice"); |
userContext.set("subscriptionTier", "premium"); |
const response = await agent.generateText("I need help", { |
context: userContext, |
}); |
``` |
### Variable Sanitization |
Sanitize user-provided variables to prevent prompt injection: |
```typescript |
instructions: async ({ prompts, context }) => { |
const sanitizedUserName = |
context.get("userName")?.replace(/[<>]/g, "")?.substring(0, 50) || "Guest"; |
return await prompts.getPrompt({ |
promptName: "personalized-greeting", |
variables: { userName: sanitizedUserName }, |
}); |
}; |
``` |
## Caching |
VoltOps supports two levels of caching to reduce API calls and improve performance. |
### Global Cache |
Configure caching at the VoltOpsClient level: |
```typescript |
const voltOpsClient = new VoltOpsClient({ |
publicKey: process.env.VOLTAGENT_PUBLIC_KEY, |
secretKey: process.env.VOLTAGENT_SECRET_KEY, |
prompts: true, |
promptCache: { |
enabled: true, |
ttl: 300, // Seconds until expiration |
maxSize: 100, // Maximum cached prompts |
}, |
}); |
``` |
### Per-Prompt Cache Override |
Override cache settings for individual fetches: |
```typescript |
// Disable cache for this specific fetch |
return await prompts.getPrompt({ |
promptName: "customer-support-prompt", |
promptCache: { enabled: false }, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.