user
Instruction: Describe how magnetic fields are generated.

assistant
Magnetic fields are generated by the motion of electrically charged particles. When an electric current is generated due to the motion of electrons in a conductor, it creates a magnetic field that encircles the conductor. Conversely, when a wire moves through a magnetic field, electric current is generated.