4. In an isosceles right $\triangle ABC$, $\angle A=90^{\circ}, AB=$ $1, D$ is the midpoint of $BC$, $E$ and $F$ are two other points on $BC$, $M$ is the other intersection point of the circumcircle of $\triangle ADE$ and the circumcircle of $\triangle ABF$, $N$ is the other intersection point of line $AF$ and the circumcircle of $\triangle ACE$, $P$ is the other intersection point of line $AD$ and the circumcircle of $\triangle AMN$. Find the length of $AP$.
Given: With point $A$ as the inversion center and $r=1$ as the radius of the inversion circle. Denote the image of point $X$ as $X^{*}$. Then
points $B, F, D, E, C$ are collinear
$\Leftrightarrow$ points $A, B^{*}, F^{*}, D^{*}, E^{*}, C^{*}$ lie on the same circle, $M$ is one of the intersection points of the circumcircle of $\triangle ADE$ and the circumcircle of $\triangle ABF$ $\Leftrightarrow D^{*}E^{*}$ intersects $B^{*}F^{*}$ at point $M^{*}$,
$AF$ intersects the circumcircle of $\triangle ACE$ at another point $N \Leftrightarrow$ $AF^{*}$ intersects $C^{*}E^{*}$ at point $N^{*}$,
$AD$ intersects the circumcircle of $\triangle AMN$ at another point $P \Leftrightarrow$ $AD^{*}$ intersects $M^{*}N^{*}$ at point $P^{*}$.
Let $B^{*}C^{*}$ intersect $AD^{*}$ at point $O^{*}$.
Applying Pascal's theorem to the cyclic hexagon $AF^{*}B^{*}C^{*}E^{*}D^{*}$, we know that the intersections of the three pairs of opposite sides $AF^{*}$ and $C^{*}E^{*}$, $F^{*}B^{*}$ and $D^{*}E^{*}$, $B^{*}C^{*}$ and $AD^{*}$, namely $M^{*}, N^{*}, O^{*}$, are collinear.

Since $P^{*}$ is the intersection of $M^{*}N^{*}$ and $AD^{*}$, then $P^{*} = O^{*}$, i.e., point $P^{*}$ lies on the line $B^{*}C^{*}$.
By the properties of inversion, we can derive
$A, B, P, C$ are concyclic
$\Rightarrow AD \cdot DP = BD \cdot DC$
$\Rightarrow AD = BD = DC = DP = \frac{\sqrt{2}}{2}$.
Thus, $AP = \sqrt{2}$.