Bi-Temporal Memory for AI Agents: Knowledge Graphs, Auditable Retention, and Lossless Context Compression

Why flat vector RAG collapses when facts mutate over time, and how BenniAlencar/agent-memory-mesh and BenniAlencar/agent-deep-research unify bi-temporal typed graphs, strict tenant isolation, BM25 + graph hybrid retrieval, and lossless context compression.

Bi-Temporal Memory for AI Agents: Knowledge Graphs, Auditable Retention, and Lossless Context Compression

1. The Amnesia & Stale-Fact Paradox in Agentic RAG

Most production AI agents do not fail because the underlying foundation model cannot reason. They fail because their memory substrate cannot distinguish historical truth from current truth, and cannot compact long-horizon observations without silently erasing provenance.

When teams bolt a flat vector database onto an autonomous loop, three failure modes emerge under load:

Core Thesis: Production agent memory is a database systems problem, not an embedding similarity problem. By combining bi-temporal typed knowledge graphs in BenniAlencar/agent-memory-mesh with pointer-preserving compaction in BenniAlencar/agent-deep-research, agents gain auditable recall and lossless long-horizon context.

2. Valid-Time vs. Transaction-Time: The Bi-Temporal Edge Model

In classical temporal databases (SQL:2011 and immutable accounting ledgers), overwriting a row destroys auditability. agent-memory-mesh models every fact as an immutable bi-temporal edge carrying two orthogonal time axes:

flowchart LR A["New Observation\n(Event @ t_valid)"] --> B["Typed Triple Extractor\n(Subject, Predicate, Object)"] B --> C{"Existing Edge\nConflict?"} C -->|"No"| D["Insert Active Edge\nt_tx_superseded = NULL"] C -->|"Yes"| E["Close Prior Edge\nSet t_tx_superseded = now()"] E --> F["Append New Edge\nLink superseded_by pointer"] D --> G["Point-in-Time Audit\nAS OF (t_valid, t_tx)"] F --> G

Because superseded edges are closed rather than deleted, an operator can execute two fundamentally different queries against the same graph: "What is the customer's rate limit today?" (t_tx_superseded IS NULL) and "What did the agent believe the rate limit was when it triggered the incident on Tuesday?" (AS OF t_tx = Tuesday).


3. Typed Triples, Provenance & Strict Tenant Isolation

Unstructured text chunks cannot enforce schema invariants. Every assertion persisted in agent-memory-mesh is normalized into a Typed Triple bound to an explicit tenant_id partition:

from dataclasses import dataclass
from typing import Optional

@dataclass(frozen=True)
class BiTemporalTriple:
    tenant_id: str          # Hard partition key across graph + BM25 index
    subject_id: str         # Typed entity, e.g. "service:billing-api"
    subject_type: str       # "service" | "user" | "policy" | "artifact"
    predicate: str          # Controlled relation, e.g. "deployed_in"
    object_id: str          # e.g. "region:eu-central-1"
    confidence: float       # Calibrated [0.0, 1.0]
    source_digest: str      # SHA-256 of raw evidence payload
    t_valid_start: str      # ISO-8601 UTC
    t_valid_end: Optional[str]
    t_tx_recorded: str      # ISO-8601 UTC
    t_tx_superseded: Optional[str] = None

Notice two critical engineering properties:

  1. Storage-Level Tenant Isolation: Every graph adjacency lookup and lexical index scan requires tenant_id as a mandatory prefix key. Multi-hop traversals cannot cross tenant boundaries even if two tenants reference identical external entity names like service:auth-gateway.
  2. Immutable Provenance Binding: Every triple stores source_digest, anchoring the extracted claim to the exact raw tool output, document chunk, or API payload that justified it.

4. Hybrid Retrieval: BM25 Lexical Precision + Multi-Hop Graph Traversal

Pure vector search notoriously struggles with exact identifiers—error codes like ERR_TLS_CERT_ALTNAME_INVALID, ticket IDs, or specific function symbols. Pure graph traversal, conversely, requires an exact starting node.

agent-memory-mesh solves this with a two-stage hybrid retrieval pipeline fused via Reciprocal Rank Fusion (RRF):


5. Lossless Context Compression in agent-deep-research

Deep research and multi-step engineering workflows routinely accumulate 150,000+ tokens of web scrapes, code diffs, and tool outputs. Re-injecting raw payloads into every turn blows past latency and cost budgets, while lossy LLM summarization destroys citations and exact numbers.

BenniAlencar/agent-deep-research pairs with agent-memory-mesh to implement Lossless Context Compression:


6. Architecture Comparison: Agent Memory Substrates

Dimension Sliding Window + Summary Flat Vector RAG agent-memory-mesh + deep-research
Temporal Semantics None (chronological overwrite) Unversioned chunks Bi-Temporal (Valid + Transaction Time)
Fact Mutation Handling Silently forgets prior state Stale chunks compete with updates Supersedes edge; preserves full audit trail
Exact Symbol / ID Recall Lost after compaction Weak (dense embedding blur) BM25 + Graph Hybrid RRF
Context Compression Lossy LLM paraphrasing Top-k chunk truncation Lossless SHA-256 Pointer Compaction
Multi-Tenant Isolation Session-only Post-filter metadata (error-prone) Mandatory Prefix-Key Partitioning

Build Auditable, Lossless Agent Memory

Explore the open-source implementations powering Benni OS: inspect the bi-temporal graph engine in agent-memory-mesh and lossless research compaction in agent-deep-research.

Explore agent-memory-mesh → Explore agent-deep-research →

Frequently Asked Questions

What is the difference between valid-time and transaction-time in AI agent memory?
Valid-time tracks when a fact was true in the external world (for example, a user's subscription tier or an API endpoint version from March 1 to May 15). Transaction-time tracks when the agent recorded or superseded that fact in its memory ledger. Separating both axes lets an agent answer both "what is true right now?" and "what did the agent believe was true at audit timestamp T?" without overwriting history.
Why does flat vector RAG fail for long-running autonomous agents?
Flat vector stores treat memory as an unversioned bag of embeddings. When a constraint or state changes, old chunks remain semantically similar to the query and outrank newer updates, causing stale-fact hallucinations. Vector similarity also struggles with exact entity identifiers, multi-hop causal chains, and strict per-tenant isolation.
How does lossless context compression work without dropping provenance?
Instead of destructive LLM summarization that discards raw evidence, lossless context compression replaces verbose intermediate payloads with content-addressed SHA-256 pointers and typed graph triples. When a downstream reasoning step in agent-deep-research needs exact quotes, numbers, or citations, it dereferences the pointer on demand while keeping the active prompt window compact.
How does BenniAlencar/agent-memory-mesh enforce multi-tenant isolation?
Every node, typed edge, BM25 inverted index entry, and retention policy in agent-memory-mesh is scoped to an explicit tenant_id partition key. Cross-tenant graph traversal is impossible at the storage and query-planner layers, preventing context leakage across workspaces or customer sessions.