Consistent mean field optimality conditions for interacting agent systems