Specification

{
  "title": "Message",
  "type": "object",
  "properties": {
    "metadata": {
      "default": null,
      "anyOf": [
        {
          "additionalProperties": {},
          "type": "object"
        },
        {"type": "null"}
      ],
      "title": "Metadata"
    },
    "role": {
      "title": "Role",
      "type": "string",
      "enum": [
        "user",
        "agent"
      ]
    },
    "parts": {
      "title": "Parts",
      "type": "array",
      "items": {"$ref": "#/$defs/Part"}
    }
  },
  "required": [
    "role",
    "parts"
  ]
}

Diagram