We show that in a stable first-order theory, the failure of higher-dimensional type amalgamation can always be witnessed by algebraic structures we call n-ary polygroupoids. This generalizes a result of Hrushovski in [15] 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).Definition 1.1. An n-amalgamation problem is a functor A : P − ([n]) → C. A solution to an n-amalgamation problem A is a functor A ′ : P([n]) → C that extends A.We say that A is an amalgamation problem over the set A(∅) (which is also called the "base set").Definition 1.2. If S is a subset of [n] closed under subsets and A : S → C is a functor, then for s ⊆ t ∈ S, let the transition mapbe the image of the inclusion s ⊆ t. Functoriality implies that A t,u • A s,t = A s,u whenever the composition is defined.