> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runflow.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Prompts

> Manage prompt templates with global and tenant-specific prompts

The **Prompts** module manages prompt templates with support for global and tenant-specific prompts.

## Using `loadPrompt()` with Agent (Recommended)

The simplest way to use prompts from the portal is with `loadPrompt()`. It works just like `openai()` - no await needed!

```typescript theme={null}
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

```typescript theme={null}
// 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:

```typescript theme={null}
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

<CardGroup cols={2}>
  <Card title="Agents" icon="robot" href="/core-concepts/agents">
    Learn about agents
  </Card>

  <Card title="Knowledge (RAG)" icon="database" href="/core-concepts/knowledge-rag">
    Learn about RAG
  </Card>
</CardGroup>
