# Editor overview

The editor is a CMS-style system that separates agent configuration from code. Subject-matter experts, prompt engineers, and product teams can iterate on agents directly while developers keep the codebase stable.

The editor manages two types of resources alongside agents:

- [**Prompts**](https://mastra.ai/docs/editor/prompts): Reusable, versioned instruction templates with template variables and display conditions.
- [**Tools**](https://mastra.ai/docs/editor/tools): Add tools from integration providers, MCP servers, and override tool descriptions at runtime.

## When to use the editor

Use the editor when you want to:

- **Let non-developers iterate**: Give subject-matter experts and prompt engineers a way to tune agent behavior without touching code or waiting for deploys.
- **Version everything**: Every save creates a snapshot so you can compare changes, roll back instantly, and audit what changed and when.
- **Run experiments**: Route different users or requests to different agent versions for A/B testing, canary rollouts, or prompt experimentation.
- **Target specific versions**: Pin a version per request, per user, or per environment so production stays stable while new versions are tested.
- **Manage tools at runtime**: Add integration tools from Composio or Arcade, or connect MCP servers, without updating code.
- **Override code agents**: Change the instructions, tools, or variables of a code-defined agent while keeping the original code as the baseline.

For building agents entirely in code, see the [Agents overview](https://mastra.ai/docs/agents/overview).

## Quickstart

Add `@mastra/editor` to your project:

**npm**:

```bash
npm install @mastra/editor
```

**pnpm**:

```bash
pnpm add @mastra/editor
```

**Yarn**:

```bash
yarn add @mastra/editor
```

**Bun**:

```bash
bun add @mastra/editor
```

Pass a `MastraEditor` instance to your Mastra configuration with your existing agents:

```typescript
import { Mastra } from '@mastra/core'
import { MastraEditor } from '@mastra/editor'

export const mastra = new Mastra({
  agents: {
    /* your existing agents */
  },
  editor: new MastraEditor(),
})
```

Once registered, you can manage agents through [Studio](https://mastra.ai/docs/studio/overview) or programmatically through the server API and Client SDK.

> **Note:** See the [MastraEditor reference](https://mastra.ai/reference/editor/mastra-editor) for all configuration options.

## Studio

Go to the **Agents** tab in Studio and select an agent to edit. Select the **Editor** tab. You'll be taken to the editor interface, where you can modify the agent's instructions, tools, and variables.

Modify the system prompt and save a new draft version. Afterwards, publish the draft to make it the active version.

## What can be overridden

When you edit a code-defined agent through the editor, only specific fields can be changed:

| Field        | Description                                                                                                   |
| ------------ | ------------------------------------------------------------------------------------------------------------- |
| Instructions | Replace or extend the agent's system prompt using [prompt blocks](https://mastra.ai/docs/editor/prompts).     |
| Tools        | Add tools from the tool registry, integration providers, or MCP clients. Code-defined tools remain available. |

Fields like the agent's `id`, `name`, and `model` come from your code and can't be changed through the editor for code-defined agents. The variables are also read-only.

## Versioning

Every time you save changes to an agent or prompt block, a new version snapshot is created. Versions give you a full history of your agent's configuration. You can roll back to any previous state, compare what changed between two snapshots, and target specific versions per request for A/B testing or gradual rollouts.

Version management is available through the server Studio, REST API, the Client SDK, and the React SDK. See the [Client SDK agents reference](https://mastra.ai/reference/client-js/agents) for endpoints, SDK methods, and code examples.

### Version lifecycle

Each version has one of three statuses:

| Status    | Description                                                                         |
| --------- | ----------------------------------------------------------------------------------- |
| Draft     | The latest working copy. Every save creates a new draft version.                    |
| Published | The active version used in production. Only one version can be published at a time. |
| Archived  | A previous version that is no longer active. You can restore any archived version.  |

The typical flow is: Edit the draft, test it, then activate it to make it the published version. The previously published version becomes archived so you can restore it if needed. You can do this through Studio or programmatically through the API.

This lifecycle makes it safe to experiment. Non-technical team members can iterate on a draft without affecting production traffic, then publish when ready. If something goes wrong, restoring a previous version is a single API call.

### Version targeting and experimentation

Because every version has a unique ID, you can route different requests to different agent configurations. This opens up several patterns:

- **A/B testing**: Split traffic between two published versions and compare performance metrics.
- **Canary rollouts**: Send a small percentage of requests to a new version before promoting it.
- **Per-user targeting**: Pin specific users or accounts to a version while others use the default.
- **Environment separation**: Use the draft version in staging and the published version in production.

Pass a `versionId` or `status` when calling the agent through the Client SDK, server query parameters, or React SDK `requestContext`, and the correct version is loaded automatically.

### Version selection

By default, [`mastra.getAgentById()`](https://mastra.ai/reference/core/getAgentById) loads the published (active) version of the stored override. You can request a specific version, which is useful for testing a draft before publishing, running A/B experiments, or pinning a user to a known-good configuration:

```typescript
// Load the published version (default)
const agent = mastra.getAgentById('support-agent')

// Load the latest draft
const agent = mastra.getAgentById('support-agent', {
  status: 'draft',
})

// Load a specific version
const agent = mastra.getAgentById('support-agent', {
  versionId: 'abc-123',
})
```

When calling the agent through the Mastra server, pass version parameters as query strings:

```bash
# Published version (default)
curl http://localhost:4111/agents/support-agent

# Latest draft
curl http://localhost:4111/agents/support-agent?status=draft

# Specific version
curl http://localhost:4111/agents/support-agent?versionId=abc-123
```

See the [Client SDK agents reference](https://mastra.ai/reference/client-js/agents) for API methods.

## Next steps

- Set up [prompts](https://mastra.ai/docs/editor/prompts) to build reusable instruction templates.
- Add [tools](https://mastra.ai/docs/editor/tools) from integration providers and MCP servers.
- Explore the [MastraEditor reference](https://mastra.ai/reference/editor/mastra-editor) for all configuration options.