AI Agents Engineering · Memory, Eval, Safety & Production · Lesson 1 of 3
Memory, RAG & context management
In production, most agent failures trace back to what was (or was not) in the context window. Managing context is the core craft: too little and the agent is ignorant; too much and it is slow, expensive, and distracted.
- RAG for agents: retrieve relevant docs/records into context on demand rather than stuffing everything up front. The agent can call retrieval as a tool.
- Long-term memory: persist facts, user preferences, and past outcomes to an external store; retrieve the relevant slice each run.
- Context compaction: summarize or drop stale turns; keep the goal, recent state, and salient facts. Watch for 'context rot' as windows fill.
- Just-in-time context: prefer fetching a record when needed over pre-loading the whole database — cheaper and less distracting.
Context is a working deskTreat the window like a desk, not a warehouse: keep the few documents you are using now within reach, file the rest, and clear finished work — or you cannot find anything.
Name the discipline: context engineeringThis craft is now called context engineering — prompt engineering is a subset. The four verbs: Write, Select, Compress, Isolate. Interview-grade vocabulary: attention budget, context rot, compaction, just-in-time context, progressive disclosure. And for long-running agents, file-based, agent-managed memory (notes, progress files, git state) has become the default — compaction is the lossy last resort.
◆ Lock it in
- Most agent failures are context failures — manage the window actively.
- Use RAG + long-term memory to bring in the right slice just in time.
- Compact old turns; keep goal, state, and salient facts to avoid context rot.
Feynman drill — say it out loudExplain how RAG and long-term memory keep an agent's context small but sufficient.
Step 1 rate your confidence · Step 2 pick your answer
Why is aggressive context management important for agents?
Step 1 — how sure are you?