▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
AI Agents in Production · Lesson 5 of 14 · 2 min read · 5 min video
Memory and state
Short-term context, long-term memory and checkpoints that let a run resume safely.
📄 Download slides (PDF)· free sign-upLLMs forget everything between calls. Every bit of "memory" an agent has is something your code saved and fed back in. Designing that deliberately is what makes agents feel smart instead of forgetful.
Three kinds of memory
- Short-term (working) memory: the messages in the current run. Limited by the context window and by cost
- Long-term memory: facts saved across sessions: "This customer prefers Telugu" or "This shop is closed on Mondays". Stored in a database and retrieved when relevant
- State: where a task is: which steps are done, which tool results came back, what's waiting for approval
Keeping context small
Long runs fill the context window, and every token costs money on every step. Common fixes:
- Trim: drop old tool results once they've been used
- Summarise: replace the early conversation with a short summary
- Retrieve: keep long-term facts in a store and fetch only the few that matter (RAG for memory)
Checkpoints
Save the agent's state after each step:
If the server crashes at step 6, you resume from step 6, not from the start. Checkpoints also make human approvals and debugging possible, because you can see exactly where a run was.
What not to remember
Don't save everything. Save facts that are useful, stable and allowed: no passwords, no card numbers, and nothing the user asked you to forget. Under India's DPDP Act, users can ask you to delete their data, so design for that from day one.
In one line
Agents only remember what your code saves: keep working context lean, store long-term facts deliberately, and checkpoint state after every step.
Share with a friend