We all know too well that The AI like to declare war...just because...without any sensible reasons...against much more powerful foe...
...Then they got beaten up...But They Still Refuse To Surrender!
TW needs a better AI: AI That Knows Its Losing The War.
When The AI's Armies were Defeated in the Field, The AI have 2 choice: Keep Fighting or Seek Peace.
In That Situation, They should fight a war or Attrition though guerilla warfare: Small Raiding Armies that cuts supply lines and do Hit-and-run attacks.
In Battles, the BAI still do not understand that it could retreat from battle without casualties, to fight another day. If all the soldiers died attacking the wall, The General dont scale the walls! They should retreat!
Ambushes, if the hit does not break the ranks, The BAI should be able to slow down the pursuers, so the rest of the rank could escape.
The AI only would not try too seek peace if the Enemy wage a war of annihilation: Decimating Cities, Mass Prisoner Crucifictions, or Burn-Pillage-Rape. In Only That Case, it is understandable that they would fight to the bitter end.
A reasonless, losing war without any justification should trigger instability in the faction. A Coup shall ensues.
This may sums it up, and add some nonsensibility to this thread: