Table of contents
The short answer
AI agent memory is a set of separate parts. Together they decide four things:
- what the agent sees right now
- what it recalls from the current chat
- what it keeps between sessions
- what it looks up from a knowledge base when needed
Most agent mistakes in real use come from mixing up these layers, not from missing them. To see how memory fits into the agent's working loop, read how AI agents work. Memory is also one of the core components that separates an AI agent from a chatbot.
In Wkil, these layers map to three settings: session memory (the current conversation), long-term memory (facts stored and retrieved across sessions) and knowledge bases (your documents, retrieved on demand). The context window is what the platform assembles from all three for each model call.
The four memory layers
The context window
This is everything sent to the model in one call: instructions, recent chat turns and any results fetched for this call. Its size is limited. Everything in it counts toward both cost and accuracy. A window crowded with unrelated material weakens focus, even when that material is correct.
Short-term memory
This is the live state of the chat: what the user just asked, what they just confirmed and where the flow paused. It usually ends with the session or after a period of no activity. That's on purpose. It isn't meant to hold lasting facts.
Long-term memory
This is information kept on purpose for later sessions: a user preference, a past decision or a note that comes up again. Someone should choose to write it. It shouldn't pile up on its own from every chat.
Retrieved knowledge
This isn't memory about the user at all. It's general knowledge the agent looks up when needed from an outside knowledge base — the RAG pattern. Its benefit is that it stays current without changing the agent's instructions. When the source updates, the knowledge updates too.
Layer comparison table
| Layer | Lifespan | Example | Misuse risk |
|---|---|---|---|
| Context window | A single call only | The last five conversation turns | Overflow that distracts the agent |
| Short-term | Length of the session | "They just picked the monthly plan" | Mistakenly treated as permanent |
| Long-term | Across sessions, until deleted | "Prefers email over phone" | Stale fact shown as current |
| Retrieved knowledge | Until the source updates | Current return policy from the knowledge base | Retrieval from an outdated source |
What to remember, what not to
- Worth keeping: fairly stable preferences, decisions the user confirmed and process details you reuse often.
- Not worth keeping: short-lived sensitive data, one-off details, or anything you'd better fetch from a trusted source when needed.
- A simple rule: if it will change soon or is rarely reused, don't store it. Fetch it when you need it.
A worked example for a customer service agent serving Saudi customers:
Prefers replies in Arabic, on WhatsApp
- Where it belongs
- Long-term memory
- Why
- Stable, reused in every session
"I want to change the delivery address on this order"
- Where it belongs
- Short-term memory
- Why
- Only matters until the request is done
Current return window and delivery fees
- Where it belongs
- Knowledge base
- Why
- Shared by all customers; changes when the policy changes
Order status
- Where it belongs
- Fetched live from the order system
- Why
- Changes hourly; a stored copy goes stale
National ID number, IBAN, card details
- Where it belongs
- Not stored in memory
- Why
- Sensitive; use them in the run if needed, then let them go
| Item | Where it belongs | Why |
|---|---|---|
| Prefers replies in Arabic, on WhatsApp | Long-term memory | Stable, reused in every session |
| "I want to change the delivery address on this order" | Short-term memory | Only matters until the request is done |
| Current return window and delivery fees | Knowledge base | Shared by all customers; changes when the policy changes |
| Order status | Fetched live from the order system | Changes hourly; a stored copy goes stale |
| National ID number, IBAN, card details | Not stored in memory | Sensitive; use them in the run if needed, then let them go |
Identity and session scoping
Every stored memory must be tied to a clear person and session. That way, one user's memory can never show up in another user's chat.
This is the most important design rule in any memory system. A mistake here isn't just a technical bug. It's an instant breach of privacy and trust — which is why AI agent security and governance must include explicit memory scoping rules.
Privacy and data minimisation
Data minimisation means keeping the least data needed for the purpose. Each stored item needs a set lifetime and a way to update or delete it. Memory that never forgets isn't a feature. It's a risk that quietly grows over time.
For organisations in Saudi Arabia, this is also a legal question: the Personal Data Protection Law (PDPL) expects personal data to be limited to what the stated purpose needs and not kept longer than that purpose requires. Before turning on long-term memory, write down what the agent may store, why, for how long, and who can delete it, and check that list with whoever owns PDPL compliance in your organisation. This article is not legal advice. Pair the retention rules with agent permissions, which limit which tools and data an agent can reach in the first place.
Common memory failure modes
- Stale memory: a fact that was once true is shown as current, without checking how old it is. Store the date with each long-term fact and have the agent re-confirm facts past a set age; AI agent workflows shows where such a check fits in a run.
- Context overflow: filling the window with material it doesn't need weakens answers and raises cost.
- Cross-user leaks: unclear identity rules let one person's memory appear for someone else.
- Memory vs. knowledge mix-ups: storing general facts as personal memory instead of fetching them from an up-to-date knowledge base.
Related reading from Wkil
FAQ
Ready to build your first digital employee?
Start building an agent on the platform, or browse the ready-made Agent Marketplace.