This is something I've given some thought to recently. I'm surprised that no CAD software (or at least none that I've used) has a, for lack of better terminology, "functionality markup." There's extensive infrastructure for mating parts in assemblies and validating designs with simulations, you'd think that someone could think up a good way of going in reverse, at least for common use cases. There should be a way to feed in some abstraction of the design requirements and get a design tree that meets those requirements. For example in the case of the hex head nut, there should be a way to describe a wrench as a combination of mates and simulated loads such that a CAD program can figure out that the flat-to-flat measurement on the nut is critical, and I should be able to open up a model of a nut and mark it up in such a way as to communicate "this gets turned by a wrench."
While probably useless for such a trivial case, one can easily imagine a case where multiple very different geometries might be appropriate for a task depending on the value of some other parameters, for example maybe I have a design with everything on one side to make machining easier, but the moment I have to add a feature to the other side it makes sense to switch a bunch of those features to the other side as well.