Tiered memory: core, recent, and archive layers
Tiered memory splits what an agent remembers into a small core, a recent store, and a large archive, moving items between them. Use it when history is far larger than the context window.
Tiered memory in 60 seconds
- What: memory split into layers by how often it is needed: a small always-present core, a recent store, and a large archive.
- Why: the context window is limited and costs money on every call, but an agent may need to remember far more than fits.
- How: the core stays in the prompt, items move outward when they go cold, and move inward when they are needed again.
- Best for: long-lived assistants and agents with large amounts of history, where only a small part matters at any moment.
- Watch for: the wrong things being demoted, silent loss during summarising, and the extra calls that moving items costs.
Where this type fits
Tiered memory is an organisation type. The other memory types describe what is stored (facts, events, methods). Tiered memory describes where it is stored and how it moves. A tiered system can hold semantic, episodic, and procedural items in its layers. The MemGPT paper (Packer et al., 2023) borrowed the idea from an operating system's virtual memory, and the Types of memory hub places it with shared memory in the "organisation" family.
The problem it solves
A long-running assistant collects history quickly. After a few weeks there may be thousands of turns, hundreds of facts, and many finished tasks. The model can read only what is in its prompt. Pushing everything in is impossible once it exceeds the window, and expensive well before that. Models also use long prompts unevenly. The Lost in the Middle study (Liu et al., 2023) found that information at the start or end of a long context was used more reliably than information in the middle.
Dropping old turns solves the size problem but loses things that still matter, like the user's name or the goal of the project. Searching an archive on every call solves it differently, but adds latency and may miss the thing that should always be known. Neither extreme works alone.
Tiering gives each item the treatment its use deserves. Things needed on every call are pinned in the core. Things needed often are kept close and cheap to fetch. Things needed rarely are archived and found by search. The prompt stays small, and the agent can still reach the past.
How it works
- Core tier: a small block always placed in the prompt. It holds the agent's role, the user's goal, and a few pinned facts. It has a hard size limit, such as 800 tokens.
- Recent tier: a store of recent turns, summaries, and active notes. Relevant items are retrieved into the prompt on each call.
- Archive tier: a large vector or text store of everything older. It is searched only when the agent decides it needs it, or when a trigger fires.
- Demotion: when the core or recent tier passes its limit, the least useful items move outward. Turns are summarised on the way, and the summary replaces the detail.
- Promotion: when an archived item is retrieved and proves useful, or a fact is used repeatedly, it moves back inward.
- Control: either your code decides the moves by rules, or the model decides through memory tools such as "save to archive" and "search archive". Rules are predictable. Model control is flexible but can fail.
Read the picture from left to right as cost and size. The core is smallest and most expensive per token, because it is paid for on every call. The archive is largest and cheapest, because you pay only when you search it. The solid arrows below show demotion, which happens as space runs out. The dashed arcs above show promotion, which happens when use shows an item matters.
The MemGPT paper describes a similar arrangement. A limited main context holds what the model sees, and external storage holds the rest, with the model calling functions to move information between them. You can build the same shape with simple rules and no special model behaviour.
A worked example
Acme Health runs a coaching assistant that has talked with a member for four months. The core tier (limit 800 tokens) holds: the member's name, "goal: run a 10 km race in March", "avoid: knee-impact exercises", and the coaching style.
Today the member writes: "My knee felt fine after Tuesday's session, can we add hills?" The agent builds the prompt from the core, plus a search of the recent tier. The search returns a summary of last week: two sessions with light intervals, and a note that the member reported mild knee soreness on Sunday. The agent also needs to know what happened in the previous injury scare in October, so it calls an archive search for "knee pain". It finds an October note saying that hill work caused a flare-up. The agent answers that hills are reasonable only as gentle inclines, and proposes one session this week with a check-in afterwards.
Two moves follow. The October note was useful, so it is promoted to the recent tier for the next month. The oldest items in the recent tier, from week one, exceed the 20 000 token budget, so they are summarised into a four-line note and the detailed turns are archived. The member's core goal stays untouched.
{
"core": ["name: Sam", "goal: 10 km race in March", "avoid: knee-impact exercises"],
"recent": [{"id": "r-118", "text": "Light intervals twice last week. Mild knee soreness Sunday."}],
"archive_hit": {"id": "a-0412", "text": "October: hill work caused knee flare-up.", "promoted_to": "recent"}
}Building it
This sketch uses rule-based moves, which are easier to test than model-driven ones. Each tier has a size limit, demotion summarises before archiving, and promotion is capped so one search cannot flood the recent tier. The helpers are placeholders.
# Placeholders: llm.generate(), embed(), count_tokens(), archive (a vector store).
CORE_LIMIT = 800 # tokens; the core is paid for on every call
RECENT_LIMIT = 20000 # tokens; above this, demote the oldest items
MAX_PROMOTE_PER_QUERY = 2 # one search must not flood the recent tier
MAX_ARCHIVE_RESULTS = 5
RECENT_TTL_DAYS = 30 # recent items not used in 30 days are demoted
class TieredMemory:
def __init__(self):
self.core = [] # short strings, pinned
self.recent = [] # dicts: text, last_used, uses
def pin(self, fact):
if count_tokens(" ".join(self.core + [fact])) > CORE_LIMIT:
raise ValueError("core is full; unpin something first")
self.core.append(fact)
def add_recent(self, text, now):
self.recent.append({"text": text, "last_used": now, "uses": 0})
self._demote_if_needed(now)
def _demote_if_needed(self, now):
# Oldest, least-used items go first.
while sum(count_tokens(i["text"]) for i in self.recent) > RECENT_LIMIT:
self.recent.sort(key=lambda i: (i["uses"], i["last_used"]))
item = self.recent.pop(0)
summary = llm.generate("Summarise in 2 lines: " + item["text"])
# Keep the full text in the archive so nothing is lost silently.
archive.put(text=item["text"], summary=summary, vector=embed(summary))
def search_archive(self, query, now):
hits = archive.search(vector=embed(query), top_k=MAX_ARCHIVE_RESULTS)
for h in hits[:MAX_PROMOTE_PER_QUERY]:
self.recent.append({"text": h["summary"], "last_used": now, "uses": 1})
self._demote_if_needed(now)
return hits
def build_prompt(self, task, recent_hits):
parts = ["Always know:", *self.core, "Recent notes:", *recent_hits]
return "\n".join(parts) + "\n\nTask: " + taskDesign decisions
- Number of tiers: two is often enough. Default: start with core plus one searchable store, and add a third tier only when the store gets large.
- Who moves items: rules or the model. Default: rules for demotion and expiry, and an explicit "search archive" tool for the model, so behaviour is testable.
- Core size: keep it small and curated. Default: under 1 000 tokens, with a limit enforced in code and a person-approved list of pinned facts.
- Summarising on demotion: it saves space but loses detail. Default: archive the original and keep the summary as the retrieval handle, so detail can be recovered.
- Placement in the prompt: because models use the middle of a long context less reliably, put the core at the start and the most relevant retrieved items near the end.
- Latency and cost: archive searches add a round trip, and summarising adds model calls. Default: demote in the background and search the archive only on a trigger.
- Access control and retention: tiers can hold personal data. Default: scope every tier by user, give the archive a retention period, and support deletion across all tiers.
Measuring it
- Recall of needed facts: on test conversations, the share of required facts present in the prompt when needed. Build the test by planting facts early and asking about them later.
- Core hit rate: how often pinned items were actually used. Items never used should be unpinned.
- Archive precision: of the items retrieved from the archive, the share that was judged useful. Low precision means the summaries or the embedding choice need work.
- Tokens per call: average prompt size, compared with a full-history baseline. This is the saving the design promises.
- Demotion errors: cases where an item was demoted and then needed urgently. Count them by reading failures.
def needle_test(agent, facts, filler_turns, questions):
# Plant facts, add filler to force demotion, then ask. Returns recall in 0..1.
for f in facts:
agent.tell(f)
for t in filler_turns:
agent.tell(t)
correct = sum(1 for q, answer in questions if answer in agent.ask(q))
return correct / len(questions)When to use it, and when not to
| Situation | Use this type? | Why |
|---|---|---|
| A long-lived assistant with months of history | Yes | No single prompt can hold it, but some of it must stay reachable. |
| A few critical facts must be known on every call | Yes | The core tier guarantees they are present. |
| History is large but each question needs only a small part | Yes | Search plus a small core keeps prompts short and cheap. |
| Short sessions that end quickly | No | Session memory is simpler and enough. |
| The whole history already fits in the window at low cost | No | Moving items between tiers adds work for no gain. |
| Exact, complete recall is legally required | Only with care | Summaries lose detail, so keep originals and test recall. |
Trade-offs
| Dimension | Effect | What to do about it |
|---|---|---|
| Quality | Keeps the right things in view, but can lose detail on demotion | Archive originals and test recall with planted facts. |
| Latency | Archive searches add a round trip | Search only on triggers and keep the recent tier fast. |
| Cost | Fewer prompt tokens, but more summarising and storage | Demote in batches in the background. |
| Complexity | Several stores and movement rules to maintain | Begin with two tiers and rule-based moves. |
| Failure modes | Wrong item demoted, stale pinned facts, hidden data growth | Review the core regularly, log moves, and set retention limits. |
Compared with related types
Working memory is the context window itself, which is the core tier plus whatever is retrieved into it. Session memory keeps history for one conversation, usually without tiers. Tiered memory is the step up when history outlives the session and outgrows the window.
Shared memory answers a different question: who may read and write the store. A tiered system can be private to one user or shared by a team, so the two ideas often combine.
What this means for your role
Common mistakes
Further reading
- Types of memory: the hub page for all memory types.
- MemGPT, Packer et al., 2023: borrows the idea of an operating system's virtual memory, moving information between a limited main context and external storage.
- Lost in the Middle, Liu et al., 2023: models used information at the start or end of a long context more reliably than information in the middle.
- Working memory (the context window): what the core tier lives inside.
- Inference serving: why every prompt token has a cost.
Tiered memory keeps the prompt small without making the past unreachable. Pin little, archive the originals, and test that planted facts survive.