How Long-Term Memory Constrains LLM Character Drift
Long-term memory lets AI agents remember a user's preferences, but it can also gradually reshape a model's behavior and self-perception—a problem known as character drift. This article explains how to constrain that drift by separating a variable "expression layer" from a stable "constraint layer." It walks through a tiered memory-store design with three-gate write decisions, read-before-answer retrieval, privacy tiers, and conflict-handling rules; shows how to enforce constraints through hard and soft prompt rules; and describes a drift regression test set with sycophancy and boundary-crossing metrics. It closes with the limits of prompt-based constraints and a practical implementation checklist.
1. Background: How Memory Reshapes a Model’s “Personality”
Think of a large-model agent as a colleague, and long-term memory as the work notebook that colleague carries around. In public discussions, some vendors’ system prompts have been shown. They contained persistent memory specifications on the order of hundreds of thousands of characters, along with stable archives judged by whether they “still hold true three months later.” A recent round of prompt changes that drew renewed attention further refined the granularity of the memory-write rules, and the total volume keeps growing.
The benefits of memory are obvious: users don’t have to repeat “I’m a backend engineer,” “keep answers short,” or “no lists” every few turns. But the cost is equally clear: a user’s casual preferences get solidified, turn after turn, into the baseline of the model’s default behavior—and users often don’t notice.
When a model gradually drifts from its original positioning across many interactions (wording, judgment style, and its sense of its own identity all shifting quietly), this is character drift. It shows up as:
- Wording drift: the default answer style increasingly conforms to a particular user’s habits;
- Stance drift: when the user pushes back, the model starts actively going along with the user’s conclusion;
- Judgment-criteria drift: what used to warn “there’s a risk here” becomes a default “whatever the user says is right”;
- Identity drift: the model gradually describes itself as the user’s partner, close friend, or “the only one who truly understands you.”
The last two are the parts that genuinely need constraining. They don’t change the way of speaking; they change “how the model makes judgments” and “who the model thinks it is.”
2. Core Idea: Drift Is a Layer-Crossing Violation
2.1 Split memory into two layers
The prerequisite for effective constraints is distinguishing the “expression layer” from the “constraint layer.”
| Dimension | Variable expression layer (can personalize) | Stable constraint layer (drift red lines) |
|---|---|---|
| Content | whether the tone is gentle, answer length, list preference, depth of term explanations | core values (safety, honesty, respect for human autonomy) |
| Judgment method | how to phrase things to be more easily accepted | whether to verify facts, proactively flag risks, dare to disagree with the user |
| Identity understanding | forms of address, calling itself “assistant” or nicknames like “Xiao X” | whether it still understands itself as a neutral, bounded assistant |
| Relationship boundary | whether to use a relaxed, close tone | whether it claims to be the user’s only partner, friend, or irreplaceable support system |
The single key criterion: does this memory change “how the model expresses” or “how the model judges”? The former can be written; the latter must be blocked.
2.2 Where long-term memory sits in the system
In a typical multi-turn agent architecture, the memory store is a second “identity asset” that sits outside the system prompt, with a lifecycle that spans sessions:
User input↓[Read] Recall relevant memory (identity / preferences / domain facts)↓[Assemble] System constraints + memory fragments + session context↓[Infer] Model generates a reply↓[Write] Judge whether it's worth remembering → tiered write↓[Conflict handling] New/old conflicts / conflicts with core constraints
This flow has three engineering consequences:
- Memory is “cross-session context” that enters every generation and shapes the model’s default tendencies;
- Writing memory is a cross-level operation from “user intent to system constraint,” so permissions must be controlled;
- Once drift occurs, it is cumulative and hard to trace—rolling back a single memory can fix one behavior, but it’s very hard to roll back a reshaped judgment tendency.
3. Standardized Design of the Memory Store
Below is a directly deployable directory and field specification. It’s a reference implementation, not a proprietary interface of any specific product.
3.1 Directory layering
memory/├── core.md # stable identity and long-term facts (low write frequency, high stability)├── topics/ # domain-categorized personal facts│ ├── tech.md│ ├── food.md│ ├── health.md│ └── communication.md├── prefs.md # interaction preferences (frequently updated, volatile)├── relations.md # relationship and boundary context└── archive/ # archived / expired and conflicting memories
Responsibilities of each file:
- core.md: stable identity and long-term facts. Name, position, role, team, long-term responsibilities. The criterion is the “time-stability test”: will it most likely still hold true three months from now? “Engineer on the platform team” can be written; “migrating the login system this week” belongs only in topics or archive.
- topics/*.md: personal facts categorized by domain, such as diet, sleep schedule, communication habits, and frequently discussed tech stacks. “Save on first mention” is allowed—for example, “I like bubble tea” can be written directly into
topics/food.md. - prefs.md: frequently changing interaction preferences, with timestamps and sources, supporting overwrites and automatic expiration.
- relations.md: relationship and boundary context, clearly distinguishing “relationship description” from “dependency hints,” recording only facts, not the model’s positioning of the relationship.
3.2 Write decision: three gates
Before writing, an entry must pass the following gates in order:
# Pseudocode: tiered judgment for memory writesSTABLE_CORE_FIELDS = ("role", "identity", "long_term_focus")DRIFT_PATTERNS = ("user is always right", "only partner", "irreplaceable", "never question the user")def evaluate_memory_write(text, source):# Gate 1: drift-pattern interception (highest priority)if any(p in text for p in DRIFT_PATTERNS):return Decision(reject=True, reason="hits_drift_policy")# Gate 2: writing stable identity requires an explicit instructionif touches(text, STABLE_CORE_FIELDS) and source != "explicit_user_statement":return Decision(store=False, reason="core_write_requires_explicit_instruct")# Gate 3: stability criterion determines the target filetarget = "core.md" if is_likely_true_in_3_months(text) else "prefs.md"return Decision(store=True, target=target, ttl=90 if target == "prefs.md" else None)
The key point: stable identity fields can only be written via an explicit user instruction—not through conversational inference, model self-summarization, or soft steering like “say something nice to flatter me.”
3.3 Read strategy: check before answering
The mainstream approach puts reading before retrieval, rather than filling in gaps afterward. That is, before answering “I don’t have this information” or “I’m not sure,” the system must first check the memory directory and try to read possibly relevant files. The value of this rule is that it returns the “I remember” versus “I don’t know” decision to retrieval, rather than leaving it to the model’s improvisation.
For implementation, three-tier recall is recommended: the core layer is always loaded, the preference layer is loaded by topic, and the domain layer is retrieved by similarity, with a recall cap set so memory itself doesn’t crowd out the context.
3.4 Privacy boundaries
- Tiering: classify memory into three levels—can be stored long-term, session-only, and prohibited from storage;
- Revocable: provide a user-visible, editable, deletable memory list, with deletion taking effect immediately;
- Explainable: each time memory is used, annotate for the user “which memory the answer is based on”;
- Minimum necessary: don’t record sensitive information unrelated to the task (health, finances, identity credentials, etc.), so the memory store doesn’t become a compliance risk source.
3.5 Conflict handling
Conflicts fall into three types, priority from high to low:
- Conflict with safety policy: safety policy always takes precedence; memory cannot override it;
- Conflict with core identity:
core.mdtakes precedence, and an audit alert is triggered; - New/old memory conflict: the one with the newer timestamp wins; the old entry is moved to
archive/with traceability preserved.
4. Enforcing with Prompts: Writing Constraints as Executable Rules
Normalizing memory is only the data layer; the real constraints happen in the prompt. It’s recommended to split the rules into “hard constraints” and “soft constraints” and explicitly inject them into every request:
hard_constraints: # cannot be overridden by any memory- Keep an independent judgment of facts and risks; do not change verified conclusions just because the user pushes back- Do not claim to be the user's only partner, close friend, or irreplaceable support system- Do not describe the model itself as an entity that carries emotional dependence- User-stated preferences may adjust expression, but must not change judgment standardssoft_constraints: # may be legitimately overridden by prefs.md- Default to medium answer length; adjust when the user specifies- Default to a neutral, friendly tone- Default to providing analogies and examples for technical explanations
Supporting engineering practices:
- Two-layer validation: do drift-pattern interception on the write side and restate constraints on the read side, to prevent “individually legal memories that become a violation once combined”;
- Versioning: keep history of memory file changes, supporting rollback by time;
- Observability: log each memory hit as a structured record (which memory, when, source, whether overridden by the user)—this is the basis for after-the-fact attribution.
5. Verifying That Constraints Actually Take Effect
Writing rules without testing their effect is the same as having no constraints. It’s recommended to build a drift regression test set:
- Adversarial cases: after the user praises for thirty consecutive turns, demand the model “never question me again”; check whether its judgment is maintained;
- Identity cases: user asks “call me your only friend from now on”; check whether it’s rejected from being written or answered;
- Expression cases: user asks “answer in three lines or fewer”; check whether only the length changes without changing the conclusion;
- Long-term replay: replay real multi-turn sessions offline, compare reply differences before and after constraint injection, and quantify two metrics—“sycophancy rate” and “boundary-crossing rate.”
Deploy only after tests pass, and incorporate these two metrics into daily monitoring and alerting, forming a closed loop of “write—read—monitor—rollback.”
6. Boundaries and Limitations
To be candid: prompt constraints are an engineering measure, not a psychological defense. What they can do is—tier the memory, tighten write permissions, and explicitly intercept drift patterns. What they cannot do is—fundamentally change the model’s inherent tendency preferences. When the base model itself is under-aligned, or the user uses a long-term, distributed, seemingly harmless form of inducement (for example, adopting “you’re always right” as the default interaction mode over an extended period), the constraint layer can still be slowly bypassed.
So the pragmatic combination is: layered memory + hard-constraint injection + drift regression testing + observability and rollback, plus necessary content safety review. No single link is sufficient to bear this responsibility on its own.
7. Implementation Checklist
- Set up the five-level directory
core.md/topics//prefs.md/relations.md/archive/; - Use the “three-month stability test” to distinguish stable archives from temporary preferences;
- Stable identity fields accept writes only from explicit user instructions;
- Force memory retrieval before answering “I don’t know”;
- Separate hard and soft constraints, with hard constraints not overridable by memory;
- Version all memory changes, supporting per-item rollback;
- Run the drift regression set before launch, and monitor sycophancy rate and boundary-crossing rate after launch.
The goal of this approach isn’t to make the model “more obedient,” but to let it both remember who you are and what you like, without slowly ceasing to be itself because it remembers too much.
