# Agent tool reference

> Document-local tools exposed by editor.tools and revise/server.

Inspect authoritative JSON schemas at runtime with `editor.tools.getDefinitions()` (browser) or `doc.tools.definitions()` (Node).

- **Browser (`revise`):** Every schema includes optional `document_id` (defaults to active document).
- **Node (`revise/server`):** Single-document headless subset. Omits `document_id`, `get_selection`, `view_image`, and `revise_run_agent`. Use `doc.tools.run(name, input)` for untyped model calls and `doc.tools.call(name, input)` for typed calls; both return `{ ok: true, value } | { ok: false, error }`.

## Reading and searching

<ResponseField name="get_selection">
  Browser only. Returns the current semantic selection (text, caret/range offsets, portable target segments, active marks, comment IDs, suggestion IDs; no geometry).
</ResponseField>

<ResponseField name="read_blocks_from_index">
  Reads consecutive body blocks starting at 0-based `index`. Returns semantic HTML with block IDs.
</ResponseField>

<ResponseField name="read_specific_blocks">
  Reads blocks by ID.
</ResponseField>

<ResponseField name="search_document">
  Searches text within a document (paginated output). Active-document searches return a `search_result_id` covering all unpaginated matches, accepted by `replace`, `replace_block`, `style_blocks`, and `remove_blocks`.
</ResponseField>

<ResponseField name="find_highlights">
  Finds highlighted blocks (optionally filtered by color; 25 blocks per page). Highlights are omitted from standard reads.
</ResponseField>

<ResponseField name="measure_document">
  Returns word, paragraph, block, and page counts without loading body text. Primary totals treat pending suggestions as accepted; includes the original projection when different.
</ResponseField>

<ResponseField name="measure_blocks">
  Returns counts for inclusive block ranges.
</ResponseField>

<ResponseField name="view_image">
  Browser only. Fetches image data by block ID when `src` is omitted from HTML reads.
</ResponseField>

