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

# Undo last AI agent run

> Reverses the most recent AI-driven changes for the given `sessionId` and truncates that exchange from the conversation history.

Returns `success`, `hasUndo` (whether further undo steps are available), per-domain `results`, and a `changes` summary of what was restored.



## OpenAPI

````yaml post /ai-agent/undo
openapi: 3.1.0
info:
  title: HERO API
  version: current
  description: |-
    The HERO REST API.

    See https://developers.myhero.so for the rendered docs.
servers:
  - url: https://app.myhero.so
security: []
paths:
  /ai-agent/undo:
    post:
      tags:
        - AI
      summary: Undo last AI agent run
      description: >-
        Reverses the most recent AI-driven changes for the given `sessionId` and
        truncates that exchange from the conversation history.


        Returns `success`, `hasUndo` (whether further undo steps are available),
        per-domain `results`, and a `changes` summary of what was restored.
      operationId: aiUndo
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                sessionId:
                  type: string
                  minLength: 1
              required:
                - sessionId
      responses:
        '200':
          description: 200 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  hasUndo:
                    type: boolean
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        domain:
                          type: string
                        action:
                          type: string
                        success:
                          type: boolean
                          example: true
                        error:
                          type: string
                      required:
                        - domain
                        - action
                        - success
                  changes:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        name:
                          type: string
                        entityType:
                          type: string
                          enum:
                            - document
                            - table
                            - project
                        actions:
                          type: array
                          items:
                            type: string
                        snapshotId:
                          type: string
                      required:
                        - id
                        - name
                        - entityType
                        - actions
                required:
                  - success
                  - hasUndo
                  - results
        '400':
          description: 400 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '401':
          description: 401 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '403':
          description: 403 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: HERO personal access token

````