[ai] enhance ai module

I did this for myself originally, don't know if is possible to be merged to the master branch for other people to use ;)