you can store the last agent in a variable itself, you would most likely have to store it in an optional variable like this:
var MaybeLastAgent: ?agent = false
and then set it like this set MaybeLastAgent = option{Agent} each time it gets switched over.
You can access an optional variable like this if (LastAgent := MaybeLastAgent?): and then do stuff with LastAgent.