Where do they come from? When did they separate from libraries?
This is actually a tougher question than you'd think. It depends on how you're thinking of "archives," because government-based record-keeping is very very old, and occurs in many cultures all over the globe. I actually wouldn't frame it in terms of libraries vs. archives, but more "when did government records become public."
Attitudes about public access actually goes back to the French Revolution, which created the Archives nationales specifically with public access rules. The French later innovated many of what are now key values and principles of archival theory and what separates us from libraries, namely respect des fonds ("with respect to creator") and provenance. Respect des fonds is the idea that the context in which a document existed has historical value and should be preserved. Mainly this means we don't reorganize stuff if we can at all help it. Archives are organized by who made it, while libraries are organized by topic.
Margaret Cross Norton was also a key "thought leader" in moving the archivist away from the historian-archivist, and that happened in the 1950s-60s. Prior to that things were a bit more loosey-goosey with people regularly being the unofficial historian and the archivist. This is an unimportant distinction among the public I've found, but it is a big part of our professional values today that we are "not historians" about our records, and don't frame them or attempt to interpret history with them.
Some of these values are fluctuating in the profession right now but these are I'd say the key elements of our heritage for the last 300 years. The merging of librarians and archivists has actually only started happening in the last 20-30 years. There's a generational split of MLS/non MLS archivists. We're also increasingly being tossed in with rare books as "Special Collections" which is not my favorite thing. Very different skillsets there.
Sorry this is a little fast and dirty, it's almost lunch. Most of this is based on Ch 2 of this book which probably all the little archivists have to read in school. EDIT: hey look the old edition is on HathiTrust!, apparently this book doesn't mention the French tradition much (how can you forget the French??) but it does talk about Margaret Cross Norton who is largely worshiped as an archival goddess.