Can bacteria only thrive in agar solution?
You seem to have some misconceptions about growing bacteria. These are cultivated using specific media, for E.coli this is usually LB Medium which contains the following ingredients per liter:


10g Bacto-tryptone
5g yeast extract
10g NaCl


This is dissolved in water and subsequently sterilized by autoclaving. Note that there are much more medium recipes for different strains and different culturing conditions.

Bacteria can then be grown either in suspension (shaking in an Erlenmeyer bottle in the liquid media) or on the surface of plates. To produce these plates, you need an agent, which solidifies the medium without having any effect on the growth of the bacteria or the medium. And this is where the Agarose is used. It can be heated up with the medium during sterilization, does not interact with the medium and bacteria do not metabolize it. If you cultivate bacteria, which produce agarase (which is an enzyme to break down agarose), you need to use a different agent to solidify your medium. And you will use a different medium anyways.
They simply grow on the surface of the solified medium and can easily be picked for further analysis or the inoculation of (bigger) liquid cultures.