01Budget the window
Allocate space among policy, task instructions, current user input, recent turns, retrieved knowledge, tool results, and output headroom. Truncate by semantics, not raw oldest-first token count.
Assemble context as a budgeted input: trusted instructions, user request, selected history, evidence, tool observations, and output headroom. If the maximum window is 16k tokens and output needs 2k, the input cannot consume all 16k. Token counts vary by tokenizer, so measure with the intended setup rather than assuming characters map uniformly to tokens.
More context is not automatically more useful. Duplicate passages, old tool results, and conflicting instructions can distract from decisive evidence while increasing prefill work. Rank context by task relevance and authority, keep source labels, and preserve the details needed to justify the next action. Test a shorter evidence-focused version against a longer one instead of treating window size as a quality strategy.
- Keep critical instructions stable and visible
- Summaries lose detail and can encode mistakes
- Large tool results should be compacted or referenced
02Memory is selective persistence
Separate ephemeral task state, conversation summaries, explicit preferences, and inferred facts. Store provenance, timestamp, confidence, sensitivity, and scope. Retrieve by relevance plus recency and policy.
Application memory needs a write policy as well as retrieval. Distinguish a user preference, an event record, a derived summary, and an attempted instruction in an untrusted document. Store provenance, subject, tenant, creation time, expiry, and consent or policy basis where relevant. A statement should not become a durable instruction just because it appeared in a conversation.
A memory read is also an authorization decision. Retrieve only the current user's permitted scope, apply freshness and sensitivity rules, and retain enough provenance to explain or delete the item. The model only sees the retrieved subset; the database remains authoritative. Support correction and retraction, including invalidating derived summaries that would otherwise reintroduce a deleted preference.
- Do not store everything said
- Let users inspect/correct/delete durable memory
- Avoid carrying preferences across incompatible contexts
03Reconcile contradictions
New information can supersede old, sources can disagree, and summaries can drift. Use versions and provenance, prefer explicit recent user statements, and ask when conflicts materially affect action.
Compaction is lossy. “Use vendor A” may preserve a decision while losing the condition “only if data remains in the EU.” Keep constraints, rejected alternatives, evidence versions, unresolved questions, and effect identities alongside summaries. Evaluate compaction by asking whether the next correct decision is still possible, not whether the shorter text sounds coherent.
When memory conflicts with current evidence, do not silently merge it into a confident answer. Compare authority, scope, and time; ask the user when the conflict cannot be resolved safely. A current explicit preference may replace an older one, while a user preference cannot override organizational access policy. Design invalidation and contradiction handling as application rules that can be tested.
- Context rot is quality degradation, not only overflow
- Compression checkpoints need validation
- Sensitive memory deserves stricter defaults