> ## 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.

# Save sage context (step 1 → 2)

> Creates a new `ss_council_sage` post in `ss_draft` status with
the provided context data, then calls the Python API to register
the sage association.

For non-customizable (system) sages, checks that the council
does not already have one of that type. On failure, cleans up
the created post.

Advances `ss_setup_step` to 2 on success.

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




## OpenAPI

````yaml /openapi/private/specs/wp/sage-internal.yml post /wp-admin/admin-ajax.php?action=sagescreen_save_context
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_save_context:
    post:
      tags:
        - Sage – CRUD
      summary: Save sage context (step 1 → 2)
      description: |
        Creates a new `ss_council_sage` post in `ss_draft` status with
        the provided context data, then calls the Python API to register
        the sage association.

        For non-customizable (system) sages, checks that the council
        does not already have one of that type. On failure, cleans up
        the created post.

        Advances `ss_setup_step` to 2 on success.

        Registered as `wp_ajax_sagescreen_save_context` — **login required**.
      operationId: ajaxSaveContext
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/SaveContextRequest'
      responses:
        '200':
          description: Context saved and sage created
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/SaveContextSuccess'
                  - $ref: '#/components/schemas/AjaxErrorResponse'
              examples:
                success:
                  summary: Sage created
                  value:
                    success: true
                    data:
                      sage_id: 1234
                duplicateSystem:
                  summary: Duplicate system sage
                  value:
                    success: false
                    message: >-
                      A system sage of this type already exists for your
                      council. Only one system sage per type is allowed per
                      council.
                noCouncil:
                  summary: User has no council
                  value:
                    success: false
                    message: No council associated with user
                pythonFail:
                  summary: Python API failure
                  value:
                    success: false
                    message: >-
                      Failed to create sage in Python service: Connection
                      timeout
                missingFields:
                  summary: Required fields missing
                  value:
                    success: false
                    message: All fields are required
      security:
        - wpAjaxNonce: []
components:
  schemas:
    SaveContextRequest:
      type: object
      required:
        - action
        - nonce
        - base_sage_id
        - sage_name
        - role
        - role_level
        - job_description
      properties:
        action:
          type: string
          const: sagescreen_save_context
        nonce:
          type: string
          description: WP nonce for `sagescreen_frontend_nonce`
          examples:
            - abc123def456
        base_sage_id:
          type: string
          format: uuid
          description: UUID of the base sage template
          examples:
            - b1c2d3e4-f5a6-7890-bcde-f12345678901
        sage_name:
          type: string
          description: Display name for the new sage
          examples:
            - My Custom Sage
        language_code:
          type: string
          description: ISO language code
          examples:
            - en
        role:
          type: string
          description: Role type
          examples:
            - Developer
        role_level:
          type: string
          description: Seniority level
          examples:
            - senior
        job_description:
          type: string
          description: Job description / context for the sage
          examples:
            - Full-stack developer responsible for building web applications...
        default_tone:
          type: string
          description: Default tone from base sage
          examples:
            - professional
        default_role:
          type: string
          description: Default role from base sage
          examples:
            - interviewer
    SaveContextSuccess:
      type: object
      properties:
        success:
          type: boolean
          const: true
          examples:
            - true
        data:
          type: object
          required:
            - sage_id
          properties:
            sage_id:
              type: integer
              description: WordPress post ID of the created council sage
              examples:
                - 1234
    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
  securitySchemes:
    wpAjaxNonce:
      type: apiKey
      in: query
      name: nonce
      description: WordPress AJAX nonce (passed as form field, verified per-action)

````