Rob Pitkin

On memory and agents: the Unified Theory of Agentic Memory

agentic_memory_consolidation

After reading Anthropic's post on "The components of agent memory", I spent some time thinking abstractly about agentic memory and what it means for an agent to "remember" something. In the LLM space, "memory" tends to mean agent-written markdown files that help agents at runtime remember user preferences, architectural patterns, and generally anything the agent deems relevant enough to write down. In the RL space, "replay buffers" are the canonical example of agent memory - buffers that store agent experiences and are almost exclusively used during training and then discarded. I found it interesting how agentic memory for LLMs is generally used at inference time but not during training, while for RL it's the opposite. In trying to reconcile these two approaches to memory, I realized both share a common framework of implicit memory (the model weights, what the agent knows inherently) and explicit memory (experiences stored separately from the agent that can be used to make decisions). With this framework in mind, which I'm calling the Unified Theory of Agentic Memory, all agents maintain implicit and explicit memories, even if they go unused.

The Unified Theory of Agentic Memory

On the human level, I like to think of implicit memory as our long-term memory and explicit memory as our short-term memory. Over time, our memories get fuzzier and it becomes harder to remember exact details about our experiences, but we still use our old memories to inform future decisions since they shape how we perceive and understand the world. However, in the short term, human memories are much clearer and we can map current situations to similar experiences we've just had. As a result, utilizing short-term memories becomes less about internalizing experiences and more about remembering how an experience played out and what we might do differently.

Mathematically, we can model an agent's memory at time t as a coupled state split across two mediums:

Ψt=(θt,Mt)

Every explicit memory mi∈Mt can be modeled as a tuple of a searchable key ki=ϕ(ei), a stored payload vi, and a priority/relevance score pi:

mi=(ki,vi,pi)

Here the ϕ(ei) operator represents encoding a raw experience into some medium that can be stored externally (e.g. writing text to a markdown file or creating an entry in a replay buffer).

With this framing, I introduce four algebraic operators over the memory state for creating, updating, and interacting with memories:

  1. Store (write / 𝒲): Encode a raw experience et with initial importance p0(et) and write it to the external store:
𝒲(Mt,et)=Mt∪{(ϕ(et),et,p0(et))}
  1. Similarity (sim / 𝒦): A similarity function 𝒦(ka,kb)∈ℝ where larger values mean greater similarity (e.g. cosine similarity on text embeddings, or negative state distance −‖sa−sb‖ in RL).

  2. Recall / Replay (read / Precall): A probability distribution for pulling past memories back into active compute given the agent's current context qt:

mi~Precall(mi∣qt,Mt)
  1. Consolidate (update / reflect / delete / 𝒞): An operator that reorganizes memory over time by updating, compressing, or pruning explicit memories (Mt→Mt+1), or distilling them into implicit weights (θt→θt+1):
(θt+1,Mt+1)=𝒞(θt,Mt)

While the Store and Similarity operators are relatively straightforward, I think it's worth spending some time explaining the other two operators in more detail.

Recall, Replay, and "Spiked Information Gain"

When I think about how humans remember past experiences, it seems like we remember things that are both relevant and surprising. For example, if I'm baking cookies in my oven, I likely won't recall every time I used my oven or mixed ingredients together in a bowl. I will remember the time I touched a pan without an oven mitt and burned my finger, or the time I added a certain ingredient that made the cookies taste better - since these experiences are the most informative for the current situation. More formally, recall systems balance two questions:

  1. Relevance (𝒦(qt,ki)): "How similar is this memory to what I'm looking at right now?"
  2. Surprise (pi): "How different was it from what I expected?"

Relevance (𝒦) is a familiar concept in agentic systems - embedding similarity in a vector store or grepping a folder of markdown files. What's harder is quantifying surprise (pi). In RL, the canonical example of surprise is the temporal-difference (TD) error δt, which is just the difference between what the agent experienced and what it expected to experience:

pt=|δt|=|(rt+γVθt(st+1))−Vθt(st)|

Here rt is the reward from the environment, γ is a scalar discount factor, and Vθt(s) represents "the predicted value of being in state s". The first term of the difference is "the value of what actually happened + the predicted future value" and the second term is simply "the predicted value". A positive TD error indicates the agent received more reward than it expected and vice versa. In the cookie-baking example, burning my finger would be a negative TD error, and adding beneficial ingredients would be a positive TD error. However, notice in the above equation that we wrap the TD error in an absolute value, since for "surprise" we don't care whether it was a "negative surprise" (trauma) or a "positive surprise"; instead, we only care about the magnitude of the surprise to determine what experiences provide the most information. More generally, information theory formalizes this kind of belief-shifting "spiked information gain" as Bayesian surprise.

Now that we have a way to quantify both relevance (𝒦) and surprise (pi), we can combine them into a single probability distribution for recalling a memory mi given our current state qt and explicit memories Mt:

Precall(mi∣qt,Mt)=exp(βrel𝒦(qt,ki)+βsurlogpi)∑j=1|Mt|exp(βrel𝒦(qt,kj)+βsurlogpj)

This complicated-looking distribution is really just a softmax distribution that scores each memory by a weighted sum of its relevance and surprise, and then normalizes those scores so they sum to 1. βrel is the weight applied to relevance and βsur is the weight applied to surprise. Together these two "knobs" control how much an agent balances similarity and surprise. Modeling recall as a probability distribution (rather than a hard lookup) is what lets one equation cover both stochastic sampling in RL and deterministic retrieval in LLMs - and turning those two knobs recovers how both fields split:

