I feel like that's the way to go about it yeah, you'd need open communication, like a diplomacy team or something, but the other empire should be able to pass a message to you saying that they are becoming unhappy for some reason and give you a chance to do something about it, even if that something might be unreasonable.
I also think that those things shouldn't be exclusively based on stuff the player does, so changes in leadership or economic events in the NPR might also result in increased or decreased feelings towards the player.
Something like this could work. The main issue, for me, is that the AI should NOT just betray you randomly, or for small reasons. I also completely agree with what Father Tim wrote. Something like: "there's a 1% chance the AI will randomly betray you every year" is not acceptable, because it means the AI is just completely unreliable.
If we are told: "Look, relationships are souring. You should do something about it or prepare for the worst", that could instead be acceptable. Also acceptable is if the AI makes requests, either big or large. Because no matter how unreasonable they might be, at least you KNOW something is amiss and can prepare.
But unreliability and randomness make diplomacy useless instead. If I cannot reliably trust even allies with whom I trade regularly, I'm better off just killing/conquering every other race. It's a lot less risky.