I'm building a world with medieval-era technology, in which there is a basic type of magic, where magic users can, rather than just waving their hands and doing anything they please, can instead control physical energies (like kinetic, heat, electrical, chemical etc.).
In this world, a lot of potential energy can be stored in a reasonably small object (I won't go into numbers, for the sake of the question let's just say "a sufficiently large amount") that can essentially be a battery to power magic if one can control it. Then I realized, it could also possibly be used to power machinery... like robots.
Now, assuming the robots can be programmed to control how to use this energy for things like movement etc. a simple constructed body (humanoid looking stone/wood/metal construct built with hinges instead of joints for example) would be able to be powered for a limited amount of time. Then, if the "battery" is replaced it can go on indefinitely as long as the body is properly maintained.
As the robots can manipulate the stored energy in their "batteries" for their own operating power, let's assume that they get their sensory inputs by detecting energy from light/sound etc. so that they can see and hear things.
However, it is the programming that I am struggling to find a reasonable explanation for. The closest thing I can think of from other fantasy worlds that operate without modern technology and programming techniques are steampunk-type robots, but I'm not sure if they are just given commands via hand-waving magic.
Is there any way to give commands to this type of robot without using hand-waving magic? Or could there be something that would act as a reasonable substitute for the internal machinery of a robot allowing it to "think"? I did think of stuffing the brain of a human/animal inside the robot and having the energy from the battery power it, but if there is a less grotesque solution that would be much better.
As an explanation for why a world with this magic is still medieval era tech, let's assume that the monarchy controls all of the wizarding population, and only allows them to build what the King requires, like an unquestioning robot army that will protect him and his family.
EDIT: I've just realized that I entirely forgot to mention that the robots don't need to nearly be as sophisticated as humans. It was pointed out that I'm essentially describing a Golem, but I'm hoping for a creation with a little more ability for free thought and reasoning, like to recognize friend from foe/ intruder from guest rather than the more literal commands of attack anything that approaches.
Also, if you can find a way to use this magic to advance the tech a little to a point that you might need for this creation, that is reasonable (you do have an army of wizards at your disposal after all).