Skip to main content
Glama

PyPI CI Tests Python MCP License: Apache-2.0 Part of Benni OS Benni OS

"Stop letting AI agents drown in conversational chatter. Bi-temporal truth graph at 85% less token overhead."

Quickstart • Why Vector Stores Fail • Bi-Temporal Architecture • Token FinOps • MCP Integration • Enterprise Benni OS

In 2026, most developers build agent memory using naive vector databases (RAG embeddings):

  1. Semantic Similarity Destroys Temporal Causality: An agent asks: "What is the customer's subscription plan?". The vector database returns: "Customer account was suspended in 2023" (score 0.89) instead of "Customer upgraded to Enterprise in 2026" (score 0.86) because the old text had more matching keywords. The agent acts on obsolete, contradicted facts.

  2. Context Window Inflation & Token Bleed: Storing raw multi-turn conversation transcripts blows up context windows. Feeding 30 turns of chat back into the model burns 10,000+ tokens per turn, increasing inference latency and costs exponentially.

  3. Decision Decay in Agent Handoffs: When specialized agents collaborate (e.g., Researcher → Coder → Tester), architectural decisions are lost in chat noise because there is no typed, immutable decision ledger.

Agent Memory Mesh solves this completely. Derived from the Benni Master OS v9.4 Doctrine (Skill 60 & 61), it replaces probabilistic text search with a deterministic Bi-Temporal Knowledge Graph that automatically supersedes obsolete facts, compresses conversational context by over 85%, and provides cryptographic snapshot rollbacks.

Related MCP server: GraphHub

🏗️ Bi-Temporal Knowledge Graph Architecture

Every memory node in Agent Memory Mesh is tracked along two orthogonal timelines:

  • Valid Time: When the fact is true in the physical world (valid_from → valid_to).

  • Transaction Time: When the agent system asserted or learned the fact.

  LangChain / CrewAI / AutoGen / MCP Clients / Multi-Agent Swarms
         │
         ├──► MemoryGraph.add_fact / add_decision / query
         └──► McpMemoryServer (JSON-RPC 2.0 Tools)
                       │
                       ▼
  ┌─────────────────────────────────────────────────────────────────────┐
  │                         agent-memory-mesh                           │
  │                                                                     │
  │  ┌───────────────────┐  ┌───────────────────┐  ┌─────────────────┐  │
  │  │ Bi-Temporal Graph │  │  Lossless Graph   │  │ Atomic          │  │
  │  │ • Valid Time      │─►│  Compressor       │─►│ Checkpoint      │  │
  │  │ • Transaction Time│  │  • Semantic Triple│  │ • SHA-256 Seal  │  │
  │  │ • Auto-Supersede  │  │  • Decision Ledger│  │ • Tamper Guard  │  │
  │  └───────────────────┘  └───────────────────┘  └─────────────────┘  │
  │                                                                     │
  │  ┌───────────────────┐  ┌───────────────────┐  ┌─────────────────┐  │
  │  │ Storage Backends  │  │  Framework        │  │ Tools & CLI     │  │
  │  │ • SQLite Graph DB │  │  Adapters         │  │ • doctor        │  │
  │  │ • In-Memory       │  │  • LangChain      │  │ • bench_matrix  │  │
  │  │ • BaseMemoryABC   │  │  • CrewAI / MCP   │  │ • store/query   │  │
  │  └───────────────────┘  └───────────────────┘  └─────────────────┘  │
  └─────────────────────────────────────────────────────────────────────┘
         │                                         │
         ▼                                         ▼
   SQLite Bi-Temporal Store                 SHA-256 Sealed Snapshots
   Zero-Contradiction Ground Truth          85%+ Token-Reduced Context

See docs/ARCHITECTURE.md for the full internal specification.

graph TD
    A["Fact A: customer plan = free_tier<br><i>Valid: Jan 2026 to Jun 2026</i>"] -->|Automatic Supersede Edge| B["Fact B: customer plan = enterprise<br><i>Valid: Jun 2026 to Present (Active)</i>"]
    B --> C{"QUERY ENGINE"}
    C -->|Query Present| D["Returns Fact B (Enterprise)<br><i>Zero Obsolete Noise</i>"]
    C -->|Time-Travel as-of March 2026| E["Returns Fact A (Free Tier)<br><i>Accurate Historical Replay</i>"]

