Starfleet considers their first purpose to be exploring the galaxy and making contact with new races.
My impression is that Starfleet is the Federation's general purpose errand boys. Just about anything that need to be done, Starfleet gets the assignment. Everything from high visibility diplomatic glamor jobs to the little shit jobs.
Their first priority would be offense/defense. It might not be what occupies most of their time, but anything else Starfleet is doing at the moment gets dropped if the Federation need them to saber rattle, or go and shoot somebody.