{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://protokol.cloud/schemas/workforce-result-schema.json",
  "title": "Workforce result schema",
  "description": "The shape of the data an end step of a playbook returns. Write it as a JSON Schema using only the keywords below: type, properties, required, items, enum, description and additionalProperties. Anything else (format, minimum, pattern, oneOf, $ref, nullable, a type written as a list) is refused. The top level is always an object with at least one property. At most 5 levels deep and 8 KB in size. Give every field a description: the agent reads it to know what to write.",
  "examples": [
    {
      "type": "object",
      "required": ["summary", "risk", "checks"],
      "properties": {
        "summary": {"type": "string", "description": "Two sentences about the project"},
        "risk": {"type": "string", "enum": ["low", "medium", "high"], "description": "Overall risk"},
        "checks": {
          "type": "array",
          "description": "Checks you made",
          "items": {
            "type": "object",
            "required": ["name", "passed"],
            "properties": {
              "name": {"type": "string", "description": "What was checked"},
              "passed": {"type": "boolean", "description": "Whether it passed"}
            }
          }
        }
      }
    }
  ],
  "$ref": "#/$defs/node",
  "required": ["type", "properties"],
  "properties": {
    "type": {"const": "object"},
    "properties": {"minProperties": 1}
  },
  "$defs": {
    "node": {
      "description": "One field of the result (or the whole result, at the top). It is a schema with a type and, as the type needs, properties, items or enum.",
      "type": "object",
      "additionalProperties": false,
      "required": ["type"],
      "properties": {
        "type": {
          "description": "What kind of value this is. One word, never a list: object (named fields, use properties), array (a list, use items), string (text), number (any number), integer (whole numbers only), boolean (true or false). There is no null and no date: use a string for a date, written the way the description says.",
          "enum": ["object", "array", "string", "number", "integer", "boolean"]
        },
        "description": {
          "description": "What the agent should put in this field, in plain words. Up to 500 characters. Always worth writing: it is the instruction the agent follows.",
          "type": "string",
          "maxLength": 500
        },
        "properties": {
          "description": "Only on an object. The named fields it holds, each a schema of its own. A field name is 1 to 64 letters, digits, _ or -, and starts with a letter (no dots, spaces or brackets). The top level needs at least one.",
          "type": "object",
          "propertyNames": {"pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"},
          "additionalProperties": {"$ref": "#/$defs/node"}
        },
        "required": {
          "description": "Only on an object. The names of the fields that must always be present. Each name must appear in properties and be listed once. Fields not listed here may be left out.",
          "type": "array",
          "uniqueItems": true,
          "items": {"type": "string"}
        },
        "items": {
          "description": "Only on an array, and an array must have it. The schema every element of the list follows.",
          "$ref": "#/$defs/node"
        },
        "enum": {
          "description": "Only on a string, number or integer. The complete list of values the field may take. Not empty, no repeats, and every value of the field's own type (text for string, numbers for number, whole numbers for integer).",
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {"type": ["string", "number"]}
        },
        "additionalProperties": {
          "description": "Only meaningful on an object. false means the agent may not add fields that are not in properties; true (the default) allows them.",
          "type": "boolean"
        }
      },
      "allOf": [
        {
          "if": {"required": ["type"], "properties": {"type": {"const": "object"}}},
          "else": {"not": {"anyOf": [{"required": ["properties"]}, {"required": ["required"]}]}}
        },
        {
          "if": {"required": ["type"], "properties": {"type": {"const": "array"}}},
          "then": {"required": ["items"]},
          "else": {"not": {"required": ["items"]}}
        },
        {
          "if": {"required": ["type"], "properties": {"type": {"enum": ["string", "number", "integer"]}}},
          "else": {"not": {"required": ["enum"]}}
        },
        {
          "if": {"required": ["type", "enum"], "properties": {"type": {"const": "string"}}},
          "then": {"properties": {"enum": {"items": {"type": "string"}}}}
        },
        {
          "if": {"required": ["type", "enum"], "properties": {"type": {"const": "number"}}},
          "then": {"properties": {"enum": {"items": {"type": "number"}}}}
        },
        {
          "if": {"required": ["type", "enum"], "properties": {"type": {"const": "integer"}}},
          "then": {"properties": {"enum": {"items": {"type": "integer"}}}}
        }
      ]
    }
  }
}
