Skip to content
AgentEnsemble AgentEnsemble
Get Started

Shared Memory Across Agent Ensembles: Consistency Models for Distributed State

When agent ensembles operate as independent services on a network, they occasionally need to share state. The question is not whether to share state — it is how to share it without creating the coordination problems that shared mutable state always creates in distributed systems.

Not all shared state needs the same consistency guarantees:

  • Inventory notes are advisory. Eventual consistency is fine.
  • Room assignments are exclusive. This needs distributed locks or optimistic locking.
  • Configuration preferences are rarely updated. Eventual consistency with version tracking works well.

SharedMemory with configurable consistency

Section titled “SharedMemory with configurable consistency”

AgentEnsemble v3.0.0 introduces SharedMemory with per-scope consistency selection:

ModelBehaviorUse case
EVENTUALLast-write-wins, no coordinationContext, preferences, notes
OPTIMISTICVersion-checked writes, retry on conflictCounters, shared documents
LOCKEDDistributed lock before each read/writeRoom assignments, exclusive resources

Different scopes can use different models:

SharedMemory inventory = SharedMemory.builder()
.store(MemoryStore.inMemory())
.consistency(Consistency.EVENTUAL)
.build();
SharedMemory rooms = SharedMemory.builder()
.store(MemoryStore.inMemory())
.consistency(Consistency.LOCKED)
.build();

The useful insight is that shared state in agent networks is not monolithic. Different categories of state need different consistency guarantees, and forcing a single model is either too expensive or too weak.

The consistency model is a property of the data, not a property of the system. Choose it based on what happens when two ensembles access the same state concurrently.


Shared memory is part of AgentEnsemble. The shared memory guide covers the full API including consistency models and network configuration.