{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/korely-ai/json-schema/korely-ai-context-response-schema.json",
  "title": "ContextResponse",
  "x-generated": "2026-11-14",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/korely-ai-openapi.json#/components/schemas/ContextResponse",
  "properties": {
    "context": {
      "type": "string",
      "title": "Context"
    },
    "tokens": {
      "type": "integer",
      "title": "Tokens"
    },
    "sources": {
      "items": {
        "type": "string"
      },
      "type": "array",
      "title": "Sources"
    },
    "degraded": {
      "type": "boolean",
      "title": "Degraded",
      "default": false
    },
    "degraded_parts": {
      "items": {
        "type": "string"
      },
      "type": "array",
      "title": "Degraded Parts"
    },
    "stable": {
      "type": "string",
      "title": "Stable",
      "description": "The head of `context` that does not depend on the question: the reader note, the same text from one call to the next. Put it in your system prompt, where the model provider's prompt cache can reuse it.",
      "default": ""
    },
    "volatile": {
      "type": "string",
      "title": "Volatile",
      "description": "The rest of `context`: the facts and the memories for this question and, when part of the retrieval failed, a closing NOTE. Put it in the turn.",
      "default": ""
    },
    "stable_hash": {
      "type": "string",
      "title": "Stable Hash",
      "description": "SHA-256 (hex) of `stable`. The same value means the same prefix, so a cached system prompt is still valid.",
      "default": ""
    },
    "changed": {
      "anyOf": [
        {
          "items": {
            "$ref": "#/$defs/Change"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Changed",
      "description": "With `reader` only: the facts this reader was handed by an earlier read and that changed since, as the block's section \"Changed since you last read\" shows them, newest first, at most 3. Each is told at most once."
    },
    "changed_more": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Changed More",
      "description": "With `reader` only: how many more changes wait for this reader, behind the same walls; told in the blocks that follow. Null when the changes could not be read this time (their records were locked): they wait for the next read."
    }
  },
  "type": "object",
  "required": [
    "context",
    "tokens",
    "sources"
  ],
  "$defs": {
    "Change": {
      "properties": {
        "fact_id": {
          "type": "string",
          "title": "Fact Id",
          "description": "The `fct_` id of the fact the reader was handed."
        },
        "was": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Was",
          "description": "It, as the block writes a fact; null when the memory that stated it was forgotten, whose words are never told."
        },
        "now": {
          "anyOf": [
            {
              "$ref": "#/$defs/ChangeNow"
            },
            {
              "type": "null"
            }
          ],
          "description": "What holds now in its place, when this key may read it; null: no longer true."
        },
        "ended_at": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Ended At",
          "description": "When it stopped being true."
        },
        "known_at": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Known At",
          "description": "When the store learned it."
        },
        "origin": {
          "type": "string",
          "enum": [
            "corrected",
            "forgotten",
            "stated",
            "read_from_memory"
          ],
          "title": "Origin",
          "description": "Where the change came from: a correction, a forget, a fact a caller wrote, or the store's reading of a memory. A label, never a score."
        },
        "source_memory_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Source Memory Id",
          "description": "With `read_from_memory`: the memory that closed it."
        },
        "by_agent": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "By Agent",
          "description": "The agent namespace of what closed it."
        }
      },
      "type": "object",
      "required": [
        "fact_id",
        "origin"
      ],
      "title": "Change",
      "description": "A fact this reader was handed and that has ended since (agent\nnotices)."
    },
    "ChangeNow": {
      "properties": {
        "fact_id": {
          "type": "string",
          "title": "Fact Id",
          "description": "The `fct_` id of the fact that holds now."
        },
        "text": {
          "type": "string",
          "title": "Text",
          "description": "It, as the block writes a fact."
        }
      },
      "type": "object",
      "required": [
        "fact_id",
        "text"
      ],
      "title": "ChangeNow"
    }
  }
}