4. Given that $x_{1}, x_{2}$ are the real roots of the equation $x^{2}-(k-2) x+\left(k^{2}+3 k+5\right)=0$ (where $k$ is a real number), then the maximum value of $x_{1}^{2}+x_{2}^{2}$ is $\qquad$ .
4. 18
$$
\Delta=(k-2)^{2}-4\left(k^{2}+3 k+5\right) \geqslant 0, k \in\left[-4,-\frac{4}{3}\right], 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)=-k^{2}-10 k-6=-(k+5)^{2}+19 \leqslant 18$, when $k=-4$, the equality holds.