Here is my theory on the whole thing, after seeing the movie, there are definitely spoilers here so skip if if you havent seen the movie.
1.) The root of the whole story is that the sentient program called the oracle has compasion on the human race and no longer wishes the machine world to control the humans anymore and wishes an end to the war.
2.) Neo is the evolutionary leap to that of a machine/human hybrid.. he has all the qualities of being human, but his brain can work within the machine space of the matrix at an unbelieveable rate, as such, the implants within him let him subconciously tap into the matrix at will, he no longer needs to jack in, as he is in both worlds at the same time.
3.) Agent Smith is the opposite of Neo, when Neo infected and destroyed him, he imprinted his bad human qualities, along with the need to survive and dominate on Agent Smith.. thereby causing an evolutionary irrational jump in Agent Smiths programming.
4.) Because Smith is the opposite of Neo, the two are technically equal and not capable of killing one another.
5.) The architect and the Oracle were the two designers, or first inhabitants of the Matrix, per se. Knowning that humans go through mutations, the Architect and Oracle were put in place to try and identify a mutation that would be a threat to them and nip it in the bud, by rebuilding the matrix and breeding out the mutation which bought them time.
6.) The Merovingian and his gang are programs that malfunctioned and no longer care about the world, they only care about their own existance and the continuation of the matrix, as such, they work against the Oracle and Architect to make sure that the Matrix continues, but unknowingly, they are a test that the 'One' must go through to weed out inferior hybrids that may not be up to the task...
7.) In the end, the Merovingian hedges his bets and allows the little girl (a programatic child based on love and not control) to enter the matrix to be the rebuilding force should the matrix go into shutdown and need to be rebuilt. The little girl would reshape the matrix based on human qualities instead of control.. but to do this the Oracle knows that the systems of control must be removed.. and they only exist (the agents) to ferret out the humans from the real world in a continuation of their war.. the Oracle knows that in order for her plan to suceed there must be peace so she starts pointing Neo in the direction that she wants.
8.) being that she knows that Neo cannot kill agent smith on his own, she sacrifices herself and inserts herself into the equation by allowing Agent Smith to assimilate her.
9.) During the battle between the two at the end, Agent Smith expends so much effort in combating Neo that the Oracle inside him has a chance to reistablish control.. but that is not enough..
10.) Agent smith realizes that he cannot control the oracle within him for to much longer so he transfers his original self from the Oracle to Neo, and as such he can be killed in the real world by the head machine.. which is done.. By sacrificing himself, Neo assures the continuation of the Matrix and the destruction of Agent Smith.. and the result is peace.
I think thats the whole Jist of it, without throwing in all the other things that just cloud the issue.