Didn't have time to play it yet, but took a look at the AI.
2 things, first: Make your AI less random-number dependend. I'd suggest you replace every random-number suggestion with something else.
Second: Make your farm building more "(idle-farm-count < X)" dependend and less "just build until we have 40".
Some farm building rules also don't have real conditions anyway, in the feudal age are some cases where you just mass farms - the AI could possibly even build more farms than you have villagers. If you really want a lot of farms then at least put a high max number in there (your AI trains 100 vills at max -> let's say your food gatherer percentage is 50 in the imperial age -> build 50 farms max ).