Agentic AI 3 min

Agent Memory: In-Context, External, Procedural

How agents remember what they have done and what they know across multiple tasks.

Agents need memory to stay useful across steps. In-context memory is what sits in the current prompt. External memory is persisted data in a store, fetched only when relevant. Procedural memory is task policy and learned workflow structure, like system instructions and tool-use rules.

Use the Right Memory for the Job
Keep short-term reasoning in context. Store durable facts and user preferences externally. Keep operating rules in system instructions and tool policies.

Here is the failure mode in concrete terms: a standard chat completion API is stateless, so every single turn re-sends the entire conversation history. If you never summarize or externalize anything, the prompt you pay for at turn 20 contains all 20 turns, and you paid for the growing prefix on every one of those 20 calls, not just the last one. Try it below.

Interactive: Context Growth Simulator
Memory Strategy

Every chat-completion API call is stateless: the full conversation is re-sent on every turn. Drag the slider to see what that does to your prompt size and bill, with and without external memory.

All-in-context (no external memory)
Prompt at turn 12: 2,160 tokens
External memory + rolling summary
Prompt at turn 12: 580 tokens
$0.042
cumulative billed cost, all-in-context
$0.019
cumulative billed cost, external memory
2.2x more expensive with everything kept in-context over 12 turns, because you re-pay for the entire growing history on every single request, not just the final one. Cost grows roughly with the square of conversation length, not linearly with it.

The fix is not 'use a smaller model,' it is architectural: keep only the last N turns verbatim, and replace anything older with a periodically-updated summary of fixed size. That turns quadratic cost growth into linear cost growth, and is exactly what external memory buys you.

Brain, Notebook, Playbook

In-context memory is your short-term brain. External memory is your notebook. Procedural memory is your playbook. Strong agents use all three intentionally.

What's Next
Memory keeps one agent coherent. The next lesson looks at what happens when you split the work across several agents at once.