# Lemmalog

> Agent memory as a deductive database, with proofs instead of recall

- Category: Agents & Automation / Agent Memory
- Language: Rust
- Licence: MIT
- Repository: https://github.com/JordyZomer/lemmalog
- Canonical page: https://ai-tldr.dev/tools/lemmalog/
- Updated: 2026-08-28

## In short

Lemmalog is a Datalog engine built to serve as an LLM agent's memory. It sits in the Agent Memory category of the Agents & Automation tools and is open-source, written in Rust and licensed MIT. To get started: build the MCP server.

## Overview

Lemmalog is a Datalog engine built to serve as an LLM agent's memory. Its thesis is that an agent's memory should be a deductive database rather than a pile of retrieved text: base facts are asserted at the ingestion boundary by an extractor, rules derive closures, temporal projections, contradiction candidates and relevance diffusion, and every derived fact carries provenance back to the source episodes it came from. Because derivation is incremental, each conversation turn updates the derived views instead of re-deriving them — or, worse, re-reasoning them in context.

The engine is written in Rust and parses its rules at runtime (an interpreter, not a proc-macro), with stratified negation, seminaive fixpoint evaluation, bi-temporal facts, semiring annotations that carry confidence and provenance, and magic-sets demand evaluation for point queries. A why() call returns the proof tree behind any fact, so an agent can check where a conclusion came from before trusting it, and retracting one fact scopes recomputation to its transitive dependents.

It is packaged three ways for agent use: a Rust crate, a REPL, and an MCP server exposing twelve tools to harnesses such as Claude Code and Kimi CLI. The intended division of labour is that the host model reads the conversation and asserts triples in a line protocol, while Lemmalog derives closures, temporal views, canonicalizations and aggregations deterministically. The repo also ships a generic agent skill that encodes the working discipline the project's own experiments converged on.

## What it does

- Runtime-parsed stratified Datalog with negation-as-absence, seminaive fixpoint evaluation, and magic-sets demand evaluation for point queries
- Provenance and confidence carried as semiring annotations, so why() returns a proof tree back to the source episodes
- Bi-temporal facts (valid_from / valid_to / asserted_at) with scoped negative deltas: retraction recomputes only the transitive dependents
- MCP server (12 tools) plus a headless CLI over the same snapshot, for harnesses and for sub-agents or cron jobs that cannot reach MCP
- Entity resolution by star-shaped aliasing that derives alias_conflict facts instead of silently merging two identities
- Hybrid retrieval (BM25 plus entity and graph boosting) with a budget-aware context assembler, and what_if hypotheticals with byte-identical store restore

## Getting started

Lemmalog builds with Cargo. The quickest path for an agent harness is the MCP server; the REPL is useful for learning the rule grammar first.

1. Build the MCP server

   The MCP server is behind a feature flag.

```bash
cargo build --release --features mcp
```

2. Register it with your harness

   Both Claude Code and Kimi CLI take a stdio JSON-RPC command. Set LEMMALOG_MCP_PATH at registration time to persist the store across sessions.

```bash
claude mcp add lemmalog --env LEMMALOG_MCP_PATH=/tmp/lemmalog.snapshot -- \
  $(pwd)/target/release/lemmalog-mcp
```

3. Assert facts, install rules, then query

   The host model asserts triples with the line protocol S --rel[conf]--> O; rules derive the rest. Note the grammar: bare capitalized words are variables, so entity names must be quoted.

```text
lemmalog_observe       {"facts": "Alice --works_at--> Acme\nAlice --manager--> Bob", "ts": 100}
lemmalog_install_rules {"rules": "reports_to(X,Y) :- current(X,\"manager\",Y)."}
lemmalog_query         {"goal": "reports_to(\"Alice\", Y)"}
```

4. Ask why before trusting a conclusion

   why() returns the proof tree for a derived fact, down to the episodes that supported it. Sub-agents and scripts can use the headless CLI against the same snapshot.

```bash
LEMMALOG_MCP_PATH=/tmp/lemmalog.snapshot lemmalog-cli query --goal 'current("s", R, O)'
```

## When to use it

- Give a long-running investigation, audit, or debugging session a working memory whose conclusions can be re-checked rather than re-remembered
- Keep an agent's knowledge consistent under change: retract one fact and have every conclusion built on it invalidated automatically
- Replace a growing transcript in the context window with a derived, budget-aware context block plus verbatim provenance
- Share one deductive store between a parent agent and its sub-agents through the MCP server and the headless CLI

## Version history

- 2026-08-28: Lemmalog was published with a write-up arguing that agent memory should be a deductive database rather than retrieved text, alongside the engine, MCP server, REPL and design document.
