LLM Conversation Context Migration: A Practical Guide to Exporting and Resuming Sessions
This guide explains how to move LLM conversation context between tools or models without losing the information that matters. It covers export file structures, a cleaning workflow with Python examples, layered context reconstruction, criteria for choosing a target application, privacy safeguards, troubleshooting, and habits that make future migrations easier.
1. Why Migrate Conversation Context
The value of an LLM conversation comes primarily from its context. After multiple rounds of discussion, the model has learned the task goals, constraints, confirmed approaches, and unresolved issues. When a provider changes usage quotas, caps the length of a single session, or a user wants to switch to a tool better suited to the current task, re-describing the background from scratch is not only time-consuming but also likely to miss key details.
The goal of session migration is therefore clear: move the useful information from an existing conversation completely into a new environment so that the new model can pick up the original thread with less preparation time.
2. Understand the Structure of Export Files First
Most conversation services do not export plain text. They export structured data that contains a large amount of state information. Common contents include:
- Message list: the role of each message (user, assistant, system) and its text content. This is the part that matters most during migration.
- Timestamps and message identifiers: used for sorting and tracking, usually not directly useful for resuming a conversation.
- Model parameters and session configuration: settings such as generation randomness and maximum output length. These need to be reconfirmed in the new environment.
- Attachments and reference information: metadata and link addresses for images or files. In most cases, only the textual descriptions need to be retained.
- Interface state: favorites, collapsed sections, branches, and similar markers. These are unrelated to conversational semantics.
Before processing, open the file with a text editor or JSON viewer to confirm the field hierarchy, then decide which contents to keep. Field names and nesting can differ greatly between services, so do not assume that all export files share the same structure.
3. General Export Workflow
Entry names and locations vary by platform, but the basic steps are similar:
- Open the conversation history list and select the conversation to save.
- Look for an export, download, or backup option in the conversation menu.
- When using a desktop browser, the file is usually saved directly to the local downloads directory.
- On mobile devices, some apps generate a download link. You need to copy it into the system browser and open it there to save the file.
After exporting, immediately check the file size and the last few messages to confirm that the content has not been truncated. If a long conversation is exported incompletely, the quality of the resumed conversation will drop noticeably.
4. Clean the Data: Keep Only Core Context
The core principle of cleaning is to preserve semantics and remove noise. Apply the following rules:
- Keep user and assistant text messages and arrange them in chronological order.
- Remove system-generated state fields, empty messages, and duplicate retry records.
- For very long code blocks or logs, keep the key snippets and mark where content was omitted.
- For approaches the user explicitly rejected, add a note to prevent the new model from adopting them again.
Below is a general Python example. It assumes the export file is a message array and that each element contains role and content fields. Actual field names should be adjusted according to the file structure.
import jsondef clean_conversation(src_path: str, dst_path: str) -> None:with open(src_path, "r", encoding="utf-8") as f:data = json.load(f)messages = data.get("messages", data) if isinstance(data, dict) else datacleaned = []for msg in messages:role = msg.get("role")content = msg.get("content")# Some formats store content as a list of parts; join them into plain textif isinstance(content, list):content = "\n".join(part.get("text", "") for part in content if isinstance(part, dict))content = (content or "").strip()if role not in ("user", "assistant") or not content:continuecleaned.append({"role": role, "content": content})with open(dst_path, "w", encoding="utf-8") as f:json.dump(cleaned, f, ensure_ascii=False, indent=2)if __name__ == "__main__":clean_conversation("export.json", "context.json")
The cleaned file should be fully readable as plain text. If you find that key information is missing, go back to the original file and supplement it rather than reconstructing it from memory.
5. Rebuild the Context and Resume the Conversation
Pasting the entire cleaned record directly into a new session usually creates two problems. First, the content may exceed the target model’s context window. Second, earlier key content may be diluted by a large amount of detail. A safer approach is to divide the material into three layers:
- Task summary: a few paragraphs explaining the project goal, current progress, and key constraints.
- Key decisions and conclusions: confirmed approaches, excluded options, and the reasons for exclusion.
- Recent original text: keep the last several complete turns to help the new model understand the current context.
The opening instruction can be written as follows:
Below is a background summary and a record of recent conversation from an earlier discussion. Please read the summary first and confirm your understanding, then continue from the first item in the To-Do list.
Estimate the input length in advance. Token conversion for Chinese text varies by tokenizer; as a rough guide, Chinese text may be about one to two tokens per character. Use the target platform’s counting method for exact numbers. At the same time, leave enough room for model output; otherwise, answers may be truncated.
6. Considerations for Choosing a Target Application
Migration quality depends not only on data quality but also on the application that carries the conversation. Evaluate the following dimensions:
- Context length: whether it can hold the organized material and still leave enough output space.
- Access method: whether it supports using your own model service API key and whether usage costs are controllable.
- Feature fit: whether you need capabilities such as file processing, code execution, or web retrieval.
- Data policy: how the provider stores and uses input content and whether it supports deleting historical data.
- Stability: response speed and error rate during long sessions.
If you want to connect your own model service, consult the provider’s public API documentation. For example, Baidu AI Cloud offers LLM-related services, and its integration details can be found in the official documentation.
7. Privacy and Security
Exported conversations often contain business data, source code, account information, and even personal privacy. Follow these practices:
- Complete cleaning locally and avoid uploading raw files to untrusted third-party tools.
- Before cleaning, check and redact keys, tokens, phone numbers, email addresses, and internal addresses.
- Provide only the minimum information required to complete the task to the target application.
- Delete intermediate files after processing, or store them in an encrypted directory.
- In enterprise environments, confirm compliance with company data management policies before migration.
The example below demonstrates how to use regular expressions for initial redaction of common sensitive information. The rules cover common formats only; manual review is still required before sending.
import reREDACTION_RULES = [(re.compile(r"(api[_-]?key|token|secret|password)\s*[:=]\s*\S+", re.IGNORECASE),r"\1=[REDACTED]"),(re.compile(r"1[3-9]\d{9}"), "[REDACTED_PHONE]"),(re.compile(r"[\w.+-]+@[\w-]+(\.[\w-]+)+"), "[REDACTED_EMAIL]"),]def redact(text: str) -> str:for pattern, replacement in REDACTION_RULES:text = pattern.sub(replacement, text)return text
8. Troubleshooting Common Issues
- Resumed answers drift from the original goal: check whether the summary omitted key constraints, add them, and restart the conversation.
- Answers repeatedly discuss issues that were already resolved: delete old failed attempts and keep only the final conclusions.
- Garbled text or broken formatting appears: confirm that the file is saved in UTF-8 encoding and check for truncated fields.
- Responses become noticeably slower or are truncated: reduce the number of original turns retained and compress more content into the summary.
9. Recommended Working Habits
For tasks that need to be advanced over a long period, the following habits can reduce migration costs:
- After completing each stage, update a separate summary document that records goals, decisions, and to-do items.
- Export and back up important conversations regularly to avoid relying on a single platform to preserve history.
- After migration, verify with two or three questions that have known answers to confirm that the new model understands the key background before continuing formal work.
