Xenophon begins the work in the middle, first telling us about the Battle of Cunaxa. Then in Book III, when the Greek army discovers that its captains have been killed, he tells us, in third person, how he came to be involved in the matter:
There was a man in the army named Xenophon, an Athenian, who was neither general nor captain nor private, but had accompanied the expedition because Proxenus, an old friend of his, had sent him at his home an invitation to go with him; Proxenus had also promised him that, if he would go, he would make him a friend of Cyrus, whom he himself regarded, so he said, as worth more to him than was his native state. After reading Proxenus' letter Xenophon conferred with Socrates, the Athenian, about the proposed journey; and Socrates, suspecting that his becoming a friend of Cyrus might be a cause for accusation against Xenophon on the part of the Athenian government, for the reason that Cyrus was thought to have given the Lacedaemonians zealous aid in their war against Athens, advised Xenophon to go to Delphi and consult the god in regard to this journey. So Xenophon went and asked Apollo to what one of the gods he should sacrifice and pray in order best and most successfully to perform the journey which he had in mind and, after meeting with good fortune, to return home in safety; and Apollo in his response told him to what gods he must sacrifice. When Xenophon came back from Delphi, he reported the oracle to Socrates; and upon hearing about it Socrates found fault with him because he did not first put the question whether it were better for him to go or stay, but decided for himself that he was to go and then asked the god as to the best way of going. “However,” he added, “since you did put the question in that way, you must do all that the god directed.”
What Xenophon says was Socrates' worry turned out to be at least more or less accurate: the association with Cyrus the Younger probably did contribute to the Athenian banishment of him.
One of the things that is also clear is that Xenophon took Socrates' parting advice very seriously: not only did he do what the Oracle told him, he makes sacrifices and follows omens throughout the course of the expedition, up to the very end, and is scrupulous about following through. The practical importance of piety to the gods is quite prominent in all of Xenophon's works, and it seems very likely that this interaction is a significant influence on him in this regard.
This scene is the only one in which Socrates the philosopher appears in the Anabasis, but it sheds a light on everything else in the work.