4. Given $x \in \mathbf{R}$. Then the function
$$
f(x)=\max \left\{\sin x, \cos x, \frac{\sin x+\cos x}{\sqrt{2}}\right\}
$$

The sum of the maximum and minimum values is $\qquad$ .
4. $1-\frac{\sqrt{2}}{2}$.

Notice that
$$
\begin{array}{l}
f(x)=\max \left\{\sin x, \cos x, \frac{\sin x+\cos x}{\sqrt{2}}\right\} \\
=\max \left\{\sin x, \cos x, \sin \left(x+\frac{\pi}{4}\right)\right\},
\end{array}
$$

Obviously, the maximum value of $f(x)$ is 1. The minimum value of $\max \{\sin x, \cos x\}$ can be obtained by plotting the graphs of $y=\sin x$ and $y=\cos x$, which is $-\frac{\sqrt{2}}{2}$, reached at $x=\frac{5 \pi}{4}$. At $x=\frac{5 \pi}{4}$, the value of $\sin \left(x+\frac{\pi}{4}\right)$ is -1. Therefore, the minimum value of $f(x)$ is $-\frac{\sqrt{2}}{2}$.