The AI's not erratic in diplomacy. They are, however, playing to win. Just because the somewhat like you, doesn't mean they won't attack if they perceive you as a threat, or as being weak.
In my current marathon game, I'm the Romans. I'm friendly with Catherine, after saving her empire from Ghandi's warmongering, and Ottoman, despite sharing a game-long border with him. They're great trading partners, allowing me to sell my excess strategic and luxury resources.
Ghandi's the second most powerful civ. He DoW'd me after absorbing two other civs (Japan, who itself had absorbed the Babylonians, and the Songhai, who I took half of), as he had a larger, though less advanced, military than I. Since I destroyed his army, and took several of his cities...he's been quiet as a lamb (though now that he's got infantry...I worry).
The English were somewhat friendly, but they DoW'd on Catherine while I was saving her from Ghandi, so I retaliated. At one time Sulieman, Elizabeth, and Catherine made great trading partners, but now it's just the Sulieman and Catherine.
Other civs: Montezuma rampaged, taking out most've the Chinese before I backdoored them and took his capital (and only non-puppet city). Ramses DoW'd early on, and lost for it, as he was my neighbor. The Chinese got mostly wiped by the Aztecs, then finished off by myself and Sulieman. The Japanese were wiped by Ghandi, after they had in turn wiped out the Babylonians.
I have noticed the AI likes to gang up on the perceived weakest/least-liked civ: I think most've the civs ganged up on poor Noba, due to his warmongering ways. I had figured he was a powerful civ, so had worked on improving relations with him (he was on the opposite side of the continent on Terra map, so I figured it was safe). Sucked that he got wiped!