The Superseding Law: When a new fact is asserted with identical (subject, predicate), previous facts are automatically closed and linked via a directed supersedes relation. Contradictions are eliminated at write time.

🚀 Quickstart in 30 Seconds

1. Installation

pip install agent-memory-mesh

2. Time-Aware Agent Memory (Eliminate Obsolete Data)

from datetime import datetime, timezone
from memory_mesh import MemoryGraph

graph = MemoryGraph()

# January: Customer on free tier
graph.add_fact("customer:acme", "plan", "free_tier", valid_from="2026-01-01T00:00:00+00:00")

# June: Customer upgrades to enterprise
graph.add_fact("customer:acme", "plan", "enterprise", valid_from="2026-06-01T00:00:00+00:00")

# Present Query: Returns ONLY active Enterprise plan
active_plan = graph.query(subject="customer:acme", predicate="plan")
print("Active Plan:", active_plan[0].object_value)  # "enterprise"

# Time-Travel Query: What was their plan in March 2026?
march_plan = graph.query(
    subject="customer:acme",
    predicate="plan",
    as_of_valid_time=datetime(2026, 3, 1, tzinfo=timezone.utc),
)
print("Historical Plan in March:", march_plan[0].object_value)  # "free_tier"

3. Record Immutable Decisions with Rationales

graph.add_decision(
    subject="database_choice",
    chosen_option="postgresql_16",
    rationale="Sub-millisecond bi-temporal query performance and JSONB support",
    alternatives=["mongodb", "mysql_8"],
)

4. Lossless Context Compression (>85% Token Reduction)

from memory_mesh import LosslessGraphCompressor

compressor = LosslessGraphCompressor()

# Compiles active graph state into a dense prompt injection block
prompt_block = compressor.compress(graph)
print(prompt_block)

Output:

### [BI-TEMPORAL KNOWLEDGE GRAPH MEMORY]
The following ground-truth facts and decisions are active and verified. Use them over assumptions:

**Active Verified Facts:**
- `customer:acme` → `plan`: enterprise

**Immutable Decisions & Rationales:**
- `Decision: database_choice` = postgresql_16 (Rationale: Sub-millisecond bi-temporal query performance) [Rejected: mongodb, mysql_8]

📊 Token FinOps & Lossless Context Compression

Metric

Raw Multi-Turn Chat Transcript

Naive Vector RAG (Embeddings)

Agent Memory Mesh

Token Consumption

~1,500 tokens

~800 tokens

~130 tokens

Token Reduction

0%

~46%

85% – 91% Saved

Obsolete Contradictions

Common (chat history contains outdated facts)

High (semantic similarity ignores time)

Zero (automatically superseded)

Decision Traceability

Buried in chat dialogue

Chunk-dependent

Dedicated immutable decision ledger

Time-Travel History

Impossible

Inaccurate

Deterministic (as_of_valid_time)

Prompt Injection Latency

High

Embedding API overhead

Near-zero (< 1ms)

🔌 Model Context Protocol (MCP) Server

Agent Memory Mesh includes a built-in MCP server for Claude Desktop, Cursor, Windsurf, and Antigravity:

from memory_mesh import McpMemoryServer

server = McpMemoryServer()

# Register directly into your MCP runtime:
# • memory_store: Stores ground-truth fact
# • memory_decision: Stores architectural/business decisions
# • memory_recall: Queries active facts
# • memory_timeline: Retrieves chronological evolution
# • memory_compress: Compiles token-dense prompt context
# • memory_snapshot: Exports SHA-256 sealed checkpoint

🧩 Framework Integrations

LangChain & LangGraph

from memory_mesh import MemoryMeshLangChainAdapter

adapter = MemoryMeshLangChainAdapter()
adapter.store_fact("user:carter", "role", "security_engineer")
adapter.store_decision("api_framework", "FastAPI", rationale="Native Pydantic v2 validation")

# Attach directly to agent prompt context
prompt_context = adapter.get_prompt_context()

