Skip to main content
The Prompts module manages prompt templates with support for global and tenant-specific prompts. The simplest way to use prompts from the portal is with loadPrompt(). It works just like openai() - no await needed!
import { Agent, openai, loadPrompt } from '@runflow-ai/sdk';

// Load prompt directly in agent config - no await!
const agent = new Agent({
  name: 'Support Agent',
  instructions: loadPrompt('customer-support', {
    product: 'CRM Pro',
    tone: 'professional',
    greeting: 'Hello'
  }),
  model: openai('gpt-4o'),
});

// The prompt is resolved automatically when processing
await agent.process({ message: 'I need help!' });
How it works:
  1. loadPrompt() creates a lazy reference (no API call yet)
  2. When agent.process() runs, the prompt is fetched from the portal
  3. Variables are rendered automatically
  4. Result is cached for subsequent calls
// Without variables
instructions: loadPrompt('simple-prompt')

// With variables (uses {{variable}} syntax in prompt content)
instructions: loadPrompt('customer-support', {
  product: 'SaaS Platform',
  tone: 'friendly',
  language: 'Portuguese'
})

Standalone Prompts Manager

For more control, use the Prompts class directly:
import { Prompts } from '@runflow-ai/sdk';

const prompts = new Prompts();

// Get prompt (global or tenant-specific)
const prompt = await prompts.get('sistema');
console.log(prompt.content);
console.log('Is global?', prompt.isGlobal);

// List all available prompts
const allPrompts = await prompts.list({ limit: 50 });
allPrompts.forEach(p => {
  console.log(`${p.name} ${p.isGlobal ? '🌍' : '🏒'}`);
});

// Create tenant-specific prompt
const custom = await prompts.create(
  'my-prompt',
  'You are a specialist in {{topic}}.',
  { variables: ['topic'] }
);

// Update tenant prompt
await prompts.update('my-prompt', {
  content: 'You are a SENIOR specialist in {{topic}}.'
});

// Delete tenant prompt
await prompts.delete('my-prompt');

// Render template with variables
const rendered = prompts.render(
  'Hello {{name}}, welcome to {{company}}!',
  { name: 'John', company: 'Runflow' }
);

// Get and render in one call
const text = await prompts.getAndRender('my-prompt', { topic: 'AI' });

Security Rules

  • βœ… Can read global prompts (provided by Runflow)
  • βœ… Can create/update/delete own tenant prompts
  • ❌ Cannot modify global prompts
  • ❌ Cannot access other tenants’ prompts

Next Steps