Back Home

代理框架

Lemmalog Uses Datalog to Maintain Agent Memory, Automatically Invalidating Downstream Conclusions When Facts Are Retracted

Lemmalog separates agent memory into facts extracted by an LLM and verifiable state maintained by a rules engine. Preliminary evaluations show that it can substantially reduce context at answer time, though overall accuracy remains constrained by fact extraction and entity alignment.

Steve Jurvetson · CC BY 2.0 · Image source
zh-Hant

Lemmalog redefines long-term agent memory as a “continuously updated deductive database,” rather than a system that searches historical conversations for similar passages. The LLM converts natural language, code, or debugging output into structured facts; a Datalog engine written in Rust computes rule closure, records validity periods and sources, and recomputes only affected downstream conclusions when base facts are corrected. This addresses a problem that vector search handles poorly: old information may remain semantically relevant even after it has become invalid.

The system supports stratified Datalog, semi-naive fixed-point evaluation, explicit fact retraction, confidence and provenance annotations, and a `why()` function that displays derivation chains. Name normalization maps local entities from different sessions to shared objects, while BM25, an entity graph, and embeddings preserve fuzzy retrieval capabilities. The project also provides 12 MCP tools that Claude Code or Kimi CLI can use to run queries, install rules, simulate `what_if` scenarios, and persist snapshots across sessions. Both the [author’s technical write-up](https://pwning.systems/posts/llm-memory-program-analysis/) and the [MIT-licensed repository](https://github.com/JordyZomer/lemmalog) are publicly available.

The author used Claude Sonnet 4.6 for one-time information extraction, then reused MemEval’s reader and evaluation pipeline. Across three LongMemEval runs, the average F1 was 0.463, below PropMem’s 0.550, but the answering model received only about 2,700 tokens per question, compared with roughly 104,000 tokens for the full history. On LoCoMo, F1 was 0.533, with context reduced to about one-sixth of the original size. Performance was stronger on knowledge-update and false-premise questions, but weaker on cross-session and implicit reasoning.

These figures cannot yet be translated directly into cost savings: creating the facts still incurs a one-time LLM extraction cost, and the systems being compared may not use exactly the same front-end model. Engineering teams should next examine extraction omissions, representations of conditional knowledge, consistency with multiple writers, and whether untrusted content can contaminate an entire derivation chain by introducing erroneous facts.

Sources

  1. I accidentally turned LLM memory into program analysis
  2. JordyZomer/lemmalog