Functional Keldysh theory of spin torques