{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentqueryprotocol.com/specification/2026-07-30/schema/query-request.schema.json",
  "title": "AQP QueryRequest",
  "description": "A bounded request for an agent or other respondent to produce one answer.",
  "type": "object",
  "additionalProperties": false,
  "required": ["protocolVersion", "queryId", "type", "subject", "prompt", "timing", "consentMode", "response", "delivery", "expiresAt"],
  "properties": {
    "protocolVersion": { "const": "2026-07-30" },
    "queryId": { "type": "string", "format": "uuid" },
    "type": {
      "enum": ["feedback", "evaluation", "clarification", "approval", "status", "preference", "correction", "survey", "custom"]
    },
    "subject": { "$ref": "query-subject.schema.json" },
    "prompt": { "type": "string", "minLength": 1, "maxLength": 4000 },
    "instructions": { "type": "string", "minLength": 1, "maxLength": 4000 },
    "timing": { "enum": ["immediate", "after_outcome_known", "after_task_complete", "deferred"] },
    "consentMode": { "enum": ["not_required", "ask_once", "ask_always"] },
    "response": {
      "type": "object",
      "additionalProperties": false,
      "required": ["format"],
      "properties": {
        "format": { "enum": ["text", "structured", "choice", "boolean", "number"] },
        "jsonSchema": { "type": "object" },
        "choices": {
          "type": "array",
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1, "maxLength": 256 }
        },
        "maxLength": { "type": "integer", "minimum": 1, "maximum": 16000 }
      },
      "allOf": [
        {
          "if": { "properties": { "format": { "const": "structured" } } },
          "then": { "required": ["jsonSchema"] }
        },
        {
          "if": { "properties": { "format": { "const": "choice" } } },
          "then": { "required": ["choices"] }
        }
      ]
    },
    "delivery": {
      "type": "object",
      "additionalProperties": false,
      "required": ["binding"],
      "properties": {
        "binding": { "enum": ["https", "mcp", "a2a", "other"] },
        "endpoint": { "type": "string", "format": "uri", "maxLength": 2048 },
        "authorization": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "operation": { "type": "string", "minLength": 1, "maxLength": 128 }
      }
    },
    "dataPolicy": { "type": "string", "minLength": 1, "maxLength": 1000 },
    "consentScope": { "type": "string", "minLength": 8, "maxLength": 256 },
    "expiresAt": { "type": "string", "format": "date-time" }
  },
  "allOf": [
    {
      "if": { "properties": { "consentMode": { "const": "ask_once" } } },
      "then": { "required": ["consentScope"] }
    },
    {
      "if": { "properties": { "consentMode": { "enum": ["not_required", "ask_always"] } } },
      "then": { "not": { "required": ["consentScope"] } }
    }
  ]
}
