Designing Agent Memory
Store what the agent needs to continue accurately, not everything it has ever seen. Long context can still lose important constraints among irrelevant messages.
#Three distinct stores
Working context contains the current request, recent observations and relevant instructions. Task state tracks completed steps, unresolved blockers and artifact locations. Long-term memory keeps reusable, verified facts across sessions.
A sliding message window is simple but can discard an early constraint. A summary compresses context but can distort uncertainty. Keep critical rules and task status explicitly structured instead of relying on either method alone.
#Retrieval is selective memory
RAG can retrieve past decisions or document passages when needed. Store source, timestamp, owner, access level and version with the text. Hybrid keyword/vector retrieval can help with exact identifiers as well as semantic questions, but evaluate it against your own data.
Permissions, balances and account settings are exact operational facts. Read them from their authoritative structured records; a vaguely similar vector result is not a safe substitute.
#Memory must expire and change
Support corrections, deletion and retention policies. A previously correct fact may be stale after a policy or product change. Record verification status so a summary does not turn an old hypothesis into current truth.
Before writing a durable memory, ask whether it is necessary, authorized and useful later. Treat content proposed by a model or retrieved from the web as untrusted until checked. Never store secrets in general retrieval indexes.
#Start small
A lightweight system can use bounded recent context plus a structured task record. Add a persistent conversation store when restart recovery is required, then retrieval when cross-session knowledge reuse becomes measurable. Test two users, conflicting updates, deletion and an old memory that must no longer influence an answer.