Example 13 Given that $x_{1}, x_{2}$ are the two real roots of the equation $x^{2}-(k-2) x + (k^{2}+3 k+5)=0$ (where $k$ is a real number). Then the maximum value of $x_{1}^{2}+x_{2}^{2}$ is $\qquad$
According to Vieta's formulas, we have
$$
\begin{array}{l}
x_{1}+x_{2}=k-2, \quad x_{1} x_{2}=k^{2}+3 k+5 . \\
\therefore \quad x_{1}^{2}+x_{2}^{2}=\left(x_{1}+x_{2}\right)^{2}-2 x_{1} x_{2} \\
=(k-2)^{2}-2\left(k^{2}+3 k+5\right) \\
=9-\left(k+5\right)^{2} .
\end{array}
$$

From the discriminant theorem, we get
$$
\begin{aligned}
\Delta & =(k-2)^{2}-4\left(k^{2}+3 k+5\right) \\
& =-3 k^{2}-16 k-16 \geqslant 0 .
\end{aligned}
$$

Solving this, we get $-4 \leqslant k \leqslant-\frac{4}{3}$.
Therefore, when $k=-4$, $x_{1}^{2}+x_{2}^{2}$ has a maximum value of
18.