Agent memory: separate facts, preferences and temporary state
In this article (5 sections)
“Memory” often combines different records that should not share authority or lifetime. A policy fact, a user’s style preference and the current draft step need different sources, validation and deletion.
Classify every record
The agent controls lab creates three synthetic records.
from agent_cases import memory_case
result = memory_case()
assert result["classes"] == ["fact", "preference", "temporary_state"]
assert result["all_have_source"] is True
assert result["all_have_expiry"] is True
print(result["records"])The fact cites a policy and expires on supersession; the preference cites user settings; temporary state belongs to one run and expires at run end.
Give each class its own contract
Facts require an authoritative source, effective date and freshness. Preferences require authenticated user scope and edit/delete controls; they cannot override policy. Temporary state requires run ID, schema and checkpoint lifetime.
Do not promote model summaries into durable facts automatically. A retrieved document cannot write a user preference. Apply tenant/access boundaries before reading memory and minimize sensitive content.
Test conflicts and forgetting
Create a newer policy, changed preference and cancelled run. Verify the old fact is no longer current, the new preference affects only that user and temporary state is removed. Define behaviour when sources conflict or expire.
The Generative & Agentic AI course connects memory classes to data contracts, privacy and state recovery.
Exercise
Design a memory schema with provenance and expiry for all three classes. Inject cross-user access and a policy/preference conflict, then demonstrate fail-closed resolution and deletion.
Continue learning
This article is part of the Agent workflows and state sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Review the prerequisite or neighbouring task in Tool errors: distinguish retryable and permanent failures.
- Continue with Test a multi-agent handoff against a single-agent baseline.
Reference: LangGraph memory overview.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our Generative & Agentic AI programme — 3 months. Add practical GenAI, retrieval and agent-building skills to your existing toolkit.
Explore Generative & Agentic AI