Targeted edits

Change a few lines of code or instructions without resending the whole text or overwriting a teammate.

Targeted edits let an AI agent change a few lines of Python or a sentence of instructions without resending the whole text. The agent reads only the part it needs and replaces exact text. It passes the revision it read, so a teammate's concurrent change is never silently overwritten.

Agents should prefer targeted edits over full replacements. They cost fewer tokens and cannot drop unrelated text by accident. Both kinds of update return a diff of what changed. Reads and edits use each resource's normal read and update tools, so there is no separate patch tool to learn.

Supported resources

ResourceRead toolUpdate toolText field
Python actionget_action_details (actionType: "python")update_python_actioncode
Condition providerget_condition_providerupdate_condition_providercode
Event handlerget_event_handlerupdate_event_handlercode
Recurring jobget_recurring_jobupdate_recurring_jobcode
Python moduleget_python_moduleupdate_python_modulecode
HTTP endpointget_http_endpointupdate_http_endpointcode
Sidebar widgetget_sidebar_widget_detailsupdate_sidebar_widgetcode
Sidebar widget actionget_sidebar_widget_actionupdate_sidebar_widget_actioncode
Product-sync parserget_product_sync_parserupsert_product_sync_parsercode
Workflow variantget_workflowupdate_workflow_variantbotInstructions
Comment workflowget_comment_workflowupdate_comment_workflowbotInstructions, dmBotInstructions
Review workflowget_review_workflowupdate_review_workflowbotInstructions
Custom Python prompt sectionget_system_promptupdate_system_prompt (patch)systemPromptSectionCode
Knowledge base articleget_articleupdate_articlecontent
Macroget_macroupdate_macrocontent

Targeted edits work on these text fields, not on arbitrary JSON paths. They don't cover nested review email steps or review category settings.

Knowledge base articles (get_article / update_article) and macros (get_macro / update_macro) also support this interface for content: use contentSelection, contentRevision, contentEdits, fullContent, and expectedContentRevision. For articles this edits the main-language content; set_article_translation still takes a translation's complete content. Portal HTML uses get_portal_page and patch_portal_page; see Portal MCP tools.

List tools for articles, macros, sidebar widgets, comment workflows and review workflows return metadata plus <field>Preview (up to 300 characters) and <field>Chars, instead of full text bodies. Use their detail readers for source. Existing list filters and pagination are unchanged.

Read bounded text, selected lines or search matches

Omit selection arguments to read the first 12,000 characters of each text field. Small fields are returned completely, and a read always says when it returned only an excerpt. To read selected Python lines:

{
  "organizationId": "your-organization-id",
  "actionId": "your-action-id",
  "actionType": "python",
  "codeSelection": { "startLine": 100, "endLine": 160 }
}

Line numbers are 1-based and inclusive. Omit startLine to begin at line 1 or endLine to read through the end. Out-of-range or reversed ranges fail.

To search literal text with context:

{
  "organizationId": "your-organization-id",
  "actionId": "your-action-id",
  "actionType": "python",
  "codeSelection": { "find": "def execute_action", "contextLines": 10 }
}

Search and line ranges cannot be combined. Search is literal and case-sensitive, with five lines of context by default. Results report the total number of matches and return context for at most the first 50. Nearby windows are merged, and omitted matches are marked as truncated. A search with no match returns zero matches, not an arbitrary excerpt.

A selected read returns its text in code, with line and absolute character boundaries in codeRead.excerpts, total sizes in codeRead.totalLines and codeRead.totalChars, and an opaque codeRevision for the complete code field. Copy that revision into the update call. Default reads also return the revision. Do not calculate revision tokens yourself.

For workflow instructions, use botInstructionsSelection and copy botInstructionsRevision. On get_workflow, also provide variantId when selecting or searching instructions. This returns only that variant; omitting both arguments retains the full workflow read. The variant must belong to the requested workflow.

Character limits and continuation

Every text read, including a line range or search result, is capped at 12,000 characters by default. Set maxChars (1 to 50,000) inside the selection to change the budget. This also bounds minified HTML or JSON on a single very long line. When codeRead.truncated is true, use codeSelection: { "offset": <codeRead.nextOffset>, "maxChars": 12000 } to read onward in the original field. Offsets are zero-based UTF-16 character positions, not byte offsets. Offset reads cannot be combined with line ranges or searches. Search continuation reads raw text from the indicated position; it does not repeat the search.

