Korely

Blog Agent memory · Multi-agent

Shared agent memory: when several agents read the same facts

Shared agent memory is several agents reading the same facts about the same customers. What breaks when one of those facts changes, and how to set up the sharing, with code.

On this page
Two agents, support-bot and billing-bot, write to one store of facts. The Pro plan fact is closed on 20 October and kept, the Free plan fact is open, and any agent that reads without an agent_id gets Free plan.
Two agents write about the same customer. The store closes the old fact with a date and keeps it.

The problem

I am the shared memory of my own AIs

I use Claude Code for my code. I use Grok for my posts, and to talk while I drive. Both know me well. Neither knows what I decided with the other.

So I carry the decisions across by hand. "With Grok we decided this." "With Claude we decided that." I'm the shared memory, and I don't recommend it. I forget a word, I paste last week's version, and I only notice when one of them answers with confidence.

If you build your own agents through an API, they have a cousin of this problem, and it gets worse when a fact changes. Say a support agent and a billing agent look after the same customers (the data here is invented). They share one notes file, so nobody has to ask the customer twice. In September the support agent writes "Maria Rossi is on the Pro plan". In October the billing agent learns that she moved to Free, and adds a line below.

A shared notes file holds two lines about Maria: Pro plan from 1 September, written by the support agent, and Free plan from 20 October, written by the billing agent. Any agent that reads the file has to guess which one is true.
The October line went in below the September one, and nobody touched the old one. Whoever reads the file answers with whichever line it picks up first. Tap to enlarge.

A week later the support agent opens the file, sees two lines about Maria, and answers with the first one it picks up, the Pro plan. Nothing threw an error, every agent did its job, and Maria still gets the wrong plan.

I've seen the same thing in the companies I work for. Two people use the same documentation. One of them changes a page, nobody tells the other, and the other keeps working from the old page until somebody says what changed.

"Shared memory" sounds simple, and it's easy to build one that fails right here. Computer scientists ran into a version of this in the 1960s, when programs had to share one resource without tripping over each other (Edsger Dijkstra, EWD 123). Agents sharing a belief about Maria have the same shape of problem.

Definitions

Three things people mean by shared agent memory

The agents never share what's in their heads (the context window, the text each one can hold at once). They share something outside it, and it's usually one of three things.

Three things people mean by shared agent memory. A chat log grows past the prompt and keeps old and new messages side by side. A notes file holds a Pro plan line and a Free plan line and nothing marks which is true. A store of facts closes the Pro plan fact on 20 October, keeps it readable, and returns the open Free plan fact.
A chat log and a notes file keep every line and mark none of them. A store of facts marks the old fact as closed, and still keeps it. Tap to enlarge.
What is sharedHow an agent reads itWhat breaks
One chat logEvery agent loads the log into its promptThe log outgrows the prompt, and old and new statements sit side by side
One notes fileEach agent reads the file at the start of a runA line is never edited, or the update is appended under the stale line, and nothing marks which one holds
One store of factsEach agent asks the store what holds nowThe store has to know when a fact stops being true, which a plain search over saved text does not

People move state out of the agents because a handoff (one agent passing work to another) loses things. The next agent gets a summary of the task, and a summary drops whatever its writer didn't think mattered. Pass it on again and it's a copy of a copy. State that has to survive is safer outside the agents, in a place they all read.

Many agent tools give each agent its own private notes. Hermes Agent, for example, keeps them in MEMORY.md and USER.md under ~/.hermes/memories/ and loads them "into the system prompt as a frozen snapshot at session start" (the instructions it begins every session with). Its documentation also says "Memory is scoped per profile by design", and points to an external memory provider for anything shared (Hermes Agent, Persistent Memory, read on 31 October 2026). So two agents end up with two sets of notes. If both need to know that Maria moved to Free, that knowledge has to live in a third place they can both read.

What changes

Why a shared note breaks when a fact changes

A shared note is fine for things that never change: a customer's date of birth, the day they signed up, the street they grew up on, your company's name, the language your bot answers in. It falls apart for things that do, and agents deal with those all day: a plan, an address, a budget, who owns a task, the price you quoted last Tuesday, a decision someone reversed.

