Flux does several things, all at the same time. Probably the most important thing it does is to help prevent oxidation of very hot metals which are in a chemically active state precisely because they are hot. Heat, in almost all cases speeds, accentuates, intensifies chemical reactions. Oxides of metals tend to have much higher melting points than the raw metals themselves, and they also tend to be lighter per unit volume. That means they will tend to float on a pool of molten metal. This is why when melting zinc and aluminum, the crud that floats on top is usually skimmed off and discarded. Without flux, many metals will "skin over" with their high melting point oxide, the oxygen coming from the surrounding air. The oxide then prevents heat (from your torch) from hitting the surface of a blob of metal you're trying to melt, so the metal then cools and then the oxide (a pollutant, obviously, if you are trying to refine) gets embedded in the surface of the metal. This usually gives a powdery, gritty, rough appearance. This completely sucks, it's exactly the opposite of what you're trying to achieve. It also represents a loss of values. If your silver enters into a chemical reaction, then it is no longer available to be nice shiny metal.
Flux is also a wetting agent, when molten it is a "wetter" liquid than the liquid metal. It has a lower surface tension, it has a greater tendency to wet surfaces. At the same time, it does not, or should not, react with the molten metal. So in the case of silver and gold in a melting dish, it produces a smooth, very low friction surface that the molten metal can be rolled around on. It smooths the surface of a melting dish by wetting and being partially absorbed into the porous ceramic material of the melting dish.
Some fluxes aggressively attack and absorb oxides and other impurties. Acid flux, as used in solder, does this. But, it leaves a residue that is well, acidic. So it is not to be used with electronic soldering, because the residual acid over time attacks other items next to the solder joint you're making. This isn't a problem with soldering copper pipe, but a good plumber will wipe away excess flux with a wet rag from a "sweated" (soldered) copper-to-copper or copper-to-brass plumbing joint because over time, excess flux will crystallize and turn green if there is moisture around that reactivates the excess acid left behind. Especially copper-to-brass where there is zinc in the brass part. You've seen that on old plumbing joints. For electronic applications, you use "resin" flux which is extracted from pine wood. Flux which doesn't boil away floats on top of the molten solder, protecting it from oxidation, wets the items being soldered, and shields the joint from oxidation as it cools. If any excess is there, it doesn't turn into an acid. Elect flux doesn't have to be so aggressive because we are not heating up the materials to torch-level heat.
So flux does all three of these things, in varying amounts, depending on the exact application. Wetting agent, oxidation preventer, pollutant scavenger. In many applications, the use of flux can be reduced somewhat by carefully controlling the atmosphere in which melting takes place. That might mean an oven with an inert atmosphere or, carefully keeping the melt in the reducing portion of a torch flame.
It is different substances for different applications. Borax is used a lot for silver and gold. You do not make it, it's super cheap to buy.