Gandalf left Thorin after his first meeting without committing to help him to reclaim Erebor. Thorin was full of grandiose plans to attack Smaug in his lair; Gandalf was not in agreement. He decided to visit Bilbo in The Shire as Bilbo had impressed him 20 years ago with his yearning for adventure and exploration. Travelling through the Shire, he asked Bilbo's neighbours as to Bilbo's whereabouts. They were disapproving in their answers as they told him of Bilbo's eccentricity in terms of his befriending Elves and Dwarves. This was not acceptable Hobbit behaviour in their eyes. At the mention of dwarves, a plan gradually began to gel in Gandalf's mind. Perhaps Bilbo might join forces with Thorin in order to start a quest for Erebor. Gandalf had suspected Saruman of losing track of his original mission to free Middle Earth of the evil that was brewing. He felt a sense of urgency to attend the White Council which he hoped would distract attention from Erebor. If he could persuade Thorin and his dwarf company to form a mission with Bilbo to oust the greedy Smaug from the Lonely Mountain while the White Council distracted Sauron, his purposes would be served.
He therefore returned to Thorin to persuade him to consider the plan for a silent attack on the dragon by taking a hobbit as his secret weapon. Hobbits were stealthy, dwarves were not renowned for their silence. The challenge for Gandalf was to persuade Thorin to agree to his plan. Following are a few passages from JRR Tolkien's "Unfinished Tales" Ch: III of the 3rd Age
Gandalf explains that after their first meeting in Bree, Thorin and he had to pass through the Shire to get to the Halls in Ered Luin. This might set the scene a little ...
"...we actually passed through the Shire, though Thorin would not stop long enough for that to be useful. Indeed I think it was annoyance at his haughty disregard of the Hobbits that first put into my head the idea of entangling him with them. As far as he was concerned they were just food-growers who happened to work the fields on either side of the Dwarves' ancestral road to the Mountains" (p 429 "Unfinished Tales" J.R.R. Tolkien)
Unfinished Tales has an excellent chapter describing Gandalf's meetings with Thorin and his kinsfolk, Balin, Gloin and Fili who were all highly sceptical about joining forces with a Hobbit.
"Your own ideas are those of a King, Thorin Oakenshield; but your kingdom is gone. If it is to be restored, which I doubt, it must be from small beginnings. Far away from here , I wonder if you fully realise the strength of a great Dragon. But that is not all: there is a Shadow growing fast in the world far more terrible. They will help one another.
.... Open war would be quite useless; and anyway it is impossible for you to arrange it. You will have to try something simpler and yet bolder, indeed something desperate." (Gandalf. "Unfinished Tales" p 429-30. J. R. R. Tolkien).
"Listen to me Thorin Oakenshield!" I said. " If this hobbit goes with you, you will succeed. If not, you will fail." (Gandalf. "Unfinished Tales". J. R. R. Tolkien).