Use textFields to include only particular text fields; [] returns metadata only. For example, get_comment_workflow can request textFields: ["dmBotInstructions"] without also loading botInstructions. Include a field in textFields if you also supply its selection. On workflows, choose variantId to avoid reading every variant.

Never pass an excerpt to a full replacement argument. Prefer exact edits with the complete field's revision; if deliberately replacing a field, construct the entire replacement. Re-read if the revision changes between pages.

The same read selections are available on get_response_system_prompt (systemPromptSelection) and get_search_ui_config (for example searchResultsHtmlSelection, with textFields: ["searchResultsHtml"]). These read options do not add patch writes to those tools. read_octocom_docs accepts contentSelection and returns contentRead per page; request one slug when paging a particular document. These caps apply to Copilot and MCP results, not to the dashboard or REST API.

Make exact-text edits

Call the resource's existing update tool. For example, update_python_action:

{
  "organizationId": "your-organization-id",
  "actionId": "your-action-id",
  "expectedCodeRevision": "revision-from-the-read-response",
  "codeEdits": [
    {
      "oldText": "return status == \"returned\"",
      "newText": "return status in {\"returned\", \"return_to_sender\"}"
    }
  ]
}

Each oldText must match exactly once, including whitespace, indentation and newline characters. If there are multiple matches, include more surrounding text to identify the intended occurrence. If there are no matches, read the current content and copy the text exactly. The tool never silently picks the first occurrence or replaces every occurrence.

Edits apply in array order, so a later edit sees the result of earlier edits. The whole call succeeds together or nothing is saved. Empty newText deletes the matched text. To insert text, replace an existing anchor with that anchor plus the addition. Empty oldText is invalid.

For workflow variants, use botInstructionsEdits and expectedBotInstructionsRevision. Comment DM instructions use dmBotInstructionsEdits and expectedDmBotInstructionsRevision. The custom Python prompt section uses systemPromptSectionCodeEdits and expectedSystemPromptSectionCodeRevision.

For update_http_endpoint, editing arguments belong inside its existing endpoint object. For update_review_workflow, they belong inside updates. Resource IDs and organizationId stay at their existing locations.

Full replacements remain available

Use fullCode to deliberately replace the entire script. It requires expectedCodeRevision from the read tool. For instructions use fullBotInstructions; for DM instructions use fullDmBotInstructions. Custom prompt code uses fullSystemPromptSectionCode. Each uses the corresponding expected revision.

For each text field, provide only one mode: full replacement or edits. Both are optional because settings-only updates, such as renaming or disabling a resource, do not change its text. An expected revision without a corresponding text change is invalid.

update_article and set_article_translation reject arguments they do not know instead of ignoring them, so a misspelled editing argument fails without saving anything.

The plain code, botInstructions, dmBotInstructions, systemPromptSectionCode and (on articles and macros) content arguments are full-replacement aliases kept for compatibility. Without a revision, they replace the whole field with no concurrency check. Prefer the explicit full-replacement fields or edits with a revision. Do not combine an alias with a replacement or edits argument for the same field.

Create tools take full content. To create the first product-sync parser, call upsert_product_sync_parser with code. Its edit and full-replacement arguments need an existing parser; they cannot patch one that does not exist yet.

Verify and recover

The server locks the resource before checking its revision and saving. If its text changed since the read, the entire update is rejected. Read it again, reassess the change, and retry with the new token. Repeated retries using the same stale token will not work.

Successful updates that use edits or a full replacement return textChanges, keyed by the edited field. Each entry contains the saved revision, a before/after diff, and diffTruncated. The response omits the resource's large text fields. Diff output is bounded; when it is truncated or computation exceeds its limit, use a selected read to inspect the saved section.

Existing field constraints, resource permissions, approval behavior and version-history paths still apply. Updating code does not automatically execute it. Run the resource's existing test tool when you need to verify behavior, remembering that test execution can have real side effects.

On this page