have you tried the emacs package agent-shell?