Usul al-Kafi
Book 5:
The Book of Belief and Disbelief

Chapter 3
The original covenant

612. 2. Imam Muhammad al-Baqir (p) said that God, the Almighty, the Glorious, drew forth the children of Prophet Adam (p) from his loins, to take the covenant of His Lordship and the prophethood of every prophet. First of all, the covenant of the prophethood of Prophet Muhammad (p) was taken.
Then God asked Prophet Adam (p): Tell me what you see?
Prophet Adam (p) looked at his descendants. He saw that the entire sky was filled with them like an ant-hill and he asked: O my Creator, I have so many descendants! Why have you created them? Is it your will to take a covenant from them?
God: I have created them so that they may worship Me and not ascribe partners to Me and to believe in My prophets and to obey them. …(B5,C3,T2)