Sammygirl...this is the way I see it. Once upon a time, long, long ago when dogs were first becoming domesticated, they began by hanging around human settlements when man went from being nomadic hunters/gatherers to settling in villages as agriculturists. (this, of course is one theory of how dogs became domestic) Anyhow, theoretically, those humans probably simply tolerated the presence of these animals. (whether they were wolf like or a smaller, dog-like animal....no one knows for sure what dogs' ancestors were, very controversial)
Then they discovered that these animals, who were at that time fairly uniform in structure (that's biology) could be used to help them do something. In the beginning, I doubt dogs were used for hunting. They'd probably at that time, hunt all right, but they'd probably run too fast and eat the kill before the human could get to it. But over time, when humans started taking an interest in these early dogs, they started choosing and exploiting traits which would be useful to them.
See....in every population, there are some mutations...slight variations of form and in temperament. This is where artificial selection probably got started. They'd take a dog that had a stronger than usual trait that they liked and breed it to another that was similar. Say they needed a very fast runner. Maybe a dog happened to have a bit longer legs and could run faster than his predecessors. So, they'd use him in their breeding program and get a bunch of faster runners.
I'm kind of thinking out loud here. Which came first, the chicken or the egg? A job came along. A dog best suited was used for the job. Job....Dog. Function....Form. But artificial selection enhanced traits to suit the job even better. Once humans really got busy with selective breeding, a dog could be created to suit a particular need... a little tweek here and a little change there. The need was there. The form, the traits came along after a need was acknowledged. Or it could have been that the form was there (a particular combination of variations) and a job opened up for that particular type. But I don't think that would be the norm because think about it....how many jobs get dreamed up just so they suit a particular form or type of dog? No, not often. The form usually comes about by way of selection in order to fill a need.
I guess these days, with so many types of dogs and so many things to do with dogs, one could dream up a new dog sport to go with an existing breed or type. The sport then, could be invented so that it would fit this particular type of dog. "Oh....we gotta change the rules of that game. That type of dog can't do that." LOL. How might agility have come about? Did the rules of this game get created and then they discovered which dogs did best? Or did they look at some very fast, agile dogs and say, "Hmmmm....we could make this game called agility and just look at those dogs! They'd really do well in it." Which came first, the game or the traits of those dogs? Well, of course we know the dogs came first. But....they are tweeking the breeding to create dogs that excell even more than before in agility. So, the form is following the function again. The dogs that are not as agile, drivey or fast are being selected against.
Anyhow...just some pondering.