Sorry, I don’t know enough to give a really good answer, but the AI can do troop buildups in preparation for war, it can do a buildup if it thinks you will attack. It will also sometimes be caught by surprise, that’s one disadvantage of event-driven diplomacy. Maybe you get an event that makes Babylon declare war, except the Babylonian AI wasn’t prepared for that.
The AI will be ruthless and try to prevent you from winning. The AI will get increasingly more likely as you get close to a victory (VPs or Ambitions count), it will refuse trades, and it will not accept a truce.
Here’s how the AI war calculation goes, roughly.
Base chance is from the opinion level - Furious/Angry/Upset/Cautious/Pleased is 50/30/20/10/5. Then proximity and strength modifiers apply. For example, proximity of Distant is -40, and relative strength of Stronger is 25. Then Peace diplomatic status applies another -20.
So, if an AI is Angry with you, is Stronger but Distant, so far we have 30 * 0.6 * 1.25 = 22.5% chance of war.
Then the AI’s leader personality factors in, military archetypes (Hero, Commander, Tactician, Zealot) apply +50%, while the peaceful Judge, Builder or Scholar apply -25%. So if the abovementioned AI with 22.5% chance has a Hero leader, we’re up to 33.75%.
This is where the AI aggression from difficulty factors in, adding more.
All of that interacts with Play to Win, for instance if you’re on 9/10 Ambitions then a whopping 40% applies.