Skip to main content

Token optimization layer for multi-agent LangGraph systems — cut shared-artifact token costs via MESI cache coherence, one import change

Project description

agent-coherence

The coherence layer for multi-agent systems — vendor-neutral, framework-agnostic.

When agents share state, one of them is reading a stale copy. The next write lands on a version that has already moved — a lost write, or a divergent view two agents now disagree on, and the error propagates to every decision downstream. agent-coherence makes that moment visible and serves the current version on the next read instead of rebroadcasting the full artifact every turn. Same library, same protocol, across LangGraph, CrewAI, AutoGen, the OpenAI Agents SDK, and any custom orchestrator. Same behavior regardless of which model provider (Anthropic, OpenAI, Google, Mistral, open-source) the agents talk to.

CI PyPI arXiv Discussions

pip install "agent-coherence[langgraph]"        # LangGraph drop-in
pip install "agent-coherence[crewai]"           # CrewAI adapter
pip install "agent-coherence[openai-agents]"    # OpenAI Agents SDK adapter (experimental)
pip install "agent-coherence[diagnose]"         # ccs-diagnose CLI
pip install "agent-coherence[all]"              # everything
# Before
from langgraph.store.memory import InMemoryStore
store = InMemoryStore()

# After — one import change, no node code changes
from ccs.adapters import CCSStore
store = CCSStore(strategy="lazy")

store.get(), store.put(), store.search() keep working unchanged. Savings show up immediately on any workload where multiple agents read the same artifact more often than they write it.

agent-coherence-replay — invariant-replay for any CoherenceAdapterCore-mediated agent system. LangGraph capture verified in v1 via CCSStore.record_to(path); CrewAI / AutoGen wired through the same seam but unverified — file an issue if it breaks.

Workload Agents Reads:Writes Hit rate Savings
Planning (read-heavy) 4 12:1 75% 69%
Code review (moderate) 3 8:3 60% 47%
High-churn (write-heavy) 4 8:4 50% 29%

Measured on real LangGraph graphs; see docs/reproduce.md and the user guide.


  • 📖 User guide — installation, namespace convention, strategies, observability, telemetry, examples, full API reference
  • 🩺 ccs-diagnose CLI — find divergent reads in your existing LangGraph graph without changing any code
  • 🔍 Why coherence matters — the gap across LangGraph, CrewAI, AutoGen, and Claude Agent SDK
  • 🔐 Security & supply chain — kill switches, hash-pinned install, attestation verification, threat model
  • 📜 Changelog — version history
  • 📄 Paper on arXiv (2603.15183) — formal protocol, TLA+ verification, simulation results

How it works

Each shared artifact is cached locally per agent and reads serve from the local cache when that copy is fresh. Writes commit to a coordinator, which sends lightweight invalidation signals (~12 tokens) to peers so the next read fetches the new version instead of rebroadcasting the full artifact. Consistency is single-writer-multiple-reader per artifact with bounded staleness — peers re-fetch on next read.

Five synchronization strategies ship out of the box: lazy (default), eager, lease (TTL-based), access_count, and broadcast. Pick the one that matches your workload's read/write ratio and how aggressively cached reads should refresh.

Architecture

  • Protocol (ccs.core, ccs.strategies) — coherence state machine and synchronization strategies; no framework dependencies.
  • Coordinator (ccs.coordinator) — authority service tracking directory state, publishing invalidations, and reclaiming stale grants (crash recovery).
  • Adapters (ccs.adapters) — framework integrations for LangGraph, CrewAI, and AutoGen (~100 lines each), plus an experimental OpenAI Agents SDK adapter (Session-cache coherence + RunHooks).
  • Simulation (ccs.simulation) — deterministic tick-driven engine for scenario benchmarks with failure injection.
  • Event bus (ccs.bus) — pluggable transport for invalidation signals; in-memory by default, swap in Redis, Kafka, NATS, or gRPC streams for production.

Protocol safety properties (single-writer, monotonic versioning, crash-recovery sweep invariants) are model-checked with TLA+/TLC. The tla-check CI job runs TLC on every push and PR.

Status

v0.8.4.2 released — ccs-diagnose heatmap multi-writer ranking. A patch over v0.8.4.1: the diagnose report's Per-Artifact Heatmap now ranks genuine multi-writer artifacts — the real coordination signal — above single-writer artifacts whose high share is expected pipeline ordering, adds a writers column and a multi-writer row highlight, and leaves the detection-layer ordering (which drives the top-event callout) unchanged. Presentation-only; no API or core-protocol changes. v0.8.4.1 bounded that same heatmap's share column to [0, 100%] (it previously counted divergent read-pairs against the read count and could exceed 100%). See CHANGELOG.md. The v0.8.3 crash-recovery deprecation cycle and the upcoming v0.9.0 default flip are unaffected.

See CHANGELOG.md for the full version history and releases for tagged artifacts. Alpha — APIs may change before v1.0.

Paper

Token Coherence: Adapting MESI Cache Protocols to Minimize Synchronization Overhead in Multi-Agent LLM Systems arXiv:2603.15183

BibTeX
@article{parakhin2026token,
  title   = {Token Coherence: Adapting MESI Cache Protocols to Minimize
             Synchronization Overhead in Multi-Agent LLM Systems},
  author  = {Parakhin, Vladyslav},
  journal = {arXiv preprint arXiv:2603.15183},
  year    = {2026}
}

Community

Questions, war stories, and ideas welcome in Discussions. If you've hit a stale-read bug in a multi-agent workflow, open an issue — I'd like to hear about it.

License

Apache-2.0. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_coherence-0.8.4.2.tar.gz (469.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_coherence-0.8.4.2-py3-none-any.whl (311.6 kB view details)

Uploaded Python 3

File details

Details for the file agent_coherence-0.8.4.2.tar.gz.

File metadata

  • Download URL: agent_coherence-0.8.4.2.tar.gz
  • Upload date:
  • Size: 469.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for agent_coherence-0.8.4.2.tar.gz
Algorithm Hash digest
SHA256 dec69fa44001fe532f4c5c659340300fdb6efc4745e7ca927ef39cc713f3a469
MD5 59b0d60fbcc40bcfe42078a62c699144
BLAKE2b-256 eb992128e0bd48f4c50d3ca0cc12ac72b3a4376ba7033c59b94bef2f6e9ed5e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_coherence-0.8.4.2.tar.gz:

Publisher: release.yml on hipvlady/agent-coherence

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_coherence-0.8.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_coherence-0.8.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 324ce9922e51cbdc57fcfe1bbf4d5d2ac18ca45c56a5583811641a67730e3dd1
MD5 61136df8a260cfe002a56f377a23d5f3
BLAKE2b-256 64f9e059b2d38dc0c88b0f6f0d65c2d0a29ef20607579691d30d2e58355910ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_coherence-0.8.4.2-py3-none-any.whl:

Publisher: release.yml on hipvlady/agent-coherence

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page