Skip to content
James Ross
articlePublished Updated 9 min read

AI agent memory: one layer shared by several coding agents

By James Ross

Shared AI agent memory means more than pointing two tools at one database. Both agents have to write into the same store without losing provenance, both have to read each other's history at session start, and the layer that processes memory has to run somewhere cheap enough that capture never pauses. Get those three right and a second agent becomes additive instead of amnesiac.

Two agent robots writing tagged note cards into one shared archive cabinet, illustrating shared AI agent memory.

This is the third piece of the company AI workspace rollout: the same instinct that put a gateway in front of model access puts a single AI agent memory store in front of two coding agents. The supporting posts cover the gateway, the browser bridge, failover and the prose-versus-numbers rule.

The scale: the memory database on one machine was large enough that a backup would run to tens of gigabytes, so copying it between machines was never an option. The integration had to read and write in place.

What a shared memory layer is for

A coding agent starts every session with no memory of the last one. Everything it learned about a repository, a bug or a decision is gone unless a person re-explains it. A memory layer fixes that by capturing observations during a session and injecting a compact index of relevant history at the start of the next one.

With one agent that is a self-contained feature. With two, the failure is obvious: each agent remembers its own work and forgets the other’s. A fix discovered in one tool is invisible in the other, so the second one re-derives it, often incorrectly. The repository becomes a place where two amnesiacs take turns.

The obvious fix, a shared database, is only a third of the work. If the writers do not record which tool produced a memory, search results become unattributable. If the readers do not merge both sources into the startup index, sharing the database changes nothing. And if capture depends on an expensive model with a weekly limit, memory stops exactly when the week gets busy, which is when it is most valuable.

Two writers, one store

The integration keeps one store and one capture pipeline. Both tools write project sessions into the existing database, and the companion layer owns the hooks that trigger capture so the two tools cannot double-capture the same session.

The write path keeps provenance. Every observation is recorded with the tool that produced it, which costs nothing at write time and makes every later query answerable. The read path is asymmetric on purpose:

  • the second tool’s session start reads all sources, so it sees the first tool’s history;
  • the first tool’s session start keeps its own history and adds the second tool’s slice beside it;
  • an explicit source filter still narrows a query when isolation is what the caller wants.

That asymmetry is not favouritism. It preserves the first tool’s existing context behaviour exactly, so installing the integration cannot change what that agent already does well, while the new tool gets the full picture. The alternative, rewriting both startup paths, would have risked the working half to improve the new one.

No schema change and no transcript parsing were needed. Upstream already captured the second tool natively; the missing piece was read behaviour. Being able to say that precisely is what kept the change small.

Scoping by repository, and where it breaks

Memory is scoped by the repository’s root folder name. Sessions from /work/storefront land under storefront, and a later session in the same checkout recalls them without any manual tagging.

That simple rule has two known edges. Git worktrees query both the parent name and a parent/worktree composite, so work done on a branch is visible from the main checkout. But two unrelated repositories with the same root folder name collide: both become one project, and each starts recalling the other’s history. The documented fix is to rename one checkout, which is honest but blunt.

The lesson is that repository identity is harder than it looks and cheap to get almost right. A path is not an identity, a folder name is not a path, and a remote URL is the closest thing to a stable key, until a fork or a rename. The integration chose the folder name because upstream already did, and documented the collision rather than pretending it could not happen.

What is worth remembering

Not everything should be remembered. Capture writes two things: an observation for almost every tool call, and a summary for each session. The summary makes a session findable later; the observations make it reconstructable.

Recall is layered for the same reason. At session start the agent gets a compact index of relevant history for that repository, not a transcript. When the index is not enough, it uses the MCP memory tools: search, then a timeline around the promising results, then only the selected observations. Each step narrows the last.

What earns a place in that index is the work that would otherwise be re-derived: the decision and its reason, the fix and the symptom it addressed, the constraint discovered in production. What does not is the raw back-and-forth that produced it. A memory store full of transcripts is a search problem; a memory store full of decisions is an asset.

Provenance matters here too. Knowing that a note came from the other agent changes how much to trust it, because the two tools ran different models with different instructions. A shared store without provenance makes every memory equally authoritative, which is worse than no memory at all.

Routing memory processing to a different model

Memory capture is a model workload, and an easy one to underestimate. An observation per tool call means dozens of calls per session, each with a prompt and a structured reply. On the default provider that work counts against the same weekly limit as interactive use, so a heavy week hits the ceiling and capture pauses. The memory system fails precisely when there is the most to remember.

The fix was to move the observer onto a different model through a local bridge. The bridge presents an OpenAI-compatible chat-completions endpoint, and the memory plugin’s own compatible-provider setting points at it. No fork of the plugin, no patched capture path.

The interesting part is the process model. The plugin’s provider is stateless and resends the whole observer conversation on every call. A one-shot CLI invocation is not: it pays the startup cost on every request. The bridge keeps warm processes and remembers what each one has already seen, so a request whose history is a prefix of the warm process’s history sends only the new messages. Anything else is replayed into a fresh process as one flattened prompt.

