Integrability of the string worldsheet theory in AdS5×S5 is related to the existence of a flat connection depending on the spectral parameter. The transfer matrix is the open-ended Wilson line of this flat connection. We study the product of transfer matrices in the near-flat space expansion of the AdS5×S5 string theory in the pure spinor formalism. The natural operations on Wilson lines with insertions are described in terms of r- and s-matrices satisfying a generalized classical Yang–Baxter equation. The formalism is especially transparent for infinite or closed Wilson lines with simple gauge invariant insertions.