> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Workspace: Multi Edit

> Apply multiple file edits atomically in the agent's workspace

Apply multiple file edits atomically. Each edit uses the same exact-match semantics as [Workspace: File Edit](/api-reference/v1/agents/workspace/file-edit). If any edit fails, all changes are rolled back.

## Path Parameters

<ParamField path="agent_id" type="string" required>
  Agent ID (UUID)
</ParamField>

## Request Body

<ParamField body="edits" type="array" required>
  Ordered list of edits to apply. Each item has:

  <Expandable title="Edit Object">
    <ParamField body="path" type="string" required>
      Path to the file to edit, relative to the workspace root.
    </ParamField>

    <ParamField body="old_text" type="string" required>
      Exact text to replace. Must match existing file content.
    </ParamField>

    <ParamField body="new_text" type="string" required>
      Replacement text.
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="status" type="string">
  Result status (e.g., `ok`).
</ResponseField>

## Example Request

```bash theme={"dark"}
curl -X POST "https://api.xpander.ai/v1/agents/<agent-id>/workspace/multi_edit" \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{
    "edits": [
      {
        "path": "app.py",
        "old_text": "DEBUG = True",
        "new_text": "DEBUG = False"
      }
    ]
  }'
```

## Notes

* Edits are applied in the order provided. Later edits can operate on content produced by earlier edits in the same request.
* If any single edit fails (e.g., `old_text` not found), the entire batch is rolled back so the workspace is not left in a half-applied state.

## See Also

* [Workspace: File Edit](/api-reference/v1/agents/workspace/file-edit)
* [Workspace: File Write](/api-reference/v1/agents/workspace/file-write)


## OpenAPI

````yaml POST /v1/agents/{agent_id}/workspace/multi_edit
openapi: 3.1.0
info:
  title: xpander.ai API Service
  description: |2-

        The xpander.ai API Service provides a unified REST API for managing AI agents,
        executing tasks, managing knowledge bases, and integrating with external systems.
        
        Features:
        - Agent Management: Create, update, deploy, and delete AI agents
        - Task Execution: Invoke agents with support for sync, async, and streaming modes
        - Knowledge Bases: Manage knowledge bases and documents for RAG workflows
        - Tools: Discover, connect, and attach tools (connectors, custom functions, MCP servers, sub-agents, workflows) to agents and workflows
        - MCP Integration: Model Context Protocol support for standardized AI interactions
        
        Authentication: All endpoints require authentication via either an API key (`x-api-key`) or an OAuth2 JWT (`Authorization: Bearer <jwt>`).
        
  version: '0.001'
servers:
  - url: https://api.xpander.ai
security: []
paths:
  /v1/agents/{agent_id}/workspace/multi_edit:
    post:
      tags:
        - API v1
        - Agents
        - Agents Workspace
      summary: 'Workspace: Multi Edit'
      description: >-
        Apply multiple edits atomically to one or more files in the agent's
        workspace. If any edit fails, all changes are rolled back.
      operationId: Workspace__Multi_Edit_v1_agents__agent_id__workspace_multi_edit_post
      parameters:
        - name: agent_id
          in: path
          required: true
          schema:
            type: string
            title: Agent Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MultiEditRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MultiEditResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    MultiEditRequest:
      properties:
        edits:
          items:
            $ref: '#/components/schemas/SingleEdit'
          type: array
          title: Edits
          description: >-
            List of edits to apply atomically. If any edit fails, all changes
            are rolled back.
      type: object
      required:
        - edits
      title: MultiEditRequest
    MultiEditResponse:
      properties:
        results:
          items:
            $ref: '#/components/schemas/SingleEditResult'
          type: array
          title: Results
          description: Results for each edit operation
      type: object
      title: MultiEditResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SingleEdit:
      properties:
        path:
          type: string
          title: Path
          description: Relative path to the file to edit
        old_text:
          type: string
          title: Old Text
          description: Exact text to find and replace
        new_text:
          type: string
          title: New Text
          description: Replacement text
      type: object
      required:
        - path
        - old_text
        - new_text
      title: SingleEdit
    SingleEditResult:
      properties:
        path:
          type: string
          title: Path
          description: The path of the edited file
        replacements_made:
          type: integer
          title: Replacements Made
          description: Number of replacements made in this file
          default: 0
      type: object
      required:
        - path
      title: SingleEditResult
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      description: API Key for authentication
      in: header
      name: x-api-key

````