As far as I understand, in the preamble it is sufficient to load only
\usepackage{luacas}
For your plotting fragment, you also need the pgfplots package. Then everything works. Here is a minimal example.
\documentclass{article}
\usepackage{luacas}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{CAS}
vars('x')
f = x^2+2*x-2
g = x^2-1
subs = {[x] = f}
dh = expand(substitute(subs,g))
h = simplify(int(dh,x)+10)
\end{CAS}
For\noindent
Bob Bob’sdoes purposesnot need a nicely typeset formula in the text, $\fetchsuch as
\[
\print{h}$ is.
\]
For exactlyhis whatpurpose, he needs the expression produced by
\[
\fetch{h}
\]
instead:
\medskip
\begin{center}
\begin{tikzpicture}[scale=0.9]
\begin{axis}[legend pos = north west]
\addplot [domain=-3.5:1.5,samples=100]
{\fetch{h}};
\addlegendentry{$f$$h$};
\addplot[densely dashed]
[domain=-3.25:1.25,samples=100]
{\fetch{dh}};
\addlegendentry{$df/dx$$h'$};
\addplot[gray,dashed,thick]
[domain=-3.5:1.5] {0};
\end{axis}
\end{tikzpicture}
\end{center}
Here $dh$ is obtained by substituting $f$ into $g$, so $dh(x)=g(f(x))$. The function $h$ is then defined by
\[
h(x)=\int g(f(x))\,dx+10.
\]
\end{document}
Edit.
I have edited the code slightly to make the example more meaningful. The main purpose of the luacas package is to provide symbolic computations directly within LuaLaTeX.