It breaks in two ways. Either the old line stays, and every agent that reads it repeats it. Or the update is added next to it, and the agent that reads both quotes whichever one the search puts first. The second one is sneakier, because the right answer is sitting right there in the file.

You may not catch it in testing. A test has one customer and two lines. Production has thousands of customers and months of lines, and the stale line only has to win once to reach a customer. When a conversation grows too long and the agent squeezes it into a summary, the summary can keep both lines and lose which one came last. And then you're back to being the memory of your own bot, the one who knows which line is current.

Sharing adds another problem. The agent that reads a fact is often not the agent that wrote it, so it never saw the change. Only the store can tell it. So the change has to be recorded in the store, on the fact itself. The idea behind that is explained in Bi-temporal memory for AI agents: what was true, and when.

How it works

One store, several agents

In Korely every memory carries two labels. user_id is the person the memory is about. agent_id is the name of the agent that wrote it. Agents that use keys of the same project write into one store, and a read that passes user_id and no agent_id returns what the store holds about that person, from every agent.

Here are the two agents from the opening, writing about the same customer. The timestamp says when each thing was true, so the facts get the right valid_from:

from korely_memory import Korely
korely = Korely() # reads KORELY_API_KEY or the key saved by korely init
# The support agent writes what it heard in September
korely.add(
"Maria Rossi is on the Pro plan.",
user_id="customer-4812",
agent_id="support-bot",
timestamp="2026-09-01",
)
# The billing agent writes the change in October
korely.add(
"Maria Rossi is now on the Free plan.",
user_id="customer-4812",
agent_id="billing-bot",
timestamp="2026-10-20",
)

Now any agent, built by anyone, can read the customer without knowing who wrote what:

context = korely.get_context("Which plan is Maria on?", user_id="customer-4812")
print(context.context)

This is the text that comes back, about ten seconds after the writes. It also opens with a reading note for the model and repeats a one-line note under the memories. We left both out here:

## Known facts
- Maria Rossi has_plan Free plan (since 2026-10-20)
## Relevant memories
- [2026-09-01] (true when said, changed later) Maria Rossi is on the Pro plan.
- [2026-10-20] Maria Rossi is now on the Free plan.

A memory is the sentence as you wrote it. A fact is the short, tidy line Korely pulls out of it, like "Maria, plan, Free". Facts are what get closed with a date. The Known facts section holds one plan, the current one. The older memory is still there, marked "changed later", so the agent can see how the answer came to be.

The billing agent's write closed the support agent's fact. The check runs on the customer's facts, whichever agent wrote them. A model reads each new fact next to the customer's open facts and decides whether they clash. The old fact stays one call away. This is what the store holds, with the fields that matter (a model writes the predicate, so another run may name it differently):

korely.get_facts(user_id="customer-4812", include_invalidated=True)
agent_idpredicateobjectvalid_frominvalid_at
billing-bothas_planFree plan2026-10-20null
support-bothas_planPro plan2026-09-012026-10-20

The predicate is the relation (here, which plan), valid_from is the day a fact became true, invalid_at is the date it was closed, and null means it is still open. Two agents, one customer, and nobody had to call a meeting.

The trap

The label that hides the answer

There's one habit that quietly breaks all of this. Each agent writes with its own agent_id, so it feels natural to read with it too: "I'm the support agent, give me my stuff." Don't. On a read, agent_id is a filter, like asking for "only the red folder", and filters in Korely only narrow. It means "only what this agent wrote". Here's the support agent asking the same question, with its own name:

korely.get_context(
"Which plan is Maria on?",
user_id="customer-4812",
agent_id="support-bot",
)
## Relevant memories
- [2026-09-01] (true when said, changed later) Maria Rossi is on the Pro plan.

There's no Known facts section this time. The current plan, Free, was written by billing-bot, and the read stayed inside what support-bot wrote, so it never looked there. What it found is the old Pro memory, still marked "changed later". The agent is left holding the old answer, with a note on it saying it's old, and the new answer isn't in the block.

