pgmem
Concepts

Execution state vs memory

Why the active path is never reused as memory.

The most important boundary in pgmem is between execution state — the agent's live working set for the conversation it's in right now — and memory — what should outlive that conversation. Execution state has a lifecycle and is sealed when the session ends; memory is explicit, attributed, and retrieved into each new session. Blur that line and the agent acts on yesterday's half-finished plan as if it were settled.

Why it matters

A long-running agent that treats its whole history as one undifferentiated context fails in two ways: the window fills with stale reasoning that drowns out what matters, and a restarted process picks up an abandoned plan as if it were settled fact. pgmem refuses to blur the two. Execution state answers "what am I doing?" and is scoped to the current session. Memory answers "what is true / was decided / happened before?" and is the only thing carried across sessions — deliberately, under policy.

The boundary

Execution stateMemory
Tiers1 (working) · 2 (execution tree)3 (episodic) · 4 (semantic) · 5 (narrative)
ScopeThe current sessionAcross sessions
LifecycleSealed at session.end(), never reusedPromoted, retained, retrieved
In the promptAlways present (Tier 2 is never dropped)Retrieved under budget, droppable

Working memory (Tier 1) is the recent turns and pins. The execution tree (Tier 2, "MAGE") is the active path through topics, decisions, and open questions — maintained as the conversation moves and compacted as it grows.

How it works

Every session starts with a fresh execution tree. When the conversation needs prior context, pgmem retrieves memory into that tree — the relevant saga, past decisions, facts — but it never rehydrates an old execution trace. When the session ends, its working and execution state are sealed for audit, and eligible episodic memory is promoted into the graph. The next session is new again.

This is why continuity across conversations is create + retrieval, not resume:

# A new conversation: fresh execution tree, memory pulled back in.
session = await mem.session.create(group_id="acme", user_id="customer-123")
context = await session.compile_context(query="Can we continue where we left off?")
# The saga, prior decisions, and facts are retrieved — not an old execution trace.

Tradeoffs & pitfalls

resume() is not "continue the previous conversation." It re-opens a session that was interrupted mid-flight — a crashed voice worker picking up the same call. For continuity across separate conversations, create a fresh session and let retrieval do the work.

  • The cost of the boundary is that durable knowledge must be formed — an observation isn't memory until it's remembered and promoted. See Trust & memory formation.
  • Execution state is small and always in the prompt; the memory tiers are what you spend retrieval budget on.

On this page