We performed a study of the baryonic matter (stars and hot gas) budget inside X-ray detected groups at z<1 using the COSMOS survey, and compared it to that of local massive clusters. We constrain the stellar and total baryon mass fractions in groups: our results suggest that groups are not simple scaled down versions of clusters and that they are likely not closed systems, being more strongly affected by non-gravitational processes (such as AGN activity) than clusters. To have a better understanding of the importance of non gravitational processes in groups we study the energetics of radio galaxy feedback in X-ray detected galaxy groups and estimated the effect of the energy injection. We find that radio-AGN activity is capable of outweighing the capacity of a group to hold its gas. Furthermore, taking this energy injection into account we predict the deviation of the S-T relation from self similarity at the groups regime.