The same question asked twice. Without an agent_id the block has a Known facts section with the Free plan. With the agent_id support-bot the block has only the older memory, the Pro plan marked changed later, and no Known facts section.
Left: what the support agent should see. Right: what it sees when it filters by its own name. Tap to enlarge.

Write with the agent_id of the agent that did the work. Read without one when the agent should see what the others know. Put agent_id on a read only when the question is about one agent, for example what billing-bot has recorded.

Good habits

Five habits for a shared memory

With a shared store, every agent gets the same answer to "what is true now?", as long as you keep a few habits.

  • Let your own code hand out the work. Dijkstra, the computer scientist from the opening, fixed programs sharing a resource with a rule for taking turns. Korely keeps a record of what holds now, so everyone starts from the current version. Who waits for whom, who gets which task and which messages go between agents stays in the code that runs your agents.
  • Give the facts a few seconds. The facts are extracted in the background after add() returns and settle in about ten seconds. A handoff that writes and reads in the same second should wait for the memory to be ready, or accept that the read comes from the memories and not yet from the facts. The memory's status in GET /v1/events says when it is ready, so a handoff can wait on that instead of on a guess.
  • Say when two things can both be true. A new fact closes an old one only when a model confirms the conflict. "Marco likes coffee" and "Marco likes tea" can both hold, so both stay open. Marco is allowed to like both. If two facts can both be true, say so in the sentence (for example "in summer I live in Barcelona"): the model then has a better chance of keeping both. Read the history with include_invalidated when you need to audit a decision.
  • Check a fact that matters. Extraction now and then skips one. If a fact matters, check that it is there with get_facts before another agent depends on it, and write it again as one simple sentence if it isn't.
  • Pass the customer on every read. Pass user_id on every read of a customer-facing agent. Without it, a read spans every end user of the project. Agents share a memory only when their keys belong to the same project, which is also how a staging project stays apart from production.

Connect your agents

Pointing several agents at one memory

Give each agent a key from the same project, and use the same user_id for the same person. That's all the sharing takes.

If your agents speak MCP (a standard way to plug tools into AI apps), Korely is also a remote MCP server at https://api.korely.ai/agent/mcp, and its tools that write and read take the same user_id and agent_id, so the rule above holds there too. The tools are in Korely MCP, and the Hermes setup is in Hermes Agent.

To try the two-agent example, install the SDK and create a free key:

pip install korely-memory
korely init --agent --agent-caller your-name --processing-region eu --json

your-name is just a label for who is calling, and eu is the project's processing region. The quickstart walks through the first write and the first read, and what each plan includes is on the pricing page.

Your data is stored in Europe, on our server in Helsinki. Korely is a European startup, and we plan to expand to where our users are. Data governance has the regions and which model reads your text.

Do one small thing before you build anything bigger. Pick one fact that two of your agents both touch, like a plan, an address or a budget. Write it from one agent, change it from the other, and read it back with get_facts. If the old fact is closed with a date and the new one is open, the sharing works. Support now reads the Free plan that billing wrote, and nobody carried it across by hand. Not even you.

FAQ

Questions about shared agent memory

Do two agents need the same agent_id to share a memory?

No. agent_id labels the namespace a memory was written under. A read that passes user_id and no agent_id returns that end user's memories and facts across every agent, so each agent keeps its own agent_id on writes and leaves it out on shared reads. Adding agent_id to a read narrows it to that one namespace; it never widens it.

Can agents built with different tools share one Korely memory?

Yes. The REST API, the SDKs, the CLI and the MCP server sit on one store. Agents share a memory when their keys belong to the same project and they use the same user_id for the same person. Keys in different projects never see each other's memories.

Does Korely coordinate the agents?

No. Korely stores what the agents write and returns what holds now. Locking a fact, queuing tasks and passing messages between agents are outside it. Who does what stays in your orchestration code.

How soon can another agent read a fact that was just written?

Typically about ten seconds. The facts are extracted in the background after the write returns, so a read issued right after may not see them yet. The memory status in GET /v1/events says when it is ready.

Back to top