AI Agent Memory: Short-Term Context, State and Long-Term Storage

AI agent memory is information retained for use beyond the current model call. Short term memory supports an active conversation or task. Long term memory can preserve selected information across sessions. Application state records authoritative facts about the workflow and its effects.

These categories should not be conflated. A conversation summary saying “the refund was issued” is not equivalent to a payment service confirmation.

Separate four kinds of retained information

KindExampleAppropriate treatment
Recent conversationThe customer's latest correctionPreserve exact wording where it affects the task
Working stateCurrent goal, pending step and unresolved issueStore with the run and update deliberately
Long term memoryA confirmed communication preferenceScope to the user and support correction or deletion
Authoritative business stateOrder status or completed paymentRead from the responsible system

A provider managed conversation can preserve messages between calls, while another interface may require the application to resend them. In either case, persistence and context selection are system behaviours rather than proof that the model has learned a new permanent fact.

Store provenance with the memory

A useful memory record identifies its subject, content, source, verification status and relevant dates.

{
  "subject_id": "customer_184",
  "kind": "communication_preference",
  "value": "Prefers email for delivery updates.",
  "source_id": "message_772",
  "basis": "explicitly_stated",
  "recorded_at": "2026-09-25T14:30:00Z",
  "review_after": "2027-03-25"
}

This is an illustrative record, with an illustrative review interval. The right retention policy depends on the information and product.

Distinguish observations from inferences. “I am in a hurry today” does not establish a permanent preference for short answers. A model generated inference should not silently become an approved profile fact.

Decide what may be written

Define eligible memory types and the evidence needed to create them. Sensitive or unnecessary information should not be saved merely because it appeared in a conversation.

Memory writes need subject and tenant checks. An assistant handling two accounts must not store one person's information under another person's identity.

Keep correction and deletion paths. If a preference changes, record which value is current and prevent the superseded value from being retrieved as active guidance.

Retrieve memory for the present task

A memory store should be queried selectively. Loading every saved statement into every call increases exposure and makes relevance harder to assess.

Filter by the authenticated subject, task and validity before ranking. Include only the information needed for the current decision. A preferred contact method may matter when preparing an update; an unrelated purchase history may not.

LangGraph's memory documentation illustrates separate short term state and long term storage mechanisms. The storage mechanism still needs an application specific policy for what is retained and read.

Suppose a customer prefers email updates and asks about a refund. The assistant needs both the saved preference and the current payment record, but those records support different decisions.

Memory and authoritative state serve different purposesSaved communication preferenceUse email for order updatesCurrent payment service recordRefund status and transaction IDContext for this requestRelevant facts from both sourcesRetain each fact’s source and date
A saved preference can guide communication, but it cannot establish that a payment happened. Read payment status from the responsible service and retain that distinction when assembling context or summarising a conversation.

Treat compaction as a derived view

A conversation summary is a lossy representation of source material. Preserve the original records when the product's retention rules permit, and retain links from important summary facts to their sources.

Test summaries for identifiers, amounts, corrections, commitments and unresolved conflicts. A summary can be short and fluent while removing the fact that changes the answer.

Do not let compaction rewrite the record of completed actions. Store action IDs and execution status separately so a resumed agent can establish what happened without relying on prose.

Test memory across sessions and failures

Useful cases include a corrected preference, an expired observation, a process restart and two users with similar names. Verify that the agent retrieves the right subject's current information and recognises unresolved work.

For write actions, idempotent execution prevents a resumed run from repeating an already completed effect. Memory supports continuity; authoritative state establishes what the system has actually done.

Where this is examined
Prompt and Context Engineering
AI Agents and Tool Calling, 18 per cent of the exam.
Related material
Book
AI Engineering, On what an agent keeps between turns and between sessions.
Book
Designing Data-Intensive Applications, On state, durability and what survives a process ending.
Concepts