The ruler has a very important duty, diplomacy. A realm without allies will not last very long. A realm which abandons her allies, can sometimes gain great advantages, or the realm may be relegated to the dustbin of history. A wise ruler will choose carefully, for his own realm's gain.
There are two elements to Diplomacy: Diplomatic Relationships and Treaties.
Are mostly roleplaying elements and have no game-mechanics effects. They are described in detail in Enhanced Diplomacy. That does not mean they are any less important. On the contrary, since relationships can not store any additional information, treaties are what explains what exactly you mean and more importantly why you mean it.
Below are the Relations that realms can have to each other. These are the formal relations, there are many variations - there is solid peace and uneasy peace, there are alliances that only exist on paper and those that are put to the test every day.
All relations except hatred are reciprocal. If realm A is at war with realm B, then realm B is also at war with realm A.
The Federation is the highest of the realm relations. It is an even stronger bond than Alliance, similar to it in most respects, but stricter: Federations can not be broken "nicely". Anyone leaving a Federation will immediately be at war with all Federation members.
Alliance represents a close bond between realms. Allies will generally fight side by side in battle, and some of the buildings of the Allied realm are open to you, if you happen to be passing through their regions.
Peaceful relations have many advantages. Battles between peaceful realms are rare.
Neutrality is the equivalant of having no relations at all. Your troops will not fight, unless one of the troop leaders involved is being too aggressive.
A simple enough concept, if you are at war with someone, they are your enemies. Your soldiers will automatically attack them on sight, assuming that one of you does not manage to evade the other. Also, you must be at war with someone in order to loot her lands.
Over time, many rulers whip their citizens into a frenzy of hatred. While this has short term advantages, in that the peasants will be more tolerant, the main disadvantage is that it is very difficult to stop hating someone. Ending a hatred stance can cause morale and region control drops, realm-wide.
Only the ruler can change diplomatic relationships. To improve them, the rulers of both realms must agree. To lower them, however, requires only one side to act and the other will automatically follow. The only exception to this is when one realm drops to hatred to another. The other realm will not automatically follow suit.
Diplomacy and Battles
In many non-trivial situations, with 3 or more realms involved, diplomacy is slightly tricky to estimate and sometimes leads to surprises. If you want to avoid surprises during battles, make clear and obvious diplomacy settings your goal.
The general attitude is that the game code attempts to err on the side of caution. Rather then forcing you into a battle with a realm at peace because of some ally, it keeps you out of the battle to honour the peace agreement. The logic behind this is simple: An ally not joining in may turn the tides of a single battle, but a peace treaty broken is the more serious affair.
This is often a matter for discussion about how "bad the code is". It isn't. Any situation with more than 2 participants gets so complicated so quickly that there simply is no right way to resolve it. The game can not know how much your ruler "means" his peace treaty. It simply knows there is a peace treaty.
So once again: The game will always try hard to not break treaties. If that means not aiding an ally, then so be it, because that is the lesser offense. Failed support can be brought in later, but an unintended attack can not be undone.