Agent state is a layered cake: ephemeral context for one turn, conversational memory for the session, long-term memory for the user, system state for the agent itself. Each layer has different requirements. Conflating them is the #1 cause of bad agent UX.

Advertisement

Turn-level: prompt context

What's in the model's context window this turn. Includes system prompt, history (truncated), retrieved knowledge, last tool result. Fits in tokens budget; nothing else.

Session: conversation memory

All turns since session start. Often summarized periodically to fit context. Stored in fast KV (Redis, DynamoDB). Tied to session ID, expires when session ends.

Advertisement

User: long-term memory

Persistent facts about user: preferences, past interactions, history of resolved issues. Vector DB for semantic retrieval, structured DB for facts. Updated by the agent ('the user said they prefer X') with optional confirmation.

Agent: operational state

Counters, rate limit windows, error logs, version pinning. The boring infra state that lets the agent run reliably. Not visible to the model; lives in monitoring/ops systems.

Patterns to avoid

One giant blob of state passed each turn (token waste). Hidden long-term memory writes the user can't see/correct (creepy). No expiry policy (long-term data piles up). Conflating session and user memory (loses cross-session context or loses session privacy).

Four layers: turn, session, user, ops. Each persistent at the right scope. Make long-term memory user-visible and editable.