Hamlet decides to seek revenge after seeing his father's ghost. This happens in Act I, Scene 5 of the play.
When Hamlet sees his father's ghost, the ghost talks to him. It tells him about how it was murdered. The ghost tells Hamlet that it was Claudius who killed Hamlet's father. The ghost also tells Hamlet that he needs to seek revenge.
After the ghost tells him this, Hamlet agrees with it and says that he will, indeed, seek revenge.
Ay, thou poor ghost, while memory holds a seat
In this distracted globe. Remember thee!
Yea, from the table of my memory
I'll wipe away all trivial fond records,
All saws of books, all forms, all pressures past,
That youth and observation copied there;
And thy commandment all alone shall live
Within the book and volume of my brain,
Unmix'd with baser matter: yes, by heaven!
To me, when he mentions the ghost's commandment, he is talking about how the ghost told him to get revenge.
So, I would argue that he is seeking revenge out of duty to his father. This makes sense because he swears to do it after his father's ghost tells him who commited the murder.
While Hamlet initially feels that he will revenge his father's death in Act I, he does not act impulsively. Realizing that regicide is a serious offense--"And shall I couple hell?" (I,v,92)--Hamlet begins to hesitate:
This time is out of joint. O cursed spite/That ever I was born to set it right! (I,v,187-188).
This hesitation continues through several soliloquies in the play as given to abstraction, "a dream itself is but a shadow" (II,ii,249),
Why then 'tis none to you; for there is nothing either good or bad, but thinking makes it so. To me it [Denmark] is a prison. (II,ii, 241-242)
and philosophical debates with himself "What a piece of work is man...." and "To be or not to be...."). From this long self-examination and debate upon existential questions, Hamlet finally emerges from his self-reproach in Act IV, Scene 4 when, after considering his own delay in contrast to the willingness of Fortinbras and the Polish armies to fight for little more than honor:
....Rightly to be great/Is not to stir without great argument,/But greatly to find quarrel in a straw/When honor's at the stake. How stand I then,/That have a father killed, a mother stained....O, from this time forth,? My thoughts be bloody, or be nothing worth!(IV,iv, 53-66)
The change in Hamlet's character occurs in Act V, Scene 1 when he asserts himself as "Hamlet the Dane" (V,i,227). Rather than in the final scene, it is in the graveyard scene in which a new Hamlet emerges, one ready for action: "the cat will mew, and dog will have his day"(V,i,264).
A deep and complex character given to much melancholic brooding and self-debate, Hamlet is all the more intriguing because he does not so quickly act upon his promise to his father's ghost because Denmark "is rotten" and the corruption in the court must be eradicated.