Given $(g \circ f)(x) = \sin x$, this implies: \[ g(f(x)) = \sin x. \] Also, $(f \circ g)(x) = \left(\sin \sqrt{x}\right)^2$, which implies: \[ f(g(x)) = \left(\sin \sqrt{x}\right)^2. \] From $(g \circ f)(x) = \sin x$, let $f(x) = \sin^2 x$. Substituting into $g(f(x)) = \sin x$, we get: \[ g(\sin^2 x) = \sin x \implies g(x) = \sqrt{x}. \] Verify with $(f \circ g)(x)$: \[ f(g(x)) = f(\sqrt{x}) = \sin^2(\sqrt{x}). \] This matches the given condition. Hence, $f(x) = \sin^2 x$ and $g(x) = \sqrt{x}$.