Example 2 Find the range of the function $y=\frac{x^{2}-x+1}{x^{2}+x+1}$.
Solve the functional transformation to
$$
(y-1) x^{2}+(y+1) x+(y-1)=0
$$

When $y=1$, equation (2) is $2 x=0$, solving for $x$ gives $x=0$ within the domain of the function, $\therefore y=1$ is in the range of the function;

When $y \neq 1$, $\because x \in \mathbf{R}, \therefore \Delta=(y+1)^{2}-$ $4(y-1)^{2} \geqslant 0$, solving gives $\frac{1}{3} \leqslant y \leqslant 3$ and $y \neq 1$. In summary, the range of the original function is $\left[\frac{1}{3}, 3\right]$.