mastra/Core Concepts

Editor

Build and manage prompts with the Mastra Editor

editorpromptstemplatestools

Editor

Build and manage prompts with the Mastra Editor.

Topics

  • Overview - Introduction to the Editor
  • Tools - Editor tools and utilities
  • Prompts - Create and manage prompts

Editor Overview

Mastra Editor provides a visual interface for creating and managing prompts.

Features

  • Prompt templating
  • Variable management
  • Version history
  • Testing interface
  • A/B testing capabilities

Accessing the Editor

const editor = mastra.getEditor();

Creating a Prompt

const prompt = editor.createPrompt({
  name: 'greeting',
  template: 'Hello, {{name}}! How can I help you today?',
  variables: {
    name: { type: 'string', required: true },
  },
});

Editor Tools

Tools available in the Mastra Editor.

Built-in Tools

  • Text manipulation - String transformations
  • JSON parsing - Parse and validate JSON
  • Template rendering - Render prompt templates
  • Variable extraction - Extract variables from input

Custom Tools

editor.registerTool({
  name: 'myTool',
  description: 'A custom editor tool',
  execute: async (input) => {
    return { processed: input.toUpperCase() };
  },
});

Tool Providers

Share tools across your team:

const toolProvider = new ToolProvider({
  name: 'company-tools',
  tools: [customTool1, customTool2],
});

Prompts

Create and manage prompts in Mastra.

Prompt Structure

const prompt = {
  name: 'customerSupport',
  system: 'You are a helpful customer support agent.',
  template: 'Customer: {{message}}\nAgent:',
  variables: {
    message: { type: 'string', required: true },
  },
};

Prompt Versioning

const newVersion = editor.updatePrompt('customerSupport', {
  system: 'You are a professional customer support agent.',
});

console.log(newVersion.version); // 2

Testing Prompts

const result = await editor.testPrompt('customerSupport', {
  variables: { message: 'Where is my order?' },
});