The trick is to recognize that the individual robotic device itself does not have to be a nanobot to do what you want. I have a sculpture (if one can call an infinitely changing shape a sculpture) on my desk made up of tens of tiny super-magnet balls. I can mold it like putty, and it stays in the shape I put it in, rather rigidly. But if I take each ball apart, and drop them on my desk, they individually roll all over, under, and between non-metal objects like you would expect from very tiny ball bearings. However, when the paths of two come together, or they come close to a metal object, they start to build up in clumps again. It is also quite amusing to watch one rolling sphere change course and 'chase after' another nearby sphere, until it catches up and melds with it. Once they form into a clump, it can be quite mechanically 'solid'. If I form it into a long thick bar, it is strong enough for me to swing and knock non-metallic things around with, and to lift metallic objects.
So think instead of a swarm of microbots, each one say the size of a grain of salt. These would individually be small enough to get between small cracks, but large enough to have functionality inside of them. But instead of magnetic spheres, how about non-magnetic geodesic dome shapes? If each surface were perfectly flat, then when two of them came together they would stick together using Van der Walls forces (think gecko feet). Biomechanical devices inside would allow the surfaces to curve, in order for the robots to break apart and reform using other surfaces, forming a different overall shape. The flat surfaces of geodesic domes would allow for a much more stable non-slip mechanical joint when rigidity were required (application of significant force). Since they use gecko feet to stick together, they could also use the same feature to individually climb walls and 'walk' across ceilings, and then reform.
Where I see the nanobots come in, are the workings inside of these individual robots. Each nanobot would specialize in a certain function, performing multiple tasks within the minibot dome. I could see some of them as biology-based DNA-type shape-shifting nanobots that would change the overall shape of the dome. I would also see these tiny nanobots-within-a-robot responsible for energy production, perhaps like mitochondria, and also for moving nutrients between the minibots. Some might even scavenge metal to produce energy. The idea of making the internal workings out of nanobots, is that the bots within the bot would be autonomous. That is, if one dome were destroyed, the individual nanobots within could re-group into nearby domes, perhaps by using scavenger bots, and maybe collectively form into a new dome in a self-healing process.
These minirobots could, in fact, specialize in function, some being nutrient carriers, some being reference nodes that determine where in reference to other nodes and in space they are, 'muscle' bots that produce stretch and contraction forces between similar minibots, some 'mother hen' nodes that would collect up other wandering nodes, and so on.
So, now we have the intelligence problem. No worries, the AI algorithms are already being worked on by military research to come up with methods to coordinate swarm robots into one unified coordinated functioning goal-directed whole.
But how do you get the 'brains' to bring it all together? One minirobot would probably not be 'smart' enough. But Quantum computer networks? Already being researched. Distributed processing through the interconnections of thousands of quantum computer nodes. The catch is, it would not be 'sequential digital' processing, it would be more like our own brains, simultaneous analogue pattern processing and probabilistic decision making. That is, they might not be good at pure logic and deductive reasoning, but they would be superior at goal-directed planning and spacial tasks based on looking at the overall situation, the type of instantaneous decisions needed for battlefield strategy.
The goal of this work is to shed light on the challenges and open
problems of Quantum Internet design. We first introduce some basic
knowledge of quantum mechanics, needed to understand the differences
between a classical and a quantum network. Then, we introduce quantum
teleportation as the key strategy for transmitting quantum information
without physically transferring the particle that stores the quantum
information or violating the principles of quantum mechanics. Finally,
the key research challenges to design quantum communication networks
So, really, within the scope of existing research, and a whole lot of engineering, your vision of a swarm of minirobots made of nanobots forming an entity that could reform itself are well within conjecture, and even within the limits of, say, the next 100 years of existing earth-based technology for a very limited function specific purpose (say mining or demolition) device under external cloud intelligence RF or 7G (we are at 5G) control.