Answer: He needed their service to find out the reason behind Hamlet's melancholy.
Step-by-step explanation:
Hamlet is extremely angry at his uncle, Claudius, because he murdered Hamlet's father. Hamlet thus decides to act as a mad man to take revenge on him.
Claudius has noticed 'a change' in Hamlet's behavior, but does not know the real reason behind it. In Act II, Scene II, Claudius and Gertrude welcome Rosencrantz and Guildenstern, Hamlet’s friends. Concerned about Hamlet's behavior after his father's death, the king hopes that Hamlet's friends will help him overcome this hard period, or at least find out the real reason behind his melancholy. Claudius invites them to spend some time at court with Hamlet and discover if there is any particular problem that he is facing. Rosencrantz and Guildenstern agree to help.