Can you please explain what it is in this game? What can of diplomatic actions are needed for winning in higher levels?
Realize 1 thing.
The AI wants to win.
This means that the best way for you to avoid war is to make it so that it wouldn't be worth it for an AI to declare war on you.
If you are militarily weak, you want to sign pacts of co-operation (and follow them... go to war with them, trade with them, research agreements and so forth), pacts of secrecy against certain opponents (and keep them... don't trade with them, don't open borders, etc), provide gifts of gold, maybe give them your excess luxuries... If you do this, you provide them incentive to stay at peace with you. You see this? They realize that declaring a war on you would lose them those gifts and resources.
If you lack gold and resources, you want to guard your borders... make them think that it will not be worth attacking you.
They do remember past actions... but it is not so cut and dry as a permanent +1 for "You provide us with resources". It is more like "They are supplying us with Ivory, which is awesome, and I could get it by settling over there, or invading him... but it probably isn't worth it, so I will stay friends with him until my research agreement is up, then see how things are going." At least this is how they say it should work and how I have seen it. It is certainly possible that the diplomacy could be completely random, but that seems quite farfetched and unlikely.
If they see you are likely to win diplomacy, they will try to disrupt that by taking out city states. That is a big behavior I have noticed.