Memory (Agent Memory)
Why Memory Is Needed
An Agent without memory is like a "goldfish" — every interaction is independent. Ask "what did you have me do yesterday?" and it has no idea.
Real-world tasks often need:
- Understanding conversation context
- Remembering user preferences and habits
- Saving intermediate task execution state
- Calling on historical knowledge to assist decisions
Memory lets Agents "accumulate experience" instead of starting from scratch every time.
What Is Memory
One-line definition: Memory is an Agent's ability to save and reuse information, enabling it to maintain coherence across multiple interactions and complex tasks.
Analogy: Memory is like a person's memory system — there's working memory (what you're currently thinking about), and long-term memory (various knowledge you've memorized).
Agent memory has three layers:
Working Memory: context information within the current task execution cycle, limited by the Context Window, released when the task ends.
Session Memory: cross-turn conversation information, saved during the session, typically managed through conversation summarization compression.
Long-Term Memory: persistent cross-session knowledge, can remember information from months or even years, usually stored in vector databases — this is where Embedding for semantic retrieval comes in.
How to Do It: When to Use Which Memory Layer
Only working memory needed: simple one-time tasks, ask and answer, done.
Session memory needed: maintaining context across multiple conversation turns, like customer service conversations or gradual complex problem solving.
Long-term memory needed: remembering user preferences, historical decisions, and domain knowledge, like personal assistants or long-term project assistants.
This is similar to RAG thinking — both retrieve relevant information from external storage and拼入 context, except Memory stores "historical experience" and RAG stores "external knowledge."
Common pitfalls:
- stuffing everything into Context: Context Window is limited, need to filter, only keep information relevant to the current task
- inaccurate memory retrieval: need semantic matching via Embedding, not simple keyword search
- memory consistency: multi-turn conversations may have memory conflicts, need version management and conflict detection
Remember this: Memory transforms Agents from "goldfish" to "experienced workers" — different memory layers serve different needs, not "the more the better," but "use what you need."
Related Products