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

# Agent Edit Study

> Execute AI-powered study editing with auto-save.

This endpoint:
1. Loads study from database
2. Executes agent with 20-tool toolpack (add/edit/remove questions, logic, assets, settings)
3. Automatically saves all mutations to database
4. Returns updated study state

Error handling: Full transaction rollback if any mutation fails.

Args:
    study_id: Study ID to edit
    request: Agent edit request with message, language, and optional documents
    supabase: Supabase service account client (injected)
    organization_id: Organization ID from API key (injected)

Returns:
    AgentEditResponseV1 with updated questions, logic, settings, and change log

Raises:
    HTTPException: 404 if study not found, 403 if forbidden, 500 if error

Use an AI agent to perform complex edits on a study, including modifying logic and settings. The agent will execute changes and return a summary.


## OpenAPI

````yaml POST /api/v1/studies/{study_id}/agent
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.getversive.com
security: []
paths:
  /api/v1/studies/{study_id}/agent:
    post:
      tags:
        - Studies
      summary: Agent Edit Study
      description: >-
        Execute AI-powered study editing with auto-save.


        This endpoint:

        1. Loads study from database

        2. Executes agent with 20-tool toolpack (add/edit/remove questions,
        logic, assets, settings)

        3. Automatically saves all mutations to database

        4. Returns updated study state


        Error handling: Full transaction rollback if any mutation fails.


        Args:
            study_id: Study ID to edit
            request: Agent edit request with message, language, and optional documents
            supabase: Supabase service account client (injected)
            organization_id: Organization ID from API key (injected)

        Returns:
            AgentEditResponseV1 with updated questions, logic, settings, and change log

        Raises:
            HTTPException: 404 if study not found, 403 if forbidden, 500 if error
      operationId: agent_edit_study_api_v1_studies__study_id__agent_post
      parameters:
        - name: study_id
          in: path
          required: true
          schema:
            type: string
            title: Study Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentEditRequestV1'
            example:
              message: Change the theme to dark mode and add a question about hobbies.
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentEditResponseV1'
              example:
                message: I have updated the study as requested.
                questions:
                  - id: q_123
                    content: Updated content?
                    type: text
                logic: []
                study_settings:
                  primaryColor: '#000000'
                changes:
                  - question_id: q_123
                    change_type: edited
                    description: Changed question text.
                deleted_question_ids: []
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
              example:
                detail:
                  - loc:
                      - body
                      - title
                    msg: field required
                    type: value_error.missing
      security:
        - HTTPBearer: []
components:
  schemas:
    AgentEditRequestV1:
      properties:
        message:
          type: string
          title: Message
      type: object
      required:
        - message
      title: AgentEditRequestV1
      description: Request for public v1 agent endpoint.
    AgentEditResponseV1:
      properties:
        message:
          type: string
          title: Message
        questions:
          items:
            additionalProperties: true
            type: object
          type: array
          title: Questions
        logic:
          items:
            additionalProperties: true
            type: object
          type: array
          title: Logic
        study_settings:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Study Settings
        changes:
          items:
            $ref: '#/components/schemas/QuestionChange'
          type: array
          title: Changes
        deleted_question_ids:
          items:
            type: string
          type: array
          title: Deleted Question Ids
      type: object
      required:
        - message
        - questions
        - logic
        - changes
        - deleted_question_ids
      title: AgentEditResponseV1
      description: Response from public v1 agent endpoint.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    QuestionChange:
      properties:
        question_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Question Id
        change_type:
          type: string
          title: Change Type
        description:
          type: string
          title: Description
      type: object
      required:
        - change_type
        - description
      title: QuestionChange
      description: Individual change for the changes log.
    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:
    HTTPBearer:
      type: http
      scheme: bearer

````