I accidentally turned LLM memory into program analysis
TL;DR Highlight
Keeping LLM memory as Datalog rules beat all published systems on knowledge-update questions
Who Should Read
Agent developers frustrated that their LLM keeps reasoning from assumptions already disproved during long sessions
Core Mechanics
- Memory is two problems: retrieval and current truth
- Vector DBs find past notes relevant to a question.
- They don't know if a note was later disproven or if conclusions built on it are now invalid.
- The LLM extracts facts, the database reasons
- The LLM turns logs, debugger output and prose into structured facts.
- A Datalog engine (Lemmalog) derives and maintains conclusions from rules.
- Removing a fact auto-invalidates its conclusions
- It tracks which facts support each conclusion, keeping it if another derivation remains.
- With no support left, the conclusion disappears.
- You can ask why it believes something
- Every conclusion carries provenance (which observations and rules produced it).
- A conclusion without provenance isn't part of the maintained state.
- Facts get validity intervals so history survives
- Example: viable(primitive_a) [10:14, 12:37), not_viable(primitive_a) [12:37, ...).
- You can answer both the current state and why you once believed otherwise.
- On LongMemEval, 2x+ the F1 of full context with 38x less context
- Lemmalog F1 was 0.463±0.010 vs 0.197 for the author's own full-context GPT-4.1 run.
- Context per question was about 2,700 tokens vs about 104,000.
- The front-end mattered more than the engine
- A 'verify support before answering' instruction made 32 of 102 answerable questions get refused, dropping F1 to 0.371.
- Fixing a bug comparing dates as symbol ids lifted LoCoMo temporal from 0.257 to 0.454.
Community Reactions
- It led on knowledge updates
- On LongMemEval Knowledge Update, Lemmalog scored 0.579 vs PropMem 0.528 and Full Context 0.202.
- Multi-Session was weak at 0.211 vs PropMem 0.582.
- On full LoCoMo it ranks third
- Three runs gave F1 0.533±0.001, behind PropMem 0.605 and OpenClaw 0.557, and Full Context at 0.542.
- Adversarial false-premise questions scored 0.707 vs 0.509 for Full Context.
- Failures were extraction misses, not reasoning
- Multi-session failures were mostly facts never extracted rather than mis-connected.
- Extraction used Claude Sonnet 4.6; later stages used the benchmark's standard readers and judges.
- Commenters recognized the stale-facts problem
- One commenter said Claude records things everywhere and treats disproved facts as true.
- Another said an LLM kept resurfacing a ruled-out cause in a hardware failure investigation.
- A decision log in CLAUDE.md works for some
- A commenter has the agent log every decision with time and context, and says it works well.
- They noted the real issue is that invalidation doesn't propagate.
- Pushback and alternatives from classic AI
- One commenter said is_a facts lead toward Cyc once you need quantifiers.
- Another suggested Answer Set Programming, a non-monotonic logic that unlearns facts.
- Suggestion to tie provenance to source versions
- A commenter proposed attaching file paths and content hashes so only affected statements get re-evaluated when a file changes.
How to Apply
- Add a retraction list to your agent notes
- Today, add 'rejected assumptions' and 'conclusions depending on them' sections to CLAUDE.md or your notes.
- Instruct the agent to remove or mark invalid any dependent conclusion when an assumption is overturned.
- Split memory into retrieval and current state
- Keep your vector memory and add a separate store holding only currently-true facts.
- Have answers prefer the current state and use retrieval as support.
- Require evidence IDs on every conclusion
- Make supporting observation IDs a mandatory field when the agent writes a conclusion.
- Add a validation step that rejects unsupported conclusions.
- Check whether your grounding instruction causes refusals
- If you added anti-hallucination prompts, measure refusal rate on answerable questions.
- Write: refuse if the premise is absent, but reason if evidence exists and needs counting, comparing or ordering.
Try It
# Paste at the start of a Claude or ChatGPT chat (simplified version of the post's method: mimics Datalog via prompt)
You are a research assistant. Maintain a 'maintained state' in this format throughout the conversation.
- FACTS: numbered observations (F1, F2...). Each marked valid/retracted
- CONCLUSIONS: numbered (C1...). Each must list its supporting FACT numbers
- Rule: when a FACT is retracted, immediately mark invalid every CONCLUSION that depends only on it. Keep conclusions that still have other valid support.
- Never write a conclusion without supporting fact numbers.
- End every reply with the updated state.
Topic: {{research topic}}
I'll now give observations; update the state. First observation: {{observation 1}}
Next to try: later say '{{observation 1}} was wrong' and ask which conclusions became invalid and why.Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques
Related Resources
- https://pwning.systems/posts/llm-memory-program-analysis/
- https://en.wikipedia.org/wiki/Cyc
- https://en.wikipedia.org/wiki/Answer_set_programming
- https://github.com/deepclause/deepclause-sdk
- https://github.com/deepclause/deepclause-pi
- https://github.com/cookiengineer/exocomp
- https://github.com/cookiengineer/gobayashi
- https://github.com/cookiengineer/gonano
- https://mirekrusin.com/cave