Home / Blog / Agentic AI
Memory in AI Agents: Short-Term Context and Long-Term Knowledge
By Softworth Solutions · · 4 min read · For readers in UK, India, UAE

In short: Memory in AI agents has two layers: short-term context, which is what the model sees on this call, and long-term memory, which your system stores and retrieves across sessions. Models remember nothing between calls on their own, so every memory is something you deliberately write, store, retrieve and put back into context.
When people say an agent 'remembers' them, what's really happening is plumbing. Getting that plumbing right is the difference between an agent that feels helpful and one that's confused, expensive or, worse, leaks one customer's details to another. Let's look at both layers.
How should agents manage short-term context?
Treat the context window as scarce working space, even when it's large. Long contexts cost more, slow responses, and models can pay less attention to details buried in the middle. For agents, context also grows with every tool call.
- Put stable instructions first, where they can be cached.
- Trim tool outputs to the fields the task needs before adding them.
- Summarise older turns and keep recent ones verbatim.
- Give the agent a short scratchpad for its plan, progress and open questions.
For long tasks, use checkpoints. At key milestones the agent writes a structured summary of what's done and what's left, the context resets to instructions plus that summary, and work continues. Costs stay flat and the agent drifts less.
What types of long-term memory are there?
There are four useful kinds, and each is stored differently.
| Memory type | Example | Good storage |
|---|---|---|
| Knowledge | Policies, manuals, product data | Search index with vectors and keywords (RAG) |
| Profile | Customer language, role, contract tier | Ordinary database table |
| Episodic | What was agreed on last week's call | Dated summaries linked to full logs |
| Procedural | Approved templates and worked examples | Versioned files reviewed by people |
Knowledge memory is curated by people and shared. Profile and episodic memory build up through use. Procedural memory is best maintained by people based on what the agent learns, rather than rewritten by the agent itself. If you're building the knowledge layer, our guide to building a knowledge assistant is a good next read.
How do you choose storage and retrieval?
Use the simplest store that fits. Structured facts belong in plain database fields that are easy to query, update and delete. Free text suits hybrid search, so retrieval works for meaning and exact terms like product codes. Retrieval matters as much as storage: filter by user, tenant and permissions first, prefer recent memories when facts change, and cap how many enter the context. Ten precise memories beat a hundred loose ones.

An illustrative example
Consider a wealth management firm in Abu Dhabi piloting a client-service agent. Early versions store every conversation and retrieve by similarity, so the agent keeps citing a client's old risk profile alongside the new one. The team moves stable facts like risk profile and preferred language into database fields with dates and sources, keeps short summaries of past calls, and adds a rule that newer facts supersede older ones. Answers get shorter, cheaper and correct.
What should an agent remember, and what should it forget?
Remember facts the user stated, decisions that were confirmed and outcomes of completed tasks. Don't store guesses, passing details or sensitive data without a clear purpose. When a new fact contradicts an old one, such as a changed address, update the old memory instead of keeping both, and attach a source and date to everything.
How do privacy laws affect agent memory?
Long-term memory about people is personal data, so data protection law applies. Tell users what's remembered, let them view and delete it, and make deletion cascade to summaries, embeddings and caches. Isolate memory strictly by tenant and user.
Key facts
- Under UK GDPR, individuals have a right to erasure, also known as the right to be forgotten, in certain circumstances. (Information Commissioner's Office)
- India's Digital Personal Data Protection Act, 2023 gives individuals rights including correction and erasure of their personal data. (MeitY)
- pgvector is an open-source PostgreSQL extension for vector similarity search, letting teams keep embeddings alongside ordinary relational data. (pgvector on GitHub)
Memory is also an attack surface. If a crafted email can get text written into an agent's memory, it can influence future runs, so validate what's stored and never save instructions from untrusted sources. Start small with profile facts and session summaries, measure the effect, then add more. Softworth Solutions (SWS AI) designs memory and retrieval layers for agentic and RAG systems; let's talk if you're planning one.
Key takeaways
- Manage the context window actively, even when it's large.
- Match each memory type to the simplest suitable store.
- Write memories by rule, with sources, dates and supersession.
- Make memory visible and deletable to meet privacy law.
Frequently asked questions
Do large context windows remove the need for agent memory?
No. They help within a task but cost more, slow responses and still end with the session. Long-term memory carries knowledge across sessions and users.
Is RAG the same as long-term memory?
RAG is one way to implement it, mainly for shared knowledge. Agent memory also includes profile facts, past interactions and procedures, which often need structured storage and different update rules.
Should an AI agent decide for itself what to remember?
It can propose memories, but you should set the rules. Limit automatic writes to stated facts and confirmed outcomes, and review procedural changes before they alter behaviour.
How does UAE data protection law affect agent memory?
Onshore UAE businesses fall under the federal PDPL, while DIFC and ADGM entities follow their own regimes, all of which give individuals rights over their personal data. Design memory so it can be viewed, corrected and deleted, and confirm details with counsel.
Planning an AI or software project? Talk to our team for a free consultation and an honest estimate.
Previous: AI for Procurement: Purchase Requests, Three-Way Matching and Approvals
Next: Data Oversharing in Microsoft 365: Fix Permissions Before Rolling Out AI