Throughout music history, different composers have approached accompany a melody differently. In the Baroque era, figured bass, a form of pseudo improvisation was king. Figured bass gave performers with the bottom note of the chord and the intervals above the bass note, this left most of the details to be “filled in” by the performer. Many pieces from the era were originally just a melody and a figured bass line. Here’s an example from Henry Purcell’s Dido and Aeneas:
Overtime, figured bass in classical music gave way to fully notated accompaniment. This was partly due to growth of larger instrumental ensembles and in part due to the growth in popularity of printed music.
Improvised accompaniment is still the norm in Jazz. While in popular music (including rock) many accompaniment patterns are repeating patterns. In classical music, a repeating musical pattern is called an ostinato. In popular music it’s often referred to as a riff.