Two possible definitions of composition of morphisms of ringed spaces. Are they equivalent? I'm trying to understand the definition of composition of morphisms of ringed spaces. I know there are several posts on MSE addressing this issue. But the specific issue I am going to discuss in the following isn't even mentioned of any of the posts I've looked at.
Given ringed spaces $(X,\mathcal{O}_X)$ and $(Y,\mathcal{O}_Y)$, a morphism between them $(f,\psi^{\sharp}):(X,\mathcal{O}_X)\to(Y,\mathcal{O}_Y)$ is defined to be a pair $(f,\psi^{\sharp})$, where $f:X\to Y$ is a continuous map of topological spaces and $\psi^{\sharp}:f^{-1}\mathcal{O}_Y\to\mathcal{O}_X$ is a morphism of sheaves over $X$ (i.e., $\psi^{\sharp}:f^{-1}\mathcal{O}_Y\to\mathcal{O}_X$ lives in the category $\mathsf{Sh}_{\mathsf{Ring}}(X)$ of ring-valued sheaves over $X$), and where $f^{-1}\mathcal{O}_Y$ is the pullback of the sheaf $\mathcal{O}_Y$ on $Y$ along $f$, i.e., it is the sheafification of the presheaf $f_p\mathcal{O}_Y$ on $X$, where $f_p$ is defined here on the Stacks Project. The data $(f,\psi^{\sharp})$ is equivalent to the data $(f,\psi^\flat)$, where $\psi^{\flat}:\mathcal{O}_Y\to f_*\mathcal{O}_X$ lives in $\mathsf{Sh}_{\mathsf{Ring}}(Y)$. Here the morphisms $\psi^\sharp$ and $\psi^\flat$ are adjoint morphisms related by the adjunction of hom-sets
$$
\mathsf{Sh}_{\mathsf{Ring}}(X)(f^{-1}\mathcal{O}_Y,\mathcal{O}_X)\cong\mathsf{Sh}_{\mathsf{Ring}}(Y)(\mathcal{O}_Y, f_*\mathcal{O}_X).
$$
Now, considering the two different forms in which what can give a morphism of ringed spaces (in the form $(f,\psi^\sharp)$ or $(f,\psi^\flat)$), there are two different ways in which one can define the composition of morphisms of ringed spaces. Namely, if
$$
(g,\varphi^\sharp)\text{ or }(g,\varphi^\flat):(Y,\mathcal{O}_Y)\to(Z,\mathcal{O}_Z)
$$
is another morphism of ringed spaces, we can define
$$
\begin{align}
(g,\varphi^\sharp)\circ(f,\psi^\sharp)&=(g\circ f,\psi^\sharp\circ f^{-1}\varphi^\sharp)\\
(g,\varphi^\flat)\circ(f,\psi^\flat)&=(g\circ f,g_*\psi^\flat\circ \varphi^\flat),
\end{align}
$$
where $f^{-1}$ denotes the pullback functor $f^{-1}:\mathsf{Sh}_{\mathsf{Ring}}(Y)\to\mathsf{Sh}_{\mathsf{Ring}}(X)$ along $f$ and $g_*$ is the pushforward functor $g_*:\mathsf{Sh}_{\mathsf{Ring}}(Y)\to\mathsf{Sh}_{\mathsf{Ring}}(Z)$ along $g$. If one writes down the morphisms $\psi^\sharp$ and $\varphi^\sharp$ and tries to find some way to “compose them,” he/she will verify that this definition is the natural one. And analogously for $\psi^\flat$ and $\varphi^\flat$.
The next step would be showing that these two possible definitions of composition of morphisms are equivalent. This means, we should show that the morphism $\psi^\sharp\circ f^{-1}\varphi^\sharp$ of sheaves on $X$ and the morphism $g_*\psi^\flat\circ \varphi^\flat$ of sheaves on $Y$ are adjoint under the hom-set adjunction
$$
\mathsf{Sh}_{\mathsf{Ring}}(X)((g\circ f)^{-1}\mathcal{O}_Z,\mathcal{O}_X)\cong\mathsf{Sh}_{\mathsf{Ring}}(Z)(\mathcal{O}_Z, (g\circ f)_*\mathcal{O}_X).
$$
(Where $(g\circ f)_*=g_*\circ f_*$ and $(g\circ f)^{-1}=f^{-1}\circ g^{-1}$ as functors.)
My problem is that I don't know how to prove it. For what this MSE post says, there are really not a lot places to learn about the issue of composing morphisms of ringed spaces. The only place I've found that mentions the exact issue I'm asking about is EGA 0, 3.5.5 (here a version in English):

