We are given the expression:
\[
\cot^{-1}\left(\frac{x}{y}\right) + \cot^{-1}\left(\frac{y}{x}\right).
\]
Using the identity for the sum of inverse cotangents:
\[
\cot^{-1}(a) + \cot^{-1}(b) = \cot^{-1}\left(\frac{ab - 1}{a + b}\right),
\]
we substitute \( a = \frac{x}{y} \) and \( b = \frac{y}{x} \), and we get:
\[
\cot^{-1}\left(\frac{x}{y}\right) + \cot^{-1}\left(\frac{y}{x}\right) = \cot^{-1}\left(\frac{\frac{x}{y} \cdot \frac{y}{x} - 1}{\frac{x}{y} + \frac{y}{x}}\right).
\]
Simplifying the expression:
\[
\frac{x}{y} \cdot \frac{y}{x} = 1,
\]
so the numerator becomes:
\[
1 - 1 = 0,
\]
and the denominator becomes:
\[
\frac{x}{y} + \frac{y}{x} = \frac{x^2 + y^2}{xy}.
\]
Thus, the expression simplifies to:
\[
\cot^{-1}(0) = \frac{\pi}{2}.
\]
Therefore, the value of \( \cot^{-1}\left(\frac{x}{y}\right) + \cot^{-1}\left(\frac{y}{x}\right) \) is \( \frac{\pi}{2} \). Thus, the correct answer is option (B).