CrewAI

from memory_mesh import MemoryMeshCrewAIAdapter

crew_memory = MemoryMeshCrewAIAdapter()
crew_memory.save("Deployment target is AWS us-east-1", metadata={"subject": "aws", "predicate": "region"})

🛡️ Atomic Checkpoint Protocol (Skill 61)

Every snapshot exports an atomic, SHA-256 sealed JSON checkpoint:

from memory_mesh import AtomicCheckpoint

# Save and seal
AtomicCheckpoint.save_to_file(graph, "state_snapshot.json")

# Restore and verify cryptographic integrity
restored_graph = AtomicCheckpoint.restore_from_file("state_snapshot.json")

💻 Terminal CLI

# Display brand, version, and architecture doctrine
memory-mesh info

# Store verified fact
memory-mesh store "user:alice" "role" "principal_architect"

# Query active memory table
memory-mesh recall --subject "user:alice"

# Inspect compressed prompt block and token savings
memory-mesh compress

# Export SHA-256 sealed checkpoint
memory-mesh snapshot backup.json

# Probe environment, bi-temporal graph, SQLite & checkpoint integrity
memory-mesh doctor

# Run multi-scale compression & throughput benchmark matrix
memory-mesh matrix --facts 25,100,250

📁 Project Structure

agent-memory-mesh/
├── docs/
│   └── ARCHITECTURE.md                  # Skill 60/61 bi-temporal graph specification
├── examples/
│   ├── 01_quickstart_bitemporal.py      # Valid-time superseding & time-travel queries
│   ├── 02_lossless_compression.py       # 85%+ token reduction vs raw chat logs
│   ├── 03_atomic_checkpoint.py          # SHA-256 sealed snapshot save/restore
│   ├── 04_langchain_agent_memory.py     # LangChain memory adapter integration
│   └── 05_mcp_memory_server.py          # Model Context Protocol (MCP) memory server
├── memory_mesh/
│   ├── __init__.py                      # Public package exports
│   ├── py.typed                         # PEP 561 type marker
│   ├── version.py                       # Version, doctrine & maintainer metadata
│   ├── adapters/
│   │   ├── __init__.py                  # Adapter exports
│   │   ├── crewai.py                    # CrewAI shared memory adapter
│   │   ├── langchain.py                 # LangChain memory adapter
│   │   └── mcp_server.py                # Native MCP JSON-RPC 2.0 server
│   ├── cli/
│   │   ├── __init__.py                  # CLI package marker
│   │   └── main.py                      # Click + Rich CLI (info, store, query, compress, doctor, matrix)
│   ├── core/
│   │   ├── __init__.py                  # Core graph exports
│   │   ├── checkpoint.py                # SHA-256 sealed atomic graph snapshots
│   │   ├── compressor.py                # Lossless semantic triple & decision compressor
│   │   ├── graph.py                     # Bi-temporal MemoryGraph with auto-supersede
│   │   └── models.py                    # MemoryNode, MemoryRelation & BiTemporalInterval
│   ├── storage/
│   │   ├── __init__.py                  # Storage backend exports
│   │   ├── base.py                      # Abstract BaseMemoryStorage interface
│   │   ├── memory.py                    # Zero-I/O InMemoryStorage backend
│   │   └── sqlite.py                    # Persistent SQLite graph storage backend
│   └── tools/
│       ├── __init__.py                  # Diagnostics & benchmark tool exports
│       ├── bench_matrix.py              # Multi-scale compression & throughput matrix
│       └── doctor.py                    # Environment, bi-temporal & SQLite probe
├── scripts/
│   ├── benchmark_compression_ratio.py   # Token compression & throughput benchmark
│   └── gate_bitemporal_integrity.py     # Fail-closed bi-temporal & tamper gate runner
└── tests/
    ├── __init__.py                      # Test suite package marker
    ├── conftest.py                      # Shared pytest fixtures
    ├── test_adapters.py                 # LangChain, CrewAI & MCP adapter tests
    ├── test_checkpoint_restore.py       # Snapshot roundtrip & tamper detection tests
    ├── test_cli.py                      # Click CLI command tests
    ├── test_compressor.py               # Lossless compression & token savings tests
    ├── test_graph_and_causality.py      # Superseding, time-travel & decision tests
    ├── test_models_and_bitemporal.py    # Temporal interval & node sealing tests
    ├── test_sqlite_storage.py           # SQLite node & relation persistence tests
    └── test_tools_and_scripts.py        # Doctor, bench_matrix & gate script tests

