2. Given $\alpha, \beta \in(0, \pi), \tan \alpha, \tan \beta$ are the two roots of the equation $x^{2}+3 x+1=0$, then the value of $\cos (\alpha-\beta)$ is
A. $\frac{1}{3}$
B. $\frac{2}{3}$
C. $\frac{\sqrt{5}}{3}$
D. $\frac{\sqrt{5}}{2}$
Suppose $\alpha>\beta$, from $\left\{\begin{array}{l}\tan \alpha+\tan \beta=-3, \\ \tan \alpha \tan \beta=1\end{array} \Rightarrow \tan \alpha-\tan \beta=\sqrt{5}\right.$
$\Rightarrow \tan (\alpha-\beta)=\frac{\sqrt{5}}{2} \Rightarrow \cos (\alpha-\beta)=\frac{2}{3}$, so the answer is $B$.