Agent memory preserves conversation context across turns and sessions, while agent knowledge gives agents access to maintained pages and notes within explicitly configured scopes.
Both need to exist because "every API call starts fresh," so anything an agent knows has to be stored outside the model and sent back in.
What is the difference between agent memory and agent knowledge?
Agent memory is state kept for a thread or a resource, such as a user, a project, or a multi-user thread. That means the conversation so far, saved facts about that resource, and observations compressed from history.
Agent knowledge is a structured store of pages and notes that outlasts a single conversation. It can be scoped privately to one user or shared across a team for material like coding conventions and runbooks.
The two stores differ on four properties:
| Property | Agent memory | Agent knowledge |
|---|---|---|
| Scope | A thread or a resource (a user, project, or multi-user thread) | A configured scope (one user, a team, a company, or a shared topic) |
| Lifetime | Kept until the agent or your code deletes it | Kept until its owner edits or removes it |
| Who writes it | The agent during a run, background processes and your server code | People and agents with write access, plus sync jobs from source documents |
| How it is retrieved | Recent messages, saved facts about the user and similar past messages | Search over shared pages, plus standing rules sent with every prompt |
A shared store also has to settle which entry is authoritative and who corrects it. Tiered memory systems such as MemGPT only decide how much fits in the prompt.
- Memory answers "what happened in this thread or with this resource."
- Knowledge answers "what maintained pages and rules apply to this scope."
- A wrong memory entry is fixed per thread or resource, and a wrong knowledge page is fixed once at the page.
What does agent memory store?
Agent memory stores what an agent has learned across a thread or resource, such as a user or project. Researchers sort it into types by what it holds.
The CoALA framework for language agents names four types of agent memory:
- Short-term memory holds the current task and the conversation so far. CoALA calls it working memory.
- Episodic memory holds past events, such as earlier conversations.
- Semantic memory holds facts, such as what the agent has learned about a user.
- Procedural memory holds how to act, in the agent's code and instructions.
A production memory system turns those types into stores like these:
- recent messages from the current thread
- a short record of facts about the user, which the agent updates itself
- past messages found again by similarity search
- a compressed summary of older messages, so a long thread still fits in the prompt
Memory that lasts across sessions is called long-term memory. Memory follows a thread or resource, such as a user or project. Knowledge organizes maintained pages and notes beyond conversation history.
What does agent knowledge store?
Agent knowledge stores what a team or company holds to be true. Every agent and person with access reads the same copy.
For a development team, that covers material like this:
- team coding conventions
- on-call runbooks
- API docs and product docs
- architecture decisions and the reasons behind them
A knowledge store is built from pages and notes. A page is a named topic with a body of text. A note is a short fact on a page, with its author attached.
An agent knowledge base is often built as retrieval over documents, known as RAG. Retrieval finds the right passage, but it does not track owners, versions or who may write.
A knowledge page needs one owner and a record of who wrote it
Unlike memory, a shared store needs rules for who may read each page and who may change it. Each page needs one owner who can fix it.
Records of who wrote what matter too. Allen Pike, writing on company brains, makes this point about maintained truth in company brains, and says you simply need to record:
- who drafted or reviewed a document
- whether a human wrote it
How do you decide whether a fact belongs in memory or knowledge?
You need three tests to decide whether a fact goes in memory or knowledge.
- Vouch test. If only the speaker can vouch for it ("I prefer metric units"), it is a fact about that person. It goes in the memory store.
- Reader test. If a separate agent should use the fact later, it needs a store with access set by role.
- Authority test. If the fact must be one value for the whole organization, it needs a single owner. That means a page with an editor.
1. Put a developer's exception to a team convention in her memory
Development teams usually set conventions that every developer must follow. Say yours is "database access goes through the repository layer, with no raw SQL in application code."
Then one developer asks her agent to break it for her own case. She is writing a backfill migration.
Her exception goes in her memory, with the context that keeps it narrow. Save it with these details:
- the repo and the task it covers
- why she needs it
- when it ends
Adding it to her personal agent memory is good so the agent does not reject her requests when working on similar projects in the future.
Keep her exception in personal memory or a user-private knowledge scope, with its task and expiry clearly recorded, rather than saving it to a shared team scope.
2. Put the team convention on a knowledge page with one editor
Memory is the wrong home for the convention itself. Memory saves facts one user at a time.
If you need to update a convention, an editor would have to go through each user and update it one at a time.
That is unnecessary redundancy and can easily be solved through agent knowledge.
3. Record decisions and their reasons in knowledge as attributed notes
Ashu Garg of Foundation Capital adds a third category in his writing on context graphs.
He argues that systems of record store outcomes, while the reasoning behind things usually sits in Slack threads or meeting transcripts.
And acting on a decision without knowing the reason behind it or the thought process behind it would mean blindly trusting an AI.
So he recommends decision traces to be recorded while the work happens. Here's his one-line version of the post:
The last generation of software captured what happened. This generation will capture why.
What if you add facts to the wrong store?
A fact in the wrong store does one of two things. It spreads one person's case to the whole team, or it splits a team rule into copies that drift.
- Convention in user memory. An agent rewrites the user's saved facts and drops the convention line. That developer's agent stops following it, with no trace of the change.
- Exception in shared knowledge. An exception saved as a team-wide rule may be incorrectly applied to other developers. Keep its audience and task limits explicit.
- Facts only in recalled messages. A match on an old message returns the superseded convention next to the current one, because recall ranks by similarity.
- Stale page, no owner. The page still states the old convention after the team changed it, and search returns it confidently.
In July 2026, Atlan co-founder Prukalpa Sankar wrote about an agent that kept pitching outdated positioning for weeks. Marketing had already changed it.
But the bad answers could not be traced to the model, the agent design, or the context.
A page with an author and a version can help narrow such searches to one record. And a trace output is exactly what you need to see which recalled messages entered the prompt.
How do you keep agent memory and knowledge fresh?
Now, onto one of the important problems, keeping your agent memory stores fresh.
Neither store expires a fact on its own. Facts leave only when something removes them, and you keep them fresh by re-checking them against a source.
That includes a developer's exception.
1. Delete stale memory yourself
I know, I myself do not want to do anything manually when it comes to agentic data because there's just so much of it.
But sometimes you need to get involved in what the model remembers and prune it manually to avoid letting stray memories pollute your context.
Do that in the memory store, not in the prompt:
- overwrite the working memory field that holds a fact when the fact changes
- remove a note that a newer decision replaced
- end a developer's exception on the date saved with it
Leave the conversation itself alone. Changing a cached prefix can reduce prompt-cache reuse, though Observational Memory compresses older messages while retaining a stable observation prefix.
Fix the stored memory, and keep the conversation stable. Trimming the prompt does not delete stale facts from storage.
2. Check compressed memory against the original messages
A summary or an observation log can keep a reason that review later corrected. Nothing in it checks itself against a source.
So compare each summary with the original messages, and correct the stored version when they disagree.
3. Reindex recalled messages after their thread metadata changes
Similarity search over past messages has a freshness catch of its own. Its filters use metadata saved with each embedding.
When thread metadata changes later, the existing embeddings keep the old values. They keep them until messages are saved or reindexed.
A recalled message is evidence that something was said. It carries no claim that the statement is still true.
4. Run a sync job that re-loads changed pages and removes deleted ones
Knowledge needs a refresh path, because "checked recently" and "correct now" are different claims. A knowledge store keeps a page until your code removes it.
So a sync job re-loads pages on a schedule and removes pages deleted at the source. It also removes stale notes, since nothing else will.
When do you need memory, knowledge, or both?
- Use memory alone when each fact is about one user or one conversation.
- Use knowledge alone when agents answer from shared documents and do not need to remember who asked. A docs-answering agent is that case.
- Use both when an agent works for one person on behalf of a team. A coding agent that follows team conventions and remembers one developer's exception is that case.
With both stores, one run holds a team scope, a user scope and a conversation scope at once.
Basically, memory handles the person, and knowledge handles the organisation.
A pinned page reaches the agent's context on every turn. Pin standing rules, such as the conventions every coding agent must follow.
Leave the rest to search.
How do you give one agent both memory and knowledge with Mastra?
Mastra is an open-source Typescript framework for building agents. And we keep finding efficient ways to achieve results our users want. Memory and context are two recurring problems.
In Mastra, you can pass an agent both a memory option and a knowledge option simultaneously to give it both stores. That's all it takes.
Here are the documentation pages for both Mastra memory and Mastra Knowledge to learn how to implement the stores in your agent.
Use Mastra Memory per user and thread, and Mastra Knowledge per shared scope
Mastra's Memory keys a user or project as a resource and a conversation (single-user or multi-user) as a thread.
Mastra Knowledge groups pages into scopes that grant roles such as viewer, contributor, and editor.
| Property | Memory | Knowledge |
|---|---|---|
| Unit of scope | A thread or a resource ID (a user, project, or multi-user thread) | A scope address (one user, a team, an organisation, or a shared topic) |
| Who reads it | The run holding that thread or resource | A run whose scopes carry a role there |
| Who writes it | The agent during a run, background observers, and trusted host code | Agents with contributor or higher, and trusted host code |
| How a wrong entry gets fixed | Update the stored fact on the thread or resource | An editor changes the page, or someone removes the note |
Configure editor access for maintainers to update conventions and contributor access for teammates whose agents can add notes asking for a change; viewers remain read-only.
Build agent memory and knowledge on Mastra
Mastra lets Memory and Knowledge share the same scopes, with access rules configured for each audience so a developer's exception stays private while team conventions stay shared.
Both run in your own app, on your own storage.
Try Mastra, the open-source Typescript framework for building production-ready AI agents.
Agent memory vs knowledge FAQs
Can a vector database be used for agent memory?
A vector database can serve one memory layer, like the search for similar past messages. It finds what was said, not what is still true. It also has no owners, versions or roles, so shared facts need a knowledge store beside it.
Can knowledge graphs improve agent memory?
Yes, for finding related facts. Links between facts let an agent move from one fact to the ones connected to it.
A graph does not decide who owns a fact, though. Ownership and access rules still decide what the agent may trust and change.
How do you test that agent memory stays with one user?
Save a fact in one user's run, then run a teammate's agent and that user's next thread. The fact should reach only the first user's runs. Use this check to confirm that the raw SQL exception stays within the intended user's memory.
Can a note be edited after an agent writes it?
Trusted server code can, with updateNote(), which replaces the note with a fresh one under a new ID. A seed script uses it so a re-run does not duplicate notes. An agent corrects a note by adding one that names the note it replaces. An editor then removes the old one, so the correction leaves a trail.
Does Mastra Knowledge replace RAG over my documents?
For a static corpus with no owners, a retrieval pipeline over your own index is enough. Knowledge adds attributed notes, roles per scope, versions, pinned pages on every turn and a write path for agents. Its search is keyword-based by default. It becomes keyword plus meaning when you add a vector store and an embedder.
Can two agents share memory in Mastra?
Yes, through identifiers. Agents called with the same resource ID share working memory and semantic recall at resource scope. Agents called with the same thread ID share message history. Supervisor delegations do the opposite by default. Each subagent gets a fresh thread and a derived resource ID, so its memory stays isolated.
Can semantic recall search Knowledge pages?
No, because the two searches never cross paths. Semantic recall finds past messages, and Knowledge has its own search tool with its own keyword and vector path. A fact that exists only as a page never surfaces through recall, and the reverse holds for old messages. Put each fact where the store that serves it can find it.
Can I pin a Mastra Knowledge page for one user only?
Yes, by choosing the scope. Pin a page in a scope only that user's runs can read, such as that user's resource scope. Pinned context follows the same read rule as search, and a pin never widens access. Pinned context has a configurable token budget, so keep a personal pin short.
What database does Mastra use for agent memory and knowledge?
Knowledge writes its own tables to the storage provider configured on your Mastra instance. That can be LibSQL, PostgreSQL or MongoDB. Memory also accepts a storage adapter, such as LibSQL. Search by meaning adds a vector store and an embedder of your choice.
