1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
51 small wins to finish your pathNext question →
Explain short-term vs long-term memory in agents.
30-second answerSay your answer out loud first, then reveal.
Short-term (working) memory
- The message history plus tool observations in the current run.
- Limited by the context window. Even with large windows, quality degrades as context fills ("context rot"), and cost grows with every token re-sent.
- Managed by trimming, summarising older turns, or offloading large tool outputs to files and keeping only a reference.
Long-term memory
Long-term memory is often divided along cognitive-science lines:
- Semantic: facts, e.g. "User prefers Python. Company uses Postgres."
- Episodic: past experiences, e.g. "Last time this deploy failed because of X."
- Procedural: how to do things. Learned instructions and updated system prompts.
How long-term memory works in practice
- Write: after a turn, or in the background, an LLM extracts memory-worthy facts.
- Store: in a vector DB, key-value store, or plain files/documents per user.
- Read: at the start of a turn, retrieve relevant memories by semantic search, recency or explicit keys, and inject them into context.
- Maintain: update conflicting facts and delete stale ones.
Example. A tutoring agent remembers that "the student struggles with backpropagation" across sessions. Without long-term memory it would start over every time.
Common mistakes
- Saying "we just store the whole chat history in a vector DB." That gives noisy retrieval and no conflict resolution.
- Ignoring privacy, i.e. what should never be stored.
Follow-ups to expect
- How do you handle a memory that becomes outdated? (See Q29.)
Related
Little by little, you're building something great.