It looks as though something might be going wrong in the AGI script itself.
Did you use a “proper” AGI library, or a quick-and-dirty homebrew solution?
(There is little virtue in walking all the way to the tool shed to fetch a chisel, if you know the screwdriver you already have in your drawer can be used for the job. On the other hand, breaking your screwdriver by inappropriately using it as a chisel does not look too good either. Knowing the difference is one of the qualities of a great programmer.)
SET VARIABLE is a legitimate enough command, but ****** probably is not a valid variable name. Maybe there was a forbidden character in there before you redacted it?
I would try to isolate the problem, by writing an AGI script that *just* sets a variable to some fixed value and exits; and having a corresponding extension that *just* calls the AGI script, displays the variable’s value in the CLI
with a NoOp() statement and then hangs up. When you know you can do that, and successfully read back the value from within your dialplan, *then* you can make it decide what value to put in that variable.