Why this matters
Agents and AI pipelines run for seconds to hours. Without explicit state and durability, a crash, deploy or timeout loses the work (and the money spent on it), and memory features can leak one user's data into another's context.
Core ideas
- Short-term memory: the conversation so far, trimmed or summarised to fit the context window.
- Long-term memory: facts and preferences extracted from past sessions and retrieved when relevant (a RAG problem over the user's own history). Temporal knowledge graphs (like the open-source Graphiti library behind Zep) store facts with validity over time.
- Agent state: an explicit, typed object (messages, plan, intermediate results, step count, budget used), not just an ever-growing message list.
- Checkpoints: saving state after each step, so a run can resume, be inspected, or wait for human input.
- Durable execution: workflow engines (Temporal, cloud durable-function services, Vercel Workflows and similar) persist each step's result; after a crash, the workflow replays to where it was and continues without re-running completed steps.
How to do it
- Scope every memory record by user and tenant; retrieval applies the same filters as any RAG (Q8).
- Let users see and delete what's remembered about them.
- Store agent state in a database (or the framework's checkpointer), keyed by run ID.
- Make every step idempotent and save paid model outputs before parsing ("never pay twice", P1).
- Use a durable workflow when a process has many steps, external waits (human approval, webhooks), or runs longer than a request.
run_id → step 1 extract (saved) → step 2 validate (saved) → step 3 wait for approval (hours)
→ crash/deploy → resume at step 3 → step 4 write (idempotency key) → done
Common mistakes
- Unbounded conversation history, so cost grows each turn until the context overflows.
- Memory shared across users by a missing filter.
- In-memory state in a web process, lost on restart.
Interview follow-ups
- "How do you keep long conversations within the context window?" Keep recent turns verbatim, summarise older ones, retrieve relevant past facts, and drop tool outputs once summarised.
- "An agent run crashed at step 7 of 10. What happens?" With checkpoints, resume from the step 7 state; completed paid calls are reused from saved outputs, not re-run.
Check yourself
What's the difference between short-term and long-term memory for an assistant?
Short-term is the current conversation in the context window (trimmed or summarised). Long-term is information persisted across sessions and retrieved when relevant, which needs scoping, retention and user control like any personal data.
When do you need a durable workflow engine instead of a queue?
When a process has many dependent steps, long waits (human approval, external callbacks) or must resume exactly where it stopped after failures, with each completed step's result preserved.
Build it
Add checkpointing to your agent so a run can be killed mid-way and resumed without repeating completed tool calls or model calls.