Why do government agencies exist?

This certainly applies to the United States, however, it's very likely other governments have "agencies". Here is an example of why governmental agencies exist. Within the Federal Government and within other levels of government, agencies are created for a specific reason. The US Commerce Department is used here as an example. This Department is a cabinet level part of the Federal government. It's headed by an appointee of the President and the Secretary of Commerce reports to the President.

The general purpose of this department is to promote business opportunities for American industries. It has other duties as well such as having foreign governments or foreign companies to buy USA made products. There is a long list of duties for this important department.

One domestic business is the credit card business. It comes to the attention of the department that consumers are being "cheated" by unscrupulous business practices by this industry.

In order that consumers are protected and regulations for this industry are being followed, the department set up within itself a separate organization or agency to deal specifically with consumer complaints about credit cards.

Thus it may create the Consumer Credit Agency to deal with the problem.

It can call it another name, as it does with the patent awarding "agency " within itself and call it the "Patent Office" or the Patent Agency.

The main point here is that it is a subset of the larger organization.