3. Given the complex number $z$ satisfies
$$
\arg \left(z^{2}-z+2\right)=\arg \left(z^{2}+z\right)=\frac{\pi}{4} \text {. }
$$

Then $z=$ . $\qquad$
3. $2+\mathrm{i}$.

From the conditions, we can set
$$
\begin{array}{l}
z^{2}-z+2=r_{1}(1+\mathrm{i}), \\
z^{2}+z=r_{2}(1+\mathrm{i}),
\end{array}
$$

where $r_{1}, r_{2}>0$.
Adding and subtracting the two equations, we get
$$
\begin{array}{l}
z^{2}+1=\frac{r_{1}+r_{2}}{2}(1+\mathrm{i}), \\
z-1=\frac{r_{2}-r_{1}}{2}(1+\mathrm{i}).
\end{array}
$$

Substituting equation (2) into equation (1) and rearranging, we get
$$
2+\frac{\left(r_{2}-r_{1}\right)^{2}}{2} \mathrm{i}=\left(\frac{3}{2} r_{1}-\frac{1}{2} r_{2}\right)(1+\mathrm{i}).
$$

Comparing the real and imaginary parts, we get
$$
\frac{3}{2} r_{1}-\frac{1}{2} r_{2}=\frac{\left(r_{2}-r_{1}\right)^{2}}{2}=2.
$$

Solving, we get $r_{1}=3, r_{2}=5$ or $r_{1}=1, r_{2}=-1$ (discard).
Thus, $z=2+\mathrm{i}$.