4. Let $x_{1}, x_{2}, \cdots, x_{n}(n \geqslant 2)$ be non-negative real numbers, and $x_{1}+x_{2}+\cdots+x_{n}=1$, find the extremum of the function
$$
f\left(x_{1}, x_{2}, \cdots, x_{n}\right)=\sqrt{x_{1}^{2}+x_{1} x_{2}+x_{2}^{2}}+\sqrt{x_{2}^{2}+x_{2} x_{3}+x_{3}^{2}}+\cdots+\sqrt{x_{n}^{2}+x_{n} x_{1}+x_{1}^{2}}
$$
4. We have $x_{1}^{2}+x_{1} x_{2}+x_{2}^{2}=\frac{3}{4}\left(x_{1}+x_{2}\right)^{2}+\frac{1}{4}\left(x_{1}-x_{2}\right)^{2} \geqslant-\frac{3}{4}\left(x_{1}+x_{2}\right)^{2}$, and $x_{1}^{2}+x_{1} x_{2}+x_{2}^{2}=\left(x_{1}+\right.$ $\left.x_{2}\right)^{2}-x_{1} x_{2} \leqslant\left(x_{1}+x_{2}\right)^{2}$, thus
$\frac{\sqrt{3}}{2}\left(x_{1}+x_{2}\right) \leqslant \sqrt{x_{1}^{2}+x_{1} x_{2}+x_{2}^{2}} \leqslant x_{1}+x_{2}$, where the left equality holds if and only if $x_{1}=x_{2}$, and the right equality holds if and only if $x_{1} x_{2}$, one is 0.
Similarly, we have $\frac{\sqrt{3}}{2}\left(x_{i}+x_{i+1}\right) \leqslant \sqrt{x_{i}^{2}+x_{1} x_{i+1}+x_{i+1}^{2}} \leqslant x_{i}+x_{i+1}$, where $i=2,3, \cdots, n$, and $x_{n+1}=x_{1}$.
Adding up the above $n$ inequalities on both sides, we get $f\left(x_{1}, x_{2}, \cdots, x_{n}\right)$ satisfies $\sqrt{3} \leqslant f\left(x_{1}, x_{2}, \cdots, x_{n}\right) \leqslant 2$, where the left equality holds if and only if $x_{1}=x_{2}=\cdots=x_{n}=\frac{1}{n}$, and the right equality holds if and only if one of $x_{1}, x_{2}, \cdots, x_{n}$ is 1, and the rest are all 0, hence the maximum value of $f\left(x_{1}, x_{2}, \cdots, x_{4}\right)$ is 2, and the minimum value is $\sqrt{3}$.