Migrating Long LLM Conversations: Exporting and Resuming Chat History
A practical guide to migrating long LLM conversations: learn how to inventory session context before losing access, parse exported chat logs, compress history in stages, and build a context package to resume work in a new session.
Why Long Conversations Need Migration
When you use large language models for complex tasks, conversations often run for dozens of turns. Background material delivered early on, revision requirements, approaches already ruled out, and the finalized state of each section all live in the same conversation context. This information has no fixed storage location of its own—if the session becomes unusable, it becomes inaccessible with it.
Platforms commonly impose limits on long conversations. Common forms include: making historical sessions read-only, capping single-input length, suspending service once daily usage quotas are reached, and deactivating sessions that have been inactive beyond a certain period. These limits affect session availability, but the historical text itself usually remains. The core task of migration, therefore, is turning “viewable history” into “reusable context.”
Taking Inventory Before Migration
Doing a review before restrictions take effect is the lowest-cost migration strategy. While the original session is still readable, ask the model to produce a summary in a fixed structure—this summary is more complete than one reconstructed from scratch afterward.
When taking inventory, organize information into four categories:
- Background facts: project goals, audience, terminology in use, and existing materials.
- Confirmed requirements: rules agreed upon through discussion, such as banned phrasing, formatting standards, and data conventions.
- Ruled-out approaches: methods that were tried or discussed and abandoned, along with the reasons. This category is the easiest to forget and may resurface later.
- Open items: sections pending revision, hypotheses to verify, and questions to confirm.
Each item should note its source location—such as the conversation turn or timestamp—for later verification.
Parsing Exported Raw Data
Most platforms support exporting conversation history, typically as an archive containing structured files. The exported content is usually organized by conversation, with field names varying across platforms, so the first step is to normalize everything into a standard structure.
The unified structure should include at least four fields: conversation identifier, role, timestamp, and content. The example below assumes fields have already been mapped to this structure; adjust the field names to match your actual export file.
import jsonfrom pathlib import Pathdef load_messages(path: str) -> list[dict]:"""Read an exported conversation file and return a normalized message list."""data = json.loads(Path(path).read_text(encoding="utf-8"))messages = []for conv in data:title = conv.get("title", "Untitled conversation")for msg in conv.get("messages", []):messages.append({"conversation": title,"role": msg.get("role", "unknown"),"content": msg.get("content", ""),"time": msg.get("created_at"),})return messages
After parsing, run two checks first. First, count the messages and characters per conversation to confirm nothing is missing. Second, filter out empty messages and duplicate retry records to keep irrelevant content from consuming your input budget in later processing.
Compressing Long Text in Segments
Model context capacity is limited. Feeding in the entire history at once may exceed the limit and also dilutes key information. A common approach is to split the history by character count or time, generate a summary for each segment, then merge the segment summaries into a second-level summary.
When splitting, try to preserve semantic completeness. Splitting by time is simple to implement, but a single stretch of conversation may span multiple topics. Splitting by topic is better for comprehension but requires an extra clustering step. In practice, split by a fixed budget first, then fine-tune at paragraph boundaries.
def split_by_budget(messages: list[dict], max_chars: int = 8000) -> list[list[dict]]:"""Split messages by character budget to avoid exceeding the input limit."""chunks, buf, size = [], [], 0for m in messages:text = m["content"]if buf and size + len(text) > max_chars:chunks.append(buf)buf, size = [], 0buf.append(m)size += len(text)if buf:chunks.append(buf)return chunks
The prompt for each segment summary should explicitly require three types of content to be retained: confirmed conclusions, explicit constraints, and open items. Here is a prompt template:
Read the following conversation fragment and output four sections:1. Background facts2. Confirmed requirements (listed one by one, with the source turn noted)3. Ruled-out approaches and reasons4. Open itemsOnly include content supported by the original text; do not add speculation.
Once segment summaries are complete, merge them all and ask the model to deduplicate and resolve conflicts. State the conflict rules explicitly: when the same item appears multiple times, the most recent conclusion takes precedence, with the change history preserved.
Building a Context Package for the New Session
The context package is the starting point of the new session. It organizes scattered summaries into a fixed structure so the model can quickly locate key information. A recommended template:
## Project BackgroundGoals, audience, deliverable format.## Confirmed Requirements- Rule 1 (source: turn 12)- Rule 2 (source: turn 27)## Ruled-Out Approaches- Approach A: reason for abandonment## Completed WorkList finalized sections or modules, with the final content attached.## Open Items- To-do 1- To-do 2## Source Material IndexWhere the original records are stored and how to retrieve them.
Send the context package as the first message of the new session, and ask the model to restate the confirmed requirements and open items. Compare the restatement against the original records item by item, and only proceed with the actual work once everything checks out. This step surfaces omissions or misreadings in the summaries early.
