Skip to content

Founder-led. Limited engagements.Talk to Us →

Part 5 of 30 · 30 Days of AI Agents

How AI Agents Use Memory | 30 Days of AI Agents, Day 5

Day 5 of 30 Days of AI Agents: short-term, working, long-term, and semantic memory, where each lives, how agents use it, and the mistakes to avoid.

By CodeITronics5 min readAI Agents · Agent Memory · Vector Databases · AI Engineering
How AI Agents Use Memory | 30 Days of AI Agents, Day 5

Yesterday we compared single-agent and multi-agent systems and called shared memory the glue that holds a team of agents together. Today we look at memory itself: the four kinds an agent uses, where each one lives, and how to design it so the agent gets more useful over time instead of more confused.

How AI Agents Use Memory — CodeITronics infographic

Save this sheet. The rest of this note walks through it section by section.

Why Memory Matters

Language models are stateless. Every API call starts from zero. Without memory, an agent forgets everything after each interaction: who the user is, what it already tried, what the company's refund policy says.

Memory gives agents four things: context, continuity, personalization, and better decisions. The chain on the sheet is a good summary: memory gives context, context gives better decisions, better decisions give better agents. Or, more poetically, memory turns intelligence into experience.

Four Types of Memory

Memory typeWhat it storesDurationExample use
Short-termCurrent conversation, recent messagesSeconds to minutesKeep chat context, follow the immediate flow
WorkingOngoing task state, intermediate stepsMinutes to hoursTrack progress through a multi-step task
Long-termUser preferences, historical dataDays to yearsPersonalization, history, learned preferences
SemanticFacts, documents, knowledge as embeddingsIndefiniteRAG, knowledge search, company docs, FAQs

These map loosely to how people work. Short-term is what you are holding in your head right now. Working memory is the notepad on your desk for today's task. Long-term is what you know about your colleagues. Semantic memory is the company wiki you search when you need a fact.

The Memory Architecture

On the sheet, the agent does not talk to each store directly. It goes through a memory manager, a controller that decides what to read, what to write, and what to forget. The manager connects:

  • short-term memory (the conversation),
  • working memory (task state),
  • long-term memory (user profile and history),
  • a vector database for semantic memory, fed by documents, APIs, web data, and files,
  • and tools and actions, whose results may be worth remembering.

This indirection matters. If every part of your agent reads and writes memory however it likes, you end up with duplicated facts, stale data, and prompts stuffed with irrelevant history. One controller with clear rules avoids that.

How Memory Is Used in Practice

The six-step flow on the sheet:

  1. The user sends a message or request.
  2. The agent retrieves relevant context from memory.
  3. The agent reasons and decides the next step.
  4. The agent uses tools or takes actions.
  5. New information is stored in memory.
  6. That context improves future interactions.

Step 2 is where most of the engineering lives. You have a limited context window and a budget, so the memory manager must assemble the right context, not all of it:

def build_context(user_id: str, task_id: str, query: str, budget_tokens: int = 6000) -> list[str]:
    parts = []
    parts.append(profile_store.get_summary(user_id))           # long-term: short and stable
    parts.append(task_store.get_state(task_id))                # working: where we are
    parts += vector_store.search(query, top_k=5)               # semantic: relevant docs
    parts += chat_store.recent(task_id, limit=10)              # short-term: latest turns
    return trim_to_budget(parts, budget_tokens)                # drop lowest-priority parts first

Order matters too. Put stable, important context (profile, task state) where it will not be trimmed, and let older chat turns go first.

Choosing Storage

Storage typeBest forExamplesSpeedQuery type
In-memoryShort-term contextVariables, buffersVery fastExact
Key-value storeSession and task stateRedis, MemcachedFastExact
Vector databaseKnowledge and semantic recallPinecone, Weaviate, Chroma, QdrantFastSemantic
SQL or NoSQLStructured data and historyPostgreSQL, MongoDBMediumExact
File or object storageDocuments and filesS3, GCS, Azure BlobMediumNone directly

A practical default for small teams: Postgres for long-term memory and history, pgvector in the same Postgres for semantic memory, and Redis for session state if you need speed. One fewer database is one fewer thing to secure and back up.

Common Mistakes

The sheet calls out five, and we see all of them:

  • Storing everything in short-term memory. The context window fills with old turns, cost climbs, and the model loses focus.
  • Not using a vector database for knowledge. Pasting whole documents into the prompt does not scale and buries the relevant paragraph.
  • No memory cleanup. Outdated facts (an old address, a changed policy) keep getting retrieved and quietly corrupt answers.
  • Poor context management. Too much context confuses the model; too little makes it guess.
  • Ignoring privacy and sensitive data. Memory is a database of what users told you. Treat it like one: access control, retention rules, and the ability to delete a user's data on request.

Key Takeaways

  • Models are stateless; memory is what gives agents context and continuity.
  • Use four distinct types: short-term, working, long-term, and semantic.
  • Route reads and writes through a memory manager with clear rules.
  • Assemble context within a token budget, in priority order.
  • Plan for accuracy, privacy, and freshness from day one, including deletion.

FAQs

Is RAG the same as agent memory?

RAG is one form of it: semantic memory retrieved by similarity search. Agents also need conversation history, task state, and user-level facts, which are usually stored and retrieved differently.

How much chat history should I keep in the prompt?

Only what the current step needs. A common pattern is the last several turns verbatim plus a running summary of older ones.

Should agents write to long-term memory automatically?

Carefully. Let the agent propose memories, but validate them, deduplicate them, and give users a way to see and remove what is stored about them.

Up Next

Day 6 is the AI agent lifecycle: perceive, understand, plan, act, observe, and evaluate and learn, the full loop an agent runs for every goal, with a worked example and the components behind each stage. If your team needs an agent that remembers the right things and forgets the wrong ones, let's talk.

Keep reading

Single-Agent vs Multi-Agent Systems | 30 Days of AI Agents, Day 4

Day 4 of 30 Days of AI Agents: single-agent vs multi-agent systems, when each fits, the real costs of coordination, and how to grow from one to many.

Prompt vs Workflow vs AI Agent | 30 Days of AI Agents, Day 3

Day 3 of 30 Days of AI Agents: prompts, workflows, and agents compared, with clear rules for picking the cheapest level that solves the problem.

AI Agent Architecture | 30 Days of AI Agents, Day 2

Day 2 of 30 Days of AI Agents: the six building blocks of agent architecture, the think-plan-act-evaluate loop, and a practical example stack.

Subscribe to the edition

One useful systems note a week from real Salesforce and automation builds. Unsubscribe in one click.

Letters

Letters to the editor

No letters yet. Questions and counterpoints are welcome.