<Note>
  Read tools return [Revise semantic HTML](https://revise.io/developer/docs/editor-sdk/concepts/semantic-html) with block IDs, not flattened text. Mutation tools target those IDs.
</Note>

## Editing text

<ResponseField name="replace">
  Edits text inside a single block (or across all matched blocks via `search_result_id`) while preserving block identity and untouched formatting. Supports attaching a comment to produced suggestions.
</ResponseField>

<ResponseField name="insert_block">
  Inserts one or more semantic HTML blocks before or after a reference block. Inline `<sup data-footnote="Body.">1</sup>` creates the footnote in the same call.
</ResponseField>

<ResponseField name="replace_block">
  Replaces one block, an inclusive same-container range (`id` through `end_id`), or every block in `search_result_id` with semantic HTML. Invalid, reversed, or cross-container ranges fail atomically with `invalid_block_range`.
</ResponseField>

<ResponseField name="remove_blocks">
  Removes blocks by range (`id` through `end_id`), exact `ids`, tail (`through_end`), or `search_result_id`. Legacy alias `remove_block` still executes but is omitted from definitions.
</ResponseField>

<ResponseField name="append_to_paragraph">
  Appends inline HTML to an existing paragraph.
</ResponseField>

<ResponseField name="break_paragraph">
  Splits a paragraph at the first occurrence of a substring.
</ResponseField>

<ResponseField name="join_paragraphs">
  Joins two adjacent paragraphs, preserving inline formatting.
</ResponseField>

## Formatting

<ResponseField name="style_blocks">
  Bulk-applies formatting using CSS-lite selectors (`*`, `#blockId`, `p`, `h1`–`h6`, `li`, lists, tables, `b`, `i`, `code`, `mark`, `a`, scoped combinations like `p b` or `#blockId strong`). Accepts `search_result_id` (`*` matches every hit).
</ResponseField>

<ResponseField name="clear_formatting">
  Strips removable inline emphasis from targets.
</ResponseField>

## Structure and layout

<ResponseField name="set_title">
  Sets the document title.
</ResponseField>

<ResponseField name="set_page_layout">
  Configures preset, page size, orientation, margins, columns, page numbers, spacing, pageless mode, and page borders.
  - Lengths require explicit `in`, `cm`, or `px` units (`mm`/`pt` are rejected with converted suggestions and no changes). `pageWidth` and `pageHeight` must be paired and match a supported paper size (otherwise use `pageSize`).
  - Clamped bounds: margins `0–3in`, indent step `0.125–2in`, block spacing `0–2in` (clamping is reported in the result message).
  - Per-section page numbering: `pageNumberFormat` (`decimal` | `lowerRoman` | `upperRoman`), `sectionIndex`, `pageNumberStart`, `pageNumberRestart: false`.
  - `pageBorders`: per-edge (`top`, `right`, `bottom`, `left`) `style`, `color`, `widthPt`, `spacePt`; `offsetFrom` (`page` | `text`); `display` (`allPages` | `firstPage` | `notFirstPage`); `zOrder` (`front` | `back`); `clearPageBorders: true` removes borders (omitted fields stay unchanged).
</ResponseField>

<ResponseField name="set_header_footer">
  Sets header/footer zones (`left`, `center`, `right`; empty string clears a zone; `{PAGE}` and `{PAGES}` are live fields). Supports `slot` (`default` | `first` | `even`), 1-based `sectionIndex`, zone `image` (`image_id` of an existing image, optional `alt`/`width`/`height`), and `clear: true` (omitting `slot` and `sectionIndex` clears that side across all sections). No-op calls fail with `"No changes detected"`.
</ResponseField>

<ResponseField name="insert_footnote">
  Inserts a numbered superscript reference and footnote/endnote body.
</ResponseField>

## Tables

<ResponseField name="read_table">
  Reads a table by `table_id`:
  - `mode: "summary"`: dimensions and per-column empty/filled/covered counts (no cell text).
  - `mode: "rows"` (default): up to 50 rows, optional column range, merged spans, and `next_read` continuation.
  - `mode: "cell_text"`: pages through an oversized cell.

  Only cells returned in full by a `rows` read authorize `edit_table_cells`. Native agent task-declaration arguments are rejected with `unsupported_argument`.
</ResponseField>

<ResponseField name="edit_table_cells">
  Sets plain text for up to 50 cells (`table_id`, `row_id`, 0-based `column`). `text` is literal (not parsed as HTML or numbers). `mode: "fill_if_empty"` skips populated cells; `mode: "replace"` overwrites read cells. Unread, unknown, duplicate, merged-covered, stale, or rich-content targets reject the entire batch atomically. In suggesting mode, each cell creates its own suggestion.
</ResponseField>

<ResponseField name="insert_table_row">
  Inserts a row `"before"` or `"after"` `referenceRowId` (preferred, from `<tr id>`) or 0-based `referenceIndex` in `tableId`. `content` is an array of cell HTML strings indexed by 0-based grid column (use `""` for merged-covered positions, or `[]` for empty cells); non-empty content at covered positions or out-of-bounds entries reject atomically.
</ResponseField>
<ResponseField name="remove_table_rows">
  Removes one or more rows by `rowIds` (stable across row edits) or `rowIndices` fallback. All cells in targeted rows must have been read; unknown, duplicate, or unread rows reject atomically. Legacy `remove_table_row` (`{ tableId, rowIndex }`) remains supported.
</ResponseField>
<ResponseField name="insert_table_column">
  Inserts a column `"before"` or `"after"` 0-based `referenceIndex` in `tableId`. `content` is an array of cell HTML strings indexed by 0-based grid row (use `""` for merged-covered positions, or `[]` for empty cells); invalid entries reject atomically.
</ResponseField>
<ResponseField name="remove_table_column">
  Removes the 0-based `columnIndex` from `tableId`.
</ResponseField>

<Warning>
  Table mutations require a prior read in the same session (`read_table` rows
  read for `edit_table_cells`; `read_table` or block read for row/column tools
  and table `replace_block`). Missing or stale reads fail atomically with
  `document_state_changed` (`table_not_read` or `table_stale`). Reordering
  existing rows, cells, or cell blocks fails with `table_order_changed`.
</Warning>

## Comments

<ResponseField name="leave_comment">
  Starts, replies to, or manages comment threads without editing document text:
  - **Start:** pass `id`, `comment`, and one `anchor` (`{ text }`, `{ start_text, end_text }`, or `{ whole_block: true }`). Overlapping an unresolved thread fails unless listed in `acknowledge_existing_thread_ids`.
  - **Reply:** pass `reply_to_comment_id` and `comment` (no `id` or `anchor`).
  - **Manage:** pass `action: "resolve" | "reopen" | "delete"` with `reply_to_comment_id` (no `comment`, `id`, or `anchor`). `delete` removes the entire thread; `resolve` keeps history.
</ResponseField>

## Delegation

<ResponseField name="revise_run_agent">
  Browser only. Delegates a multi-turn task to Revise's agent loop (which can call internal `render_document_pages`). Invoke via `editor.tools.executeDynamic("revise_run_agent", { task })` or `editor.agent.run(task)`. Excluded from `editor.tools.getDefinitions()`. See [delegation](https://revise.io/developer/docs/editor-sdk/guides/delegated-agent).
</ResponseField>

## Excluded UI operations

Review navigation, comment-panel toggles, focus, viewport geometry, zoom, and direct canvas rendering are host-only APIs on [`ReviseEditorHandle`](https://revise.io/developer/docs/editor-sdk/api/handle), not agent tools.