Consolidation: Backpropagation and Reflection

Since the agent's memory state Ψt=(θt,Mt) is coupled, consolidation 𝒞(θt,Mt) breaks into two pathways:

(θt+1,Mt+1)=𝒞(θt,Mt)=(𝒞θ(θt,Mt),𝒞M(Mt;θt+1))

The first pathway involves replaying memories from Mt to slowly update weights θt:

θt+1=θt−η𝔼mi~Precall[∇θℒ(θt;mi)]

Viewed through this lens, supervised learning and LLM pre-training are just explicit memory consolidation - the dataset is Mt and backpropagation compresses it into fixed-size implicit weights θt, at which point Mt is discarded.

The second pathway involves using new or existing explicit memories to update, reflect upon, or prune memories from Mt, without changing θt. In practice, this looks like MuZero Reanalyze in RL or, more commonly, LLM agents updating markdown files or dreaming. Always-loaded files like AGENTS.md or CLAUDE.md sit right on the boundary between the two: physically they live in Mt as plain text, but because they condition every forward pass without a search step, consolidating experiences into them acts as a stand-in for updating frozen weights θt - effectively turning explicit text into tweakable parameters.

Putting the Framework to Use: The Missing Quadrant

As noted in the Recall section, there are four "quadrants" agents can live in depending on how they balance relevance and surprise (the values of the "knobs"). The fourth quadrant, "full agentic recall", fully leverages both, but we rarely see it in practice at inference time, if ever.

To explore this quadrant, specifically in RL, I wanted to come up with a way for an agent to query its replay buffer at runtime rather than just using the buffer to source batches of experiences for backpropagation. Normally, in value-based RL (like Q-learning with softmax action selection), the agent's implicit weights predict an expected return zθt(s,a) for each action and then sample an action via softmax. My first instinct was to look up all past experiences where the agent took action a (i.e. subset Mt(a)) and add their recalled return Gi directly onto that action's predicted value (with Precall normalized over Mt(a) so the weights sum to 1):

znaive(s,a)=zθt(s,a)+λ∑mi∈Mt(a)Precall(mi∣s,Mt(a))·Gi

However, once backpropagation updates θt, the weights have already learned the outcome of the action, so adding the raw return on top again would double-count it and skew the agent's policy. Instead of adding the raw return Gi, my next thought was to add only what the weights haven't learned yet - the difference between the observed outcome Gi and what the weights currently predict, zθt(s,a):

ztotal(s,a;Ψt)=zθt(s,a)+λ∑mi∈Mt(a)Precall(mi∣s,Mt(a))·(Gi−zθt(s,a))

where λ∈[0,1] is a scalar controlling the influence explicit memory has on the action logit.

Intuitively, this works like instant bootstrapping that fades over time. Immediately after a "surprising experience", the weights haven't moved yet, so the explicit residual, Gi−zθt(s,a), carries 100% of the signal and gives the agent a one-shot reflex. Over time, as consolidation updates the weights, backpropagation slowly pulls zθt(s,a) toward Gi, which means the residual tends toward zero at the same rate. Once the residual reaches zero, the explicit memory term vanishes - avoiding the double-counting issue the naive approach has.

To see this gradual residual handoff in action, I created a simple 3x5 Cliff-Walking gridworld, where there's a reward of -0.1 per timestep, -10 if the agent falls off the cliff, and +10 if the agent reaches the goal state:

cliff_gridworld

I compared two tabular Q-learning agents using softmax action selection, averaged over 40 seeds. Both start with zero-initialized Q-tables (Qθ0=0) and run the exact same prioritized replay consolidation after each episode - the only difference is that one agent queries Mt at runtime using the residual equation above (λ=1), while the other agent uses standard Q-learning and only relies on Qθt:

memory_handoff_demo

On top, runtime recall boosted early performance - since past experiences are immediately available to the agent - and helped it converge faster as a result. On the bottom, you can see the action-values for stepping off the cliff over time, and notably, the implicit Q-value and explicit residual change at equal and opposite rates and always sum to the true value, -10.

This is a toy gridworld, not a frontier benchmark, but it shows how applying the unified framework lets us explore new algorithms or reframe existing ideas through a different lens. In fact, the way we combine the network's prediction with the buffer's recalled value turns out to be the exact same formula used in DeepMind's Ephemeral Value Adjustments (EVA). If we let Qexplicit(s,a) denote the recalled return from Mt(a) and expand zθt+λ(Qexplicit−zθt), we get:

ztotal(s,a)=(1−λ)zθt(s,a)+λQexplicit(s,a)

which is the exact weighted-average form from the EVA paper (just with a simpler way of computing Qexplicit).

Rethinking How We Evaluate Agent Memory

Most LLM memory benchmarks today, such as LoCoMo, are focused on recall - testing flat storage and similarity lookup (our 𝒲 and 𝒦 operators) with βsur=0. Even newer benchmarks like LongMemEval that add temporal reasoning and knowledge updates still mostly treat memory as a passive database to reason over rather than an active learning loop.

Under the Unified Theory of Agentic Memory, evaluating an agent's memory system means testing all four operators together:

Returning to the question I started with: what does it mean for an agent to "remember" something? It isn't just logging the past into markdown files, or replaying a buffer during training and throwing it away. Remembering is the full loop between explicit and implicit memory - capturing what was surprising, recalling it when it matters, and letting it reshape what to do next.