how to make AI take cover when they are underfire?

Or how to make AI take cover first when they spot enemy? It looks more realistic that AI takes cover first and then begin fire.