Agent memory

1 min read
On trails:AGENTSstep 5/9

Memory is what makes an agent stateful (see the design principlesAgent design principlesFour properties that make a loop an agent: goal-directed, reactive, stateful, autonomous.Opens in a new tab). It comes at two scales: short-term, which lasts for one conversation, and long-term, which outlives it.

Short-term

Short-term memory is thread-scoped: the message history of the conversation in progress. It lives in the context window, so it is finite and has to be trimmed or summarized when it grows (see overflow managementContext overflowWhen the history outgrows the window: cut the oldest, or summarize them.Opens in a new tab). A new thread starts empty. In LangGraph a checkpointer keeps it, addressed by a thread id.

Long-term

Long-term memory is stored across sessions and shared across threads. The LangChain docs split it into three kinds.

KindHoldsExample
SemanticFacts and conceptsThe user prefers dark mode
EpisodicPast events and actionsA past run kept as a few-shot example
ProceduralRules for performing tasksThe agent's prompt and instructions
Table 1: long-term memory

In LangGraph this is a store, kept apart from the thread. What gets pulled into the prompt on each step is the job of the context assemblerThe context assemblerThe step that builds the prompt from scratch on every loop.Opens in a new tab.


Sources