I have mentioned it before and will again that I had a one-on-one lesson with Ben regarding this very subject. I guess we talked about it for around 3 hours or so. So I will tell ya what he suggested I do in order to learn this.
First get acquainted with the bag-o-licks and know them inside and out. Then try to sit down and work out at least 10 "simple songs" that are very common like Happy Birthday to You, Twinkle Twinkle Little Star, etc and work out the melody.
The idea in working out the melody is to slowly start to be able to play what you hear...I mean in all practicality you have to get good enough on your instrument to "not think about it" and use the instrument to "sing". So for instance whatever you would "hum" in your head you should be able to make the guitar give you that same sound. This is one of the reasons why so many teachers want you to hum the notes when doing your scale practices...it's familiarization with intervals and recognizing where a "sound or note is".
A valuable tool that some of us use is the Tef Player....one can work out the melody there and then look at the "blank spots" between notes on the melody then fill them with licks, maybe it's your own lick or maybe it's one you've heard before through Ben. It does not have to be a complete lick, could be just part of one that you've learned from Ben or elsewhere.
Now you are probably saying "Wait this is just like memorizing a song vs. improvisation"....well you have to practice doing this! Once you practice this enough then it will start coming natural.
Drguitar mentioned how bluegrass likes the follow the melody...no doubt about that. I like sticking pretty close to the exact melody notes but will leave out ones that are not really important if I have a passage that sounds cool for a measure or so, then I will get back on the melody....so always have that melody close by!
For instance sing this in your head "happy birthday to you............happy birthday to you"...well notice the "space" between the 2 phrases, now sing it like this and keep it in the same time "happy brithday to you..you crazy fool..happy birthday to you" If you keep both in the same time signature/beats per minute then you've improvised in adding in the "you crazy fool"....you've filled up that "blank spot" with improv and still are following the melody.
I've been working on these types of ideas over the last year and I am finding myself to be a much better player....at least I am able to follow a melody line a lot better.
You have to learn to "talk or sing" with your instrument just like you would with humming a melody...I mean we all can hear a song we've never heard before and listen to a verse, chorus, then a verse for the first time and although we might not know the lyrics we can hum the melody....now we all have to get good enough to use our instrument to play the melody without much thinking going on...just like we can recognize or hum the melody with little effort.
Hope I have helped.