text
stringlengths
0
59.1k
});
// Use longer TTL for stable prompts
return await prompts.getPrompt({
promptName: "system-instructions",
promptCache: { ttl: 3600, enabled: true },
});
```
### Clear Cache
Force refresh by clearing the cache:
```typescript
voltOpsClient.prompts.clearCache();
```
### Cache Strategy Recommendations
| Prompt Type | TTL | Rationale |
| ------------------------ | -------- | --------------------------------------------- |
| High-frequency greetings | 60s | Frequently accessed, small updates acceptable |
| System instructions | 3600s | Rarely changes, benefit from longer cache |
| Personalized prompts | Disabled | Dynamic content, always fetch fresh |
```typescript
// High-frequency prompts: short TTL
await prompts.getPrompt({
promptName: "chat-greeting",
promptCache: { ttl: 60, enabled: true },
});
// Stable prompts: long TTL
await prompts.getPrompt({
promptName: "system-instructions",
promptCache: { ttl: 3600, enabled: true },
});
// Dynamic prompts: no cache
await prompts.getPrompt({
promptName: "personalized-prompt",
promptCache: { enabled: false },
variables: { userId: dynamicUserId },
});
```
### Preloading Prompts
Preload critical prompts at application startup:
```typescript
const criticalPrompts = ["welcome-message", "error-handler", "main-agent"];
await Promise.all(criticalPrompts.map((name) => prompts.getPrompt({ promptName: name })));
```
## Chat Prompts
Chat prompts define multi-message conversations with role-based structure.
### Fetching Chat Prompts
```typescript
const agent = new Agent({
name: "ChatAgent",
model: openai("gpt-4o-mini"),
instructions: async ({ prompts }) => {
return await prompts.getPrompt({
promptName: "chat-support-prompt",
variables: {
agentRole: "customer support specialist",
companyName: "VoltAgent Corp",
},
});
},
});
```
### Chat Prompt Structure
Chat prompts return a structure with messages:
```typescript
{
type: "chat",
messages: [
{ role: "system", content: "You are a customer support specialist." },
{ role: "user", content: "Hello, I need help." },
{ role: "assistant", content: "Hello! How can I assist you today?" }
]
}
```
## Error Handling
Implement fallback strategies for network failures or missing prompts:
```typescript
instructions: async ({ prompts }) => {
try {