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}$
2. B.
From the given information, we have
$$
\tan \alpha + \tan \beta = -3, \tan \alpha \cdot \tan \beta = 1 \text{.}
$$

Thus, $\tan \alpha$ and $\tan \beta$ are both less than 0.
Assume $\alpha \geqslant \beta$. Then $\pi > \alpha \geqslant \beta > \frac{\pi}{2}$.
Therefore, $\tan \alpha \geqslant \tan \beta, 0 \leqslant \alpha - \beta < \frac{\pi}{2}$.
$$
\begin{array}{l}
\text{From } (\tan \alpha - \tan \beta)^2 \\
= (\tan \alpha + \tan \beta)^2 - 4 \tan \alpha \cdot \tan \beta \\
= 5 \\
\Rightarrow \tan \alpha - \tan \beta = \sqrt{5}.
\end{array}
$$

Thus, $\tan (\alpha - \beta) = \frac{\tan \alpha - \tan \beta}{1 + \tan \alpha \cdot \tan \beta} = \frac{\sqrt{5}}{2}$
$$
\Rightarrow \cos (\alpha - \beta) = \frac{1}{\sqrt{1 + \tan^2 (\alpha - \beta)}} = \frac{2}{3}.
$$