In my book, I want to have a character who has a weapon that is actually a swarm of nanobots, and that can take on the shape of any melee weapon within a matter of seconds. I'm thinking of holding them together via powerful electro-magnets spread across the body of each nanobot. Powerful computers set within each bot could figure out how exactly to manipulate themselves into the desired shape using swarm intelligence, and assume the required structure through strategic activation and deactivation of the magnets.
I think I can solve the energy problem, using piezoelectic bodies and localized nuclear reactors, but the main problem is that electromagnets that small and powerful don't really exist.
Any alternative ways to hold them together so they can withstand the strain of combat?
Edit: I am thinking of using room temperature superconducting electromagnets to hold the bots together, since I read that fields of over 17 tesla have been achieved with them. Thoughts?