At the beginning of act 2, scene 2, Claudius welcomes Rosencrantz and Guildenstern to the Danish court. He asks them, as Hamlet's friends, to stay in Elsinore awhile and keep an eye on him, reporting back on any strange behavior that they might notice. Rosencrantz and Guildenstern accept this invitation, though I'm not sure if they could actually decline it if they wished to.
When they first reunite with Hamlet, the three friends share some lewd jokes, but when Hamlet asks them "What news?" things begin to go downhill. Though there must be some reason that these two friends have come to Denmark, never having visited Hamlet before nor having been invited by him, they tell him that they really have no news and nothing much is going on. This is Hamlet's first clue that Rosencrantz and Guildenstern have been sent for, and he asks them as much:
Were you not sent for? Is it your own inclining? Is it a free visitation? Come, come, deal justly with me. Come, come. Nay, speak.
He asks them for the truth and Guildenstern admits that he doesn't really know what to say. Hamlet correctly guesses that "the good king and queen have sent for [them]," but they don't tell him why. He explains that they were likely sent for because he's been out of sorts lately, not feeling like himself, but generally feeling like things are depressing and bad. Soon, the acting troop arrives and distracts him from the newly arrived friends.
Thus, in this act, Hamlet is already a bit suspicious of his friends; he works out fairly quickly that they've come at the behest of his uncle, but he seems pretty confident that they don't have the wits to keep anything from him for long. Later, he will grow a great deal more angry with them, and he will eventually plan for their murders, believing that they were in on the king's plan to murder him. For now, though, Hamlet doesn't seem terribly upset with them, but content to sort of keep an eye on them (while they keep one on him).