🌐 The Benni OS Open-Source Ecosystem

agent-memory-mesh is part of the Benni OS decentralized agentic infrastructure. Explore the 17 open-source repositories powering sovereign AI agents:

Repository

Focus & Architecture

Stars

conductor-sdd

Zero-Dependency Spec-Driven Development, Static AST Drift Detector & MCP Guardrail

GitHub Stars

benni-inference-engine

High-Throughput Sovereign Local Inference for 8GB–16GB Consumer GPUs

GitHub Stars

agent-eval-harness

Deterministic Zero-Cloud Agent Evaluation, Red-Teaming & Benchmark Harness

GitHub Stars

agent-code-sandbox

Micro-Second Zero-Dependency Code Sandbox & Execution Shield for AI Agents

GitHub Stars

agent-deep-research

Autonomous Multi-Source Deep Research & Evidence Synthesis Engine

GitHub Stars

agent-browser-mesh

Token-Saving Resilient Headless Browser Automation & A11y DOM Compiler

GitHub Stars

agent-intent-compiler

Deterministic Intent Compiler & Typed DAG Execution Planner for AI Agents

GitHub Stars

agent-token-optimizer

Sub-Millisecond Context Compression & Semantic Deduplication Engine

GitHub Stars

bio-sync-operator-os

Real-Time Biometric Swarm Governance & 120 FPS Resonant Kinetic Interface

GitHub Stars

agent-cyber-sentinel

Zero-Trust Runtime Security, Prompt Injection Firewall & Secrets Redaction

GitHub Stars

agent-run-ledger

Deterministic Multi-Step Task Execution Ledger & Anti-Looping Engine

GitHub Stars

reality-lock

Cryptographic State Verification & Invariant Proof Engine for Agents

GitHub Stars

agent-memory-mesh

Hybrid Vector + BM25 Hierarchical Session Memory & Continuity Engine

GitHub Stars

benni-operator-gateway

Human-in-the-Loop Approval & Policy Enforcement Gateway

GitHub Stars

mcp-forge

Rapid Model Context Protocol (MCP) Server Scaffolding & Dynamic Tooling

GitHub Stars

benni-nexus

Autonomous Multi-Agent Intent Routing & Swarm Coordination Hub

GitHub Stars

community-autopilot

Autonomous GitHub Community Triaging & PR Feedback Agent

GitHub Stars

🏛️ Commercial & Sovereign Architecture

This open-source stack serves as the decentralized foundation for the Benni OS autonomous swarm kernel and commercial engineering platform:

🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md. All pull requests must pass 100% of tests (pytest tests).

📄 License & Provenance

Agent Memory Mesh is licensed under the Apache License, Version 2.0.

© 2026 Benni OS Core Engineering Group — Engineered by Benni Alencar. All rights reserved.

agent-memory-mesh — Part of the Benni OS Core Engineering Group

AGENT_MEMORY_MESH • SKILL_60_61_NATIVE • BI_TEMPORAL_GRAPH • LOSSLESS_COMPRESSION • APACHE_2.0

Engineered by Benni Alencar & the Benni OS Core Engineering Group

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Provides versioned, structured memory for AI agents, allowing them to store facts, detect conflicts, and track knowledge history via a hosted SaaS platform. It enables efficient hierarchical information retrieval and semantic search while keeping token usage constant as memory scales.
      7
      20 npm
      8
      Apache 2.0
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables persistent, graph-based memory for AI agents, allowing them to store, traverse, and recall relationships between facts, decisions, and context across sessions for efficient reasoning and reduced token usage.
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      A long-term memory system built for AI Agents. Agent wakes up already knowing who he is, not querying "who am I?" every session. Every turn calling back accurate memory context. Achieving accurate memory hits while also preventing memory from expanding at scale. No compression, no forgetting.
      42
      -