We show that in a stable first-order theory, the failure of higher dimensional type amalgamation can always be witnessed by algebraic structures that we call n-ary polygroupoids. This generalizes a result of Hrushovski in [16] that failures of 4-amalgamation are witnessed by definable groupoids (which correspond to 2-ary polygroupoids in our terminology). The n-ary polygroupoids are definable in a mild expansion of the language (adding a predicate for a Morley sequence).