pgmem
Concepts

Concepts

The mental models behind pgmem — read these before building.

pgmem manages memory in levels — six of them — and keeps the active levels strictly apart from the durable ones. This section explains those levels and the rules that keep you out of trouble. Start with the map below, then the mental model.

How to read these docs. Understand the model first: the four essentials in The mental model prevent the common mistakes, and Going deeper covers the mechanisms. Then build — Guides are copy-paste tasks, Reference is the exact API, Operations is running it in production, and Examples are runnable apps.

The memory levels

Everything pgmem holds sits in one of six levels. Tiers 1–2 are execution state — scoped to the current session and never reused as memory. Tiers 3–5 are memory — they outlive the session under explicit policy. Tier 6 is live context — present in the prompt but never stored.

TierLevelHoldsLifetime
1Working memoryRecent turns, pins, active tool outputCurrent session
2Execution stateThe active path — the MAGE treeCurrent session
3EpisodicSession facts, decisions, commitmentsSession → promotion
4SemanticThe durable knowledge graphCross-session
5NarrativeSagas — stories across sessionsCross-session
6Live contextSystem-of-record state, injected at compile timeNever stored

Only retrieval reads across these levels on the turn; forming and promoting memory happens off it. For the full picture see The five-tier model and How a turn flows.

The mental model

The four ideas a developer needs before writing a line of pgmem. Skip these and you'll fight the tool; internalize them and it gets out of your way.

Going deeper

The mechanisms behind the model. Read these when you're tuning behaviour or want to know exactly how something works.

Before you ship

On this page