4. Let $a$ be a positive number. Then the function
$$
f(x)=a \sin x+\sqrt{a} \cos x\left(-\frac{\pi}{2} \leqslant x \leqslant \frac{\pi}{2}\right)
$$

the sum of the maximum and minimum values $g(a)(a>0)$ is in the range $\qquad$ .
4. $\left(0, \frac{1}{2}\right)$.

First, we have
$$
f(x)=\sqrt{a^{2}+a} \sin (x+\varphi)\left(-\frac{\pi}{2} \leqslant x \leqslant \frac{\pi}{2}\right) .
$$

where, $\varphi=\arcsin \frac{\sqrt{a}}{\sqrt{a^{2}+a}}=\arcsin \frac{1}{\sqrt{a+1}}$.
At this point, we have
$$
\begin{array}{l}
-\frac{\pi}{2}+\arcsin \frac{1}{\sqrt{a+1}} \leqslant x+\varphi \\
\leqslant \frac{\pi}{2}+\arcsin \frac{1}{\sqrt{a+1}} .
\end{array}
$$

When $x=\frac{\pi}{2}-\varphi=\frac{\pi}{2}-\arcsin \frac{1}{\sqrt{a+1}}\left(x \in\left[-\frac{\pi}{2}, \frac{\pi}{2}\right]\right)$,
$f(x)$ reaches its maximum value of $\sqrt{a^{2}+a}$.
To find the minimum value of $f(x)$, we only need to consider $x+\varphi0 \text { ). }
\end{array}
$$

Therefore, the range of $g(a)$ is $\left(0, \frac{1}{2}\right)$.