On the Lagrangian structure of integrable hierarchies