The ecological role of microorganisms is of utmost importance due to their multiple interactions with the environment. However, assessing the contribution of individual taxonomic groups has proven difficult despite the availability of high throughput data, hindering our understanding of such complex systems. Here, we propose a quantitative definition of guild that is readily applicable to metagenomic data. Our framework focuses on the functional character of protein sequences, as well as their diversifying nature. First, we discriminate functional sequences from the whole sequence space corresponding to a gene annotation to then quantify their contribution to the guild composition across environments. In addition, we distinguish between sequence spaces that have different ways of carrying out the function. We demonstrate the validity of our approach by quantifying the guild of ammonia oxidation, and further reveal novel ecological dynamics of putrescine uptake guild in marine ecosystems. Thus, guilds help elucidate the functional role of different taxonomic groups with profound implications in the study of microbial communities.