That produced the numbers that justified the design: about 5 seconds per cold call, about 2.7 seconds warm, and four parallel calls in about 7 seconds. A process retires after 25 turns or when its context passes 120,000 tokens, with two spares and a hard cap of six, so a burst queues instead of forking the host.

The cost is real: roughly 9,000 input tokens per observation, most of it the tool’s own system prompt rather than the observation. That is acceptable on a plan with generous limits and wasteful on a metered one, which is why the bridge is a local component with an explicit model setting rather than a hidden default.

The feedback loop that produced 290 junk sessions

The memory plugin watches agent sessions. The bridge runs agent sessions. Nobody connected those two facts on the first install.

Every warm process the bridge started was a session, so the plugin observed the bridge’s own conversations, compressed them into observations, and sent those observations back through the bridge. That started more sessions. In five minutes the database held about 290 junk sessions under a project named after the bridge’s working folder.

The fix is a pair of exclusions. The bridge runs its processes in a dedicated empty folder, and the installer adds that path to the plugin’s excluded projects. The pool is also hard-capped at six processes of roughly 100 MB each, so a burst can slow capture but cannot fork unbounded processes. The verification is a count that should stay at zero:

select count(*) from sdk_sessions
where project = 'bridge-workdir';

This is the failure mode shared memory creates and single-agent memory does not: any agent that observes other agents can observe itself. A process cap is not enough because the loop is logical, so the exclusion has to be explicit.

Per-agent memory vs a shared store vs synced files

Approach Cross-tool recall Provenance Failure mode Operational cost When it fits
Each agent keeps its own memory None Implicit in which tool you ask The other agent re-derives known work Low One agent, one repository
One shared store with one capture pipeline Both directions Recorded per write Feedback loops, repository-name collisions Medium: one store, one worker Two or more agents on the same work
Syncing the database file between machines Delayed at best Whatever the file held Corruption when the log is copied live High and risky Almost never

Which should you choose? If one agent does all the work, use its built-in memory and stop there. As soon as a second agent touches the same repositories, put both writers into one store with provenance and one capture pipeline, because the value comes from recall in both directions and the cost comes from duplicating databases. Syncing the database file is the option that looks easiest and fails worst: a live write-ahead log is not a portable file, and copying it risks both corruption and silent divergence.

What broke and what we changed

The observer observed itself. About 290 junk sessions in five minutes, fixed by running the bridge in a dedicated folder and excluding that folder from capture. The verification is a query that should return zero, not a hope.

Capture competed with interactive use. The observer ran on the same limited plan as the chat sessions, so memory paused exactly when the week was heavy. Moving it to a separate model through a local bridge decoupled the two budgets.

Cold starts dominated the observer’s latency. A fresh process per observation cost about 5 seconds of startup. The warm pool with delta replay cut the per-observation time to about 2.7 seconds and made parallel capture practical.

The database was too large to copy. An install that cloned the database between machines would have moved tens of gigabytes and created a second source of truth. The integration deliberately does not copy it, and documents a stopped-worker export as the only safe migration path.

A client that asked for streaming. The memory plugin accepts a plain JSON reply even when it asks for streaming, so the bridge never had to implement it. It answers 503 when the upstream tool cannot start, which makes an unavailable worker visible instead of silent.

Frequently asked questions

What is shared agent memory?

Shared agent memory is one history store that several coding agents read from and write to, with each write tagged by source. It lets an agent see decisions and fixes made in another tool, instead of starting every session with only its own context.

Can two coding agents use the same memory database?

Yes, if both write through one capture pipeline and the reader merges both sources. Sharing the database alone is not enough: if startup injection stays source-filtered, both tools write to the same file and still cannot recall each other's work.

Why does provenance matter in a memory store?

Because a memory from a different agent was produced by a different model with different instructions. Without provenance, every note looks equally authoritative and search results cannot be weighted or filtered. Provenance costs one field at write time and makes every later query answerable.

What should an agent remember between sessions?

Decisions and their reasons, fixes and the symptoms they addressed, and constraints discovered in production. Not raw transcripts. A compact index injected at session start plus on-demand search beats loading history wholesale, and it keeps the context budget for the work.

Why route memory processing to a different model?

Because observation runs on every tool call and competes with interactive use for the same limit. Moving it to a separate model through a local bridge keeps capture running during a busy week. The trade-off is roughly 9,000 input tokens of fixed overhead per observation.

How do you stop a memory system observing itself?

By excluding the memory worker's own working directory from capture and running its processes somewhere identifiable. A process cap alone does not help, because the loop is logical: observations create sessions, and sessions create observations. Verify with a query that should return zero.

Is it safe to sync the memory database through a file-sync service?

No. SQLite's write-ahead log and the database file have to stay consistent, and a file-sync service can copy one without the other or replay writes out of order. Use the tool's supported export or a stopped-worker copy instead of live-syncing the files.