One of the most important questions to ask yourself as a web developer is if you enjoy working on a single product, or across multiple products. There is no right answer to this question. However, there is a right answer for you.
Product work creates deep knowledge in a given discipline, both in terms of domain knowledge, and technical knowledge. You need to being willing and able to continually refine and build upon the same software over a long period of time.
The more interesting technical problems tend to arise in product work. You get to deal with issues of scale. You get to deal with the problem of how to change a legacy codebase. You get to deal with optimization and conversion. You get to pivot.
Product work isn't for you if you like to start fresh on a regular basis, again either domain wise or technically. If you're working on a product for dentists, you'll always be working in dentistry. If you're working on a todo list application, you'll always be working on a todo list application. If your product was built in framework ABC, you'll likely always be working in framework ABC.
Agency work creates a wide breadth of skills across multiple disciplines, both technical skill and industry knowledge. If we assume that agency work is for a new product idea or engagement, which it tends to be in my experience, it favors those that enjoy starting fresh on a regular basis. Developers often get to use the latest technical hotness.
The wide breadth comes at the cost of depth. You tend to solve a variation of the same problem over and over. The more interesting technical challenges don't arise until the engagement has ended and the product has been handed off.
There are agencies that make a name for themselves by specializing in a given challenge, a hybrid of the two models. One example might be Rails application performance. This type of agency gets to solve some of the deeper technical challenges of an existing product, and get to apply that knowledge across many industries.