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

# AI-assisted content generation

> Sends form data to the AI model with a prompt configured per
form type (context or culture). Returns generated content that
can be either JSON or plain text depending on the prompt.

Uses the `sage_screen_form_prompt_context` or
`sage_screen_form_prompt_culture` options as the system prompt.

Registered as `wp_ajax_sagescreen_ai_generate` — **login required**.




## OpenAPI

````yaml /openapi/private/specs/wp/sage-internal.yml post /wp-admin/admin-ajax.php?action=sagescreen_ai_generate
openapi: 3.1.0
info:
  title: SageScreen — Sage Module
  description: >
    Council sage management. Sages are AI screening assistants customized

    per council. Each council can have system sages (non-customizable,

    auto-attached) and custom sages (built through a multi-step workflow).


    **CPT:** `ss_council_sage`

    **Custom statuses:** `ss_draft`, `ss_building`, `ss_active`, `ss_inactive`,
    `ss_paused`


    ## Build Workflow


    Custom sages go through a 6-step creation workflow:

    1. **Context** — Define role, level, and job description

    2. **Culture** — Configure tone, scoring, intro question, evaluation
    guidelines

    3. **Build** — Automated build via Python service (8 sub-steps)

    4. **Test** — Optional test screen to verify sage behavior

    5. **Finalize** — Review and confirm build

    6. **Deploy** — Set email config and activate sage


    Build sub-steps (step 3) run sequentially in the Python service:

    `starting` → `creating_sage` → `sage_generation` → `test_shu` →

    `test_ha` → `test_ri` → `transcending_training` → `enlightenment`
  version: 1.0.0
servers:
  - url: https://{domain}/wp-json/sagescreen/v1
    description: WordPress REST API
    variables:
      domain:
        default: api.sagescreen.app
security: []
tags:
  - name: Sage – REST
    description: REST API endpoints for sage operations and Python callbacks
  - name: Sage – CRUD
    description: AJAX endpoints for sage creation, editing, and status management
  - name: Sage – Build Workflow
    description: AJAX endpoints for the multi-step sage build process
paths:
  /wp-admin/admin-ajax.php?action=sagescreen_ai_generate:
    post:
      tags:
        - Sage – CRUD
      summary: AI-assisted content generation
      description: |
        Sends form data to the AI model with a prompt configured per
        form type (context or culture). Returns generated content that
        can be either JSON or plain text depending on the prompt.

        Uses the `sage_screen_form_prompt_context` or
        `sage_screen_form_prompt_culture` options as the system prompt.

        Registered as `wp_ajax_sagescreen_ai_generate` — **login required**.
      operationId: ajaxAiGenerate
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/AiGenerateRequest'
      responses:
        '200':
          description: AI generation result
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/AiGenerateSuccess'
                  - $ref: '#/components/schemas/AjaxErrorResponse'
              examples:
                jsonContent:
                  summary: Generated JSON content
                  value:
                    success: true
                    content:
                      intro_question: Tell me about a time you handled a difficult customer.
                      intro_reasoning: This question assesses conflict resolution skills.
                textContent:
                  summary: Generated text content
                  value:
                    success: true
                    content: You are a senior software engineering interviewer...
                invalidForm:
                  summary: Invalid form identifier
                  value:
                    success: false
                    message: Invalid form identifier
      security:
        - wpAjaxNonce: []
components:
  schemas:
    AiGenerateRequest:
      type: object
      required:
        - action
        - nonce
        - form_data
        - form_identifier
      properties:
        action:
          type: string
          const: sagescreen_ai_generate
        nonce:
          type: string
          description: WP nonce for `sagescreen_frontend_nonce`
          examples:
            - abc123def456
        form_data:
          type: object
          description: Key-value pairs of form field data to send to AI
          additionalProperties:
            type: string
          examples:
            - role: Developer
              role_level: senior
              job_description: Full-stack web development
        form_identifier:
          $ref: '#/components/schemas/FormIdentifier'
        language_code:
          type: string
          description: ISO language code for generation language
          examples:
            - en
    AiGenerateSuccess:
      type: object
      properties:
        success:
          type: boolean
          const: true
          examples:
            - true
        content:
          oneOf:
            - type: object
              description: Generated JSON content
              additionalProperties: true
              examples:
                - intro_question: Tell me about...
                  intro_reasoning: This assesses...
            - type: string
              description: Generated text content
              examples:
                - You are a senior software engineering interviewer...
    AjaxErrorResponse:
      type: object
      description: |
        Standard AJAX error. The `data` field is either a plain string
        (from `wp_send_json_error`) or absent when using `wp_send_json`
        directly with `success: false`.
      properties:
        success:
          type: boolean
          const: false
          examples:
            - false
        message:
          type: string
          description: Error message (when using wp_send_json directly)
          examples:
            - Security check failed
        data:
          oneOf:
            - type: string
              examples:
                - Security check failed
            - type: object
              properties:
                message:
                  type: string
                  examples:
                    - Insufficient permissions
    FormIdentifier:
      type: string
      description: Form type for AI generation
      enum:
        - context
        - culture
      examples:
        - context
  securitySchemes:
    wpAjaxNonce:
      type: apiKey
      in: query
      name: nonce
      description: WordPress AJAX nonce (passed as form field, verified per-action)

````