Custom Call Status via AGI

I’ve created a custom destination that that fires off an AGI Script, this script updates a remote MySQL database with the phoneid which aids in real time customer identification. Each desktop at the user site runs a popup client that delivers Customer/Sales queries and call history. Between the 1st and 2nd ring of the phone. The current callerid system is being driven via RS232 by a 4 line Rollover serial calleridBox. I am trying to deliver the same info from Asteriisk.

My problem, after I run the Update AGI I then send the call to ring group777/everybody. It would be the cat’s pajamas if I could identify the extension that ultimately took the call, and whever it gets transfered etc. I need to be able to fire off another AGI when ever the call got handed off to a transfer or was hung up. At the very least I would like to update my remote MySQL when the call terminates.

Anyone have any ideas? I appreciate any clues, hints or feedback.