4. Given the hyperbola $\frac{x^{2}}{a^{2}}-\frac{y^{2}}{b^{2}}=1(a, b>0)$ with its two foci at $A(-1,0), B(1,0)$, a line $l$ passing through point $B$ intersects the right branch of the hyperbola at points $M$ and $N$, and $\triangle A M N$ is an isosceles right triangle with $N$ as the right-angle vertex. Then the length of the real axis of the hyperbola is $\qquad$
4. $\frac{2 \sqrt{85+34 \sqrt{2}}}{17}$.

By the definition of a hyperbola, we have
$$
\begin{array}{l}
|A M|-|B M|=2 a, \\
|A N|-|B N|=2 a .
\end{array}
$$

From the given conditions, we get
$$
|A M|=\sqrt{2}|A N|=\sqrt{2}|M N|=\sqrt{2}(|B M|+|B N|) \text {. }
$$

Combining equations (1) and (2), we get
$$
|A M|=4 a,|B M|=2 a \text {. }
$$

In $\triangle A M B$, by the cosine rule, we have
$$
\begin{array}{l}
|A B|^{2}=|A M|^{2}+|M B|^{2}-2|A M||M B| \cos 45^{\circ} \\
\Rightarrow 4=16 a^{2}+4 a^{2}-8 \sqrt{2} a^{2} \\
\Rightarrow a^{2}=\frac{1}{5-2 \sqrt{2}}=\frac{5+2 \sqrt{2}}{17} \\
\Rightarrow 2 a=\frac{2 \sqrt{85+34 \sqrt{2}}}{17} .
\end{array}
$$