The critical expression in which it is proven the fact about I'm asking for is squared in red. The thing is that I don't understand where the “then we have immediately that $w^\sharp$ is the composite morphism” comes from.
Some notes on what is Grothendieck considering there: Instead of ringed spaces, he considers general “sheafed spaces” and morphisms of “sheafed spaces,” which are just a generalization to the case of ringed spaces. A “sheafed space” is a pair $(X,\mathscr{F})$, where $X$ is a topological space and $\mathscr{F}$ is a sheaf on $X$ valued on some category $\mathsf{C}$, and the definition of a morphism between sheafed spaces is, mutatis mutandis, the same as the definition we have wrote here for ringed spaces. The category of “sheafed spaces” is also addressed in EGA 0, 3.5.2.
 A: In the adjunction isomorphism $\operatorname{Hom}(f^{-1} {-}, {-}) \simeq \operatorname{Hom}({-}, f_* {-})$, apply naturality to the morphism $(\varphi^{\sharp}, \operatorname{id}_{\mathcal{O}_X})$ and the fact that $\psi^\sharp \mapsto \psi^\flat$ to get that $\psi^\sharp \circ f^{-1} \varphi^\sharp \mapsto \psi^\flat \circ \varphi^\sharp$.  Likewise, in the adjunction isomorphism $\operatorname{Hom}(g^{-1} {-}, {-}) \simeq \operatorname{Hom}({-}, g_* {-})$, apply naturality to the morphism $(\operatorname{id}_{\mathcal{O}_Z}, \psi^\flat)$ and the fact that $\varphi^\sharp \mapsto \varphi^\flat$ to see that $\psi^\flat \circ \varphi^\sharp \mapsto g_* \psi^\flat \circ \varphi^\flat$.
It now remains to verify that the adjunction $\operatorname{Hom}((g\circ f)^{-1} {-}, {-}) \simeq \operatorname{Hom}({-}, (g\circ f)_* {-})$ agrees exactly with the composition of the adjunctions for $g$ and $f$, i.e. that it is equal to the composition $$\operatorname{Hom}((g\circ f)^{-1} {-}, {-}) \simeq \operatorname{Hom}(f^{-1} g^{-1} {-}, {-}) \simeq \operatorname{Hom}(g^{-1} {-}, f_* {-}) \simeq \\
\operatorname{Hom}({-}, g_* f_* {-}) \simeq \operatorname{Hom}({-}, (g\circ f)_* {-}).$$
However, on deeper inspection, recall that most likely, the way we defined the canonical isomorphism $(g\circ f)^{-1} \mathcal{F} \simeq f^{-1} g^{-1} \mathcal{F}$ is very closely related to applying the Yoneda lemma to the isomorphism of functors
$$\operatorname{Hom}((g\circ f)^{-1} \mathcal{F}, {-}) \simeq \operatorname{Hom}(\mathcal{F}, (g\circ f)_* {-}) \simeq \operatorname{Hom}(\mathcal{F}, g_* f_* {-}) \simeq \\
\operatorname{Hom}(g^{-1} \mathcal{F}, f_* {-}) \simeq \operatorname{Hom}(f^{-1} g^{-1} \mathcal{F}, {-}).$$
So in a sense, the actual situation is inverted from the desired statement: we chose the canonical isomorphism $(g\circ f)^{-1} \simeq f^{-1} \circ g^{-1}$ exactly in such a way that the adjunction between $(g\circ f)^{-1}$ and $(g\circ f)_*$ would agree with the composition of the adjunctions between $g^{-1}$ and $g_*$, respectively $f^{-1}$ and $f_*$.
