Rabbi Yehoshua of Sikhnin in the name of Rabbi Shmuel said: He took counsel with the souls of the righteous. This is what is written: "These were the potters, and those that dwelt among plantings and hedges; there they dwelt with the king in his work" (1 Chronicles 4:23). "These were the potters," on account of "And the LORD God formed man of the dust of the ground" (Genesis 2:7). "Those that dwelt among plantings," on account of "And the LORD God planted a garden in Eden in the east" (Genesis 2:8). "And hedges," on account of "who have placed the sand as a boundary for the sea" (Jeremiah 5:22). "They dwelt with the king in his work," with the King, the King of kings of kings, the Holy One, blessed be He, dwelt the souls of the righteous, those with whom the Holy One, blessed be He, took counsel and created the world.
The Heavenly Court
Bereshit Rabbah 8:7
רבי יהושע דסכנין בשם רבי שמואל אמר: בנפשותן של צדיקים נמלך, הדא הוא דכתיב (ד"ה א ד): המה היוצרים ויושבי נטעים וגדרה עם המלך במלאכתו ישבו שמה. המה היוצרים, על שם וייצר ה' אלהים את האדם עפר מן האדמה. יושבי נטעים, על שם ויטע ה' אלהים גן בעדן מקדם. וגדרה, על שם (ירמיה ה) אשר שמתי חול גבול לים. עם המלך במלאכתו ישבו, עם המלך מלך מלכי המלכים הקדוש ברוך הוא ישבו נפשות של צדיקים, שבהן נמלך הקדוש ב"ה וברא את העולם.