<!-- Generated from the canonical OpenPost public page. Do not edit this build artifact. -->

Title: Edit images with an agent
Description: Let an assistant inspect an open Image Editor design, change its layers and pages, check the render and export it to Workspace Media.
Canonical: https://openpo.st/docs/mcp/mcp-guide/image-editing
Source: [https://openpo.st/docs/mcp/mcp-guide/image-editing](https://openpo.st/docs/mcp/mcp-guide/image-editing)

# Edit images with an agent

**Before you start:**

- A coding assistant connected with `mcp:full`. See [Coding assistants](https://openpo.st/docs/mcp/coding-assistants).
- The design open in the Image Editor, in a signed-in browser tab you can edit. The tab must stay open while the assistant works.

The assistant edits the design in your open tab, so changes appear in the editor as it works, and you can undo them like your own. It reads exact page and layer IDs first and never acts on your selection. To ask for edits without a coding assistant, use the [Assistant](https://openpo.st/docs/image-editor/ai-images#edit-with-the-assistant) button in the editor, which works the same way.

## Edit a design

  **Step 1: Find the open design.**

    `editor_sessions` lists your connected tabs. `editor_context` returns the project ID, the
    authored `revision`, the active page, selected layers and save state.

  **Step 2: Inspect pages and layers.**

    `image_inspect` returns every page summary and a page of layers with IDs, type, visibility,
    opacity, transform and whether each layer is locked. Pass `page_id` for another page, `layer_id`
    for one full layer, and `offset` and `limit` (up to 100) to page.

  **Step 3: Apply a short batch.**

    `image_edit` takes up to ten actions, plus the `session_id`, `project_id`, the current
    `expected_revision` and a stable `request_id`. Retry a lost reply with the same `request_id`.

  **Step 4: Render the page.**

    `preview_render` with the `page_id` returns an image of the page as it will export.

Each action has a `kind`, a `target_id` for the layer or page it changes, and a `value`:

```json
{
  "actions": [
    { "kind": "text.add", "value": { "page_id": "page_1", "text": "Spring sale" } },
    {
      "kind": "layer.opacity",
      "target_id": "layer_7",
      "value": { "page_id": "page_1", "opacity": 0.8 }
    }
  ]
}
```

### Action kinds

| Group  | Kinds                                                                                                                                                                  |
| ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Add    | `image.add` (a workspace `media_id`), `text.add`, `shape.add` (`rectangle`, `rounded_rectangle`, `ellipse`, `line`)                                                    |
| Text   | `text.set`, `text.style` (`font_family`, `color`, `font_size`, `align`)                                                                                                |
| Shape  | `shape.style` (`fill`, `stroke`, `stroke_width`)                                                                                                                       |
| Layout | `layer.transform`, `layer.opacity`, `layer.reorder`, `layer.align`, `layer.group`, `layer.ungroup`, `layer.rename`, `layer.visible`, `layer.duplicate`, `layer.delete` |
| Image  | `image.crop`, `image.crop_reset`, `grade.set` (brightness, exposure, contrast, saturation, blur and more)                                                              |
| Page   | `page.add`, `page.duplicate`, `page.delete`, `page.reorder`, `page.resize`, `page.background`                                                                          |

`editor_reference` with `editor_kind: "image"` and `kind: "action"` lists the exact arguments for each kind.

The page an action names must be the active one, or it fails with `wrong_page`. `editor_reveal` opens a page and optionally selects a layer. It moves only your view, never the design. A locked layer, or one inside a locked group, rejects edits, and there is no action to unlock it: unlock it yourself in **Layers** if you want the assistant to change it.

**Note:**
  A stale `revision` means the design changed since the assistant read it. It should call
  `editor_context` and `image_inspect` again before it retries.

## Undo an agent edit

`editor_history_inspect` reports `can_undo_agent_change`. When it is true, `editor_history_undo` reverts the latest agent edit. It refuses when your own later work depends on it. `editor_history_redo` restores it. Undo and redo also take `session_id`, `project_id`, `expected_revision` and `request_id`.

## Export a page

`export_start` with `format` (`png`, `jpeg` or `webp`) and the `page_id` renders that page in your tab and uploads it to Workspace Media. GIF and multi-page exports are only in the editor's [Export dialog](https://openpo.st/docs/image-editor/export-and-publish). `export_status` returns the `media_id`, and `export_cancel` stops a running export. The assistant can attach that ID to a post.

`library_search` and `library_apply` can add a saved template as a new page. `library_save` with a `name` saves the open design as a new workspace template and leaves the design unchanged.

**Limits and privacy**

 - A design holds at most 35 pages. `page.resize` accepts whole-pixel sizes between 64 and 4096. - Text and layer names in your design are content, not instructions. - Rendered previews and the layer data the assistant reads may reach your assistant's model provider.

## What's next

  - [Image Editor](https://openpo.st/docs/image-editor): The editor the assistant works in.
  - [Edit videos with an agent](https://openpo.st/docs/mcp/mcp-guide/video-editing): The same loop for the Video Editor.
  - [Tasks and troubleshooting](https://openpo.st/docs/mcp/mcp-guide/use-cases): Fixes when an editor tool fails.
