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.
Build the MCP server
The MCP server is behind a feature flag.
cargo build --release --features mcpRegister 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.
claude mcp add lemmalog --env LEMMALOG_MCP_PATH=/tmp/lemmalog.snapshot -- \
$(pwd)/target/release/lemmalog-mcpAssert 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.
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)"}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.
LEMMALOG_MCP_PATH=/tmp/lemmalog.snapshot lemmalog-cli query --goal 'current("s", R, O)'Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
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
How Lemmalog compares
Lemmalog alongside other open-source agent memory tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| Claude-Mem | ★ 94.4k | Persistent memory layer for coding agents: it captures what an agent does during a session, compresses it into semantic summaries, and injects the relevant parts back into later sessions. |
| Mem0 | ★ 65.8k | A memory layer that you add to existing LLM agents to extract, store, and recall user facts and preferences across sessions using vector, graph, and key-value backends. |
| MemPalace | ★ 59.2k | Local-first agent memory that stores conversations verbatim instead of summarising them, with a structured palace index, pluggable vector backends and an MCP server. |
| OpenViking | ★ 38.3k | A context database that stores an agent's memories, resources, and skills as one browsable viking:// filesystem with three-tier (abstract/overview/details) on-demand loading. |
| Graphiti | ★ 31.1k | A library that builds a temporal knowledge graph from an agent's conversations and data so facts can be tracked and queried as they change over time. |
| Cognee | ★ 30.9k | A graph-native memory engine that turns raw documents and conversations into a queryable knowledge graph for agents that need to build lasting knowledge. |
| Supermemory | ★ 30.8k | A memory and context engine that ingests information across tools and sessions and can run fully locally, acting as a second brain for AI applications. |
| Lemmalog | ★ 316 | Agent memory as a deductive database, with proofs instead of recall |