May 28, 2026 · 11 min read

You built an AI agent. It calls tools, plans multi-step workflows, and the first time you run it, the demo feels magical. Then you run it again the next day, and it greets you like a stranger. Same clarifying questions. Same mistakes. Same steps reconstructed from scratch.
That is not a tooling problem. That is a memory problem.
Most agents shipping today are stateless. They execute inside a loop, but they do not accumulate knowledge across runs. Every session starts at zero, which means every improvement they appeared to make last time is gone. If agents are going to automate real work, they have to get better the longer you use them. That only happens with memory, and not just stored data, but structured, evolving memory that compresses experience into knowledge.
In this article, I will break down what memory really means inside an agent, where the standard implementations fall short, how to design memory as a first-class layer in your agent loop, and finally how a system like Engram handles this in practice. By the end, you should have a clear mental model for adding real long-term memory to whatever you are building.
If you like Video more, You can watch this:
When people say "memory" in AI, they usually mean storing chat history and pulling it back later. That is not memory. That is replay.
An agent already has context during execution. The system prompt, the tools, the intermediate tool calls, the partial outputs, all of it sits inside the model's context window for the duration of a single run. The moment the run ends, that context evaporates.
The common patch is to dump everything into a vector database, then retrieve the chunks that look semantically similar to the next prompt. This keeps the agent informed, but it does not make it smarter. It is the equivalent of handing someone a transcript of a meeting they never attended and hoping they get up to speed.
Real memory does something more interesting. It compresses raw experience into reusable knowledge. Humans do not remember entire conversations word for word. We remember conclusions, preferences, and patterns. Agents need the same transformation layer between raw execution and stored memory, or they will keep drowning in their own logs.
The default agent loop looks roughly like this:
At a glance, this feels like memory. In practice it builds a system that can recall but cannot learn.
The agent never refines what it knows. It never resolves contradictions. It never updates outdated information. It just accumulates. Over time, the store fills with multiple versions of the same idea, conflicting preferences, and abandoned half-thoughts. Retrieval gets noisier, irrelevant context starts crowding the prompt, token usage climbs, and accuracy drops.
This is the reason so many agents feel stuck at the same level no matter how many sessions you put through them.
The gap is a learning step between execution and storage.
Most loops look like this:
input → plan → execute → store → end
A real long-term-memory loop should look like this:
input → plan → execute → learn → update memory → next run
That learning step is where transformation happens. Instead of saving raw logs, the system pulls out structured insights and writes those. If a user says they prefer Postgres over MySQL, that is a stable preference, not a line buried in a chat log. If an agent tried three approaches and only one worked, the successful path is a reusable strategy, not noise mixed in with two failures.
Without this step, the agent keeps rediscovering the same things on every run, and you pay for it in tokens, latency, and user trust.
It helps to split memory into layers, the same way cognitive science does. Most current systems collapse all three into one bucket, which is exactly why they get confused.
A good memory system treats these differently. Episodes get logged and mostly left alone. Semantic facts get reconciled and updated in place. Procedures get versioned, scored, and promoted when they keep working.
A working memory layer for agents needs three core operations:
This pipeline is what turns memory into something the agent can rely on instead of something it has to sift through every turn.
Once a memory layer like this is in place, the agent's behavior changes in ways the user actually notices:
At this point the agent stops being a pure execution engine and starts being something closer to an accumulating knowledge system. That is the line between "impressive demo" and "tool I actually use every day."
This brings us to Engram, an open-source memory layer designed to sit alongside your agent rather than inside it. The project bills itself as "persistent cognitive memory for AI agents" and is built around exactly the extract → reconcile → retrieve pipeline above.
Here is what makes Engram worth a look:
Engram exposes itself through a TypeScript SDK, a REST API, and an MCP server, which means it slots into Claude Desktop, Cursor, Windsurf, and anything else that speaks the Model Context Protocol.
The Python core is a single pip install:
pip install engram-core
Optional extras cover the server, the MCP integration, embedding backends, or the full bundle. For the TypeScript SDK, install the client package alongside whatever agent framework you are already using.
The self-hosted version of openengram.ai ships a setup wizard that walks you through account creation and model configuration, and all features unlock locally at no cost. If you want to start with the cloud-hosted control plane, you grab an API key (ek_...) and point the SDK at it.
Here is the smallest end-to-end example using the Python SDK:
from engram import Memory
mem = Memory()
mem.store("User prefers Python", type="preference", importance=8)
mem.store("Project uses Postgres, not MySQL", type="fact", importance=9)
results = mem.search("programming language")
context = mem.recall(limit=10)
store is the extraction entry point. You tag each memory with a type and an importance score so the consolidation pass can reason about it later. search runs full-text and semantic retrieval. recall pulls the top-N most relevant memories for prompt injection.
The TypeScript flavor is just as light:
import { Engram } from '@engram/client';
const engram = new Engram({ apiKey: 'ek_...' });
await engram.remember("User prefers dark mode");
const memories = await engram.recall("UI preferences");
Both SDKs share the same mental model: write through remember / store, read through recall / search, and let the consolidation pipeline keep the underlying store clean in the background.
You can also link memories explicitly to build a small knowledge graph the agent can walk:
bug_id = mem.store("Login fails on Safari", type="error_fix", importance=9)
fix_id = mem.store("Added WebKit prefix to CSS", type="error_fix")
mem.link(bug_id, fix_id, "caused_by")
graph = mem.graph(bug_id, max_depth=2)
That link call is what turns a flat collection of facts into procedural memory the agent can actually follow.
Let us put this together with a concrete scenario. You are building a developer agent that helps scaffold and maintain a project. Without memory, every new session restarts the same conversation about your stack.
Bootstrap a tiny project:
mkdir agent-with-memory && cd agent-with-memory
python -m venv .venv && source .venv/bin/activate
pip install engram-core openai
Wire memory into a basic loop:
from engram import Memory
from openai import OpenAI
mem = Memory()
client = OpenAI()
def chat(user_input: str) -> str:
context = mem.context(user_input, max_tokens=500)
messages = [
{"role": "system", "content": f"Known about the user:\n{context}"},
{"role": "user", "content": user_input},
]
reply = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
).choices[0].message.content
mem.store(user_input, type="event", importance=4)
mem.store(reply, type="event", importance=3)
return reply
print(chat("Set up a new Node service. I prefer Postgres and pnpm."))
print(chat("Add a users table to the project."))
On the first call, the agent has nothing to recall, so it answers from scratch and writes two events to memory. On the second call, mem.context() returns the relevant prior decisions (Postgres, pnpm) and injects them into the system prompt. The agent never has to ask "what package manager do you use" again, and you never have to repeat yourself.
If you then say "actually, switch this project to Bun," Engram's reconciliation step updates the existing preference rather than appending a contradicting one. That is the difference between a memory system and a log.
The second project shows how to plug Engram into an existing coding agent without writing client code at all. Most modern coding agents (Claude Desktop, Cursor, Windsurf, the Antigravity CLI, and others) speak MCP, and Engram ships an MCP server out of the box.
Start the MCP server:
pip install "engram-core[mcp]"
engram mcp serve
Then add it to your agent's MCP config. For Claude Desktop, edit claude_desktop_config.json:
{
"mcpServers": {
"engram": {
"command": "engram",
"args": ["mcp", "serve"]
}
}
}
Restart the agent. From inside any session you can now ask things like:
Remember that this project uses Drizzle ORM, not Prisma.
What have I told you about my testing setup?
The agent calls Engram's MCP tools to write and read memories, and the consolidation loop keeps the store tidy in the background. The same memory pool is now visible to every MCP-aware agent you use, which is the part most people underestimate the first time they try it.
When you sit down to design an agent, the first question is usually "which model?" or "which tools?" That is the wrong starting point. The first question should be:
What does this agent need to remember, and how should that memory evolve?
Decide what qualifies as durable knowledge for your domain. Decide what should never be stored (raw PII, transient state, things that age out fast). Decide how updates and conflicts are resolved. Then design your loop so that every execution contributes back to that memory, not just consumes from it.
A few practical heuristics:
That is what turns a collection of tools into a system that actually improves over time.
Engram is one of the most thoughtful entries in the agent-memory space right now, but it is worth going in with calibrated expectations.
Where it shines:
Where to be careful:
Once you have a memory layer wired in, there are a few directions worth exploring:
The Engram documentation at engram.to and openengram.ai is the best place to go deeper, and the GitHub organizations behind the various implementations are active and worth tracking.
Most agents today feel powerful in the moment and forget everything afterward. That is the ceiling on what they can become.
Memory raises that ceiling. It lets agents accumulate knowledge, refine behavior, and adapt with use instead of resetting every session. Engram is one good implementation of this idea, but the larger shift is architectural. Agents are not just reasoning systems anymore. They are learning systems, and memory is the layer that makes the learning stick.
If you are building agents right now, focus less on making them smarter inside a single run. Focus on making them better across many runs.
That is where the real leverage is. Give it a try in your next project and see how quickly the dynamic changes.
Also published on DEV.to.