I accidentally turned LLM memory into program analysis
pwning.systems
pwning.systems
1. User request understanding: natural language -> a more rigorous representation, in my case Datalog.
2. Result interpretation: facts and derived facts -> natural language.
Between those terminals, the work should be mechanical reasoning over some ontology or formal knowledge structure.
That connects to another principle I've been thinking about, which I call Weathering: useful reasoning should change the shape of the system. If an LLM has already had to infer a relation, mapping, rule, or abstraction, repeated use should wear that inference into the system so that the next similar request doesn't require discovering it again from scratch.
With continued use, a weathering-capable system should therefore require less and less probabilistic intelligence for recurring work. Put another way, there should be a declining marginal cost of cognition since the products of intelligence harden into structure that can subsequently be reused and evaluated mechanically.
“He weathered the storm” vs “the stone weathered into an arch”.
You can endure as long as you want to, but we're all going to erode eventually.
[1] https://aclanthology.org/2026.eacl-long.333/ [2] https://openreview.net/pdf?id=eC4ygDs02R
My problem is the context of today’s models (that I’ve been using - Claude Opus 5 and GPT-Sol) are a black box to a user like me. I cannot tell what they already hold in their context over the duration of a coding session. I cannot tell influencers a little by using/not using MCP tools, AGENTS.md like MD files, but what they _actually_ use at inference time is still opaque.
For example, if I insist that GPT-Sol use a size bounded dynamic cheat sheet for my project, and even have those reflector&curator agents refine them concurrently, what is to say GPT-Sol doesn’t have an intrinsic cheat sheet like that already, and it is just reading/curating/managing this one in addition and only getting confused needlessly along the way?
Similarly, all those codegraph like tools and semantic search addons.. what is to say the model genuinely uses them instead of relying on its own inference techniques and just “perform” for the user audience as if they are using these fancy tools?
This is not to say we shouldn’t try more ways of managing context and just give up to our AI provider overlords. Just thinking through the logic of what we are working with.
Would it even help if it weren’t a blackbox? Maybe to the frontier labs with resources, but even trying to read through the thinking traces of an open model doing a nontrivial task easily takes me an entire day to do correctly (i.e. actually looking at the code it read in) and much more if I’m trying to tune a specific repeatable task.
Applying that to agentic coding seems like a losing proposition. The only way to manage it seems to be more agents and that’s its own rabbit hole of compounding errors (like Claude’s useless comments).
The weathering need is real. An llm equivalent of dbms analysing usage pattern to tune indexes.
And I guess for 2, stay out as long as possible.
I guess this is somewhat different; it admits that in some cases you do need the LLM doing more work somewhere in the middle.
But it also means sometimes you never enter the LLM to begin with, or never re-enter it for output.
Soon, he'll discover that he needs quantifiers. Then that "for all" is too strong sometimes, and he needs "for most". That way lies Cyc.
It's not a bad idea. But it does have a history.
In fact, both Cyc and the "AI" Labs have the _same basic thesis_: Intelligence is, primarily, a data entry problem. They just disagree about what kinds of heuristics should be run over that data (logic-programs, neural-nets).
Whenever I read about someone using LLMs to write code, it _very closely_ resembles how Lenat was using Eurisko/Cyc to solve problems: they let the system run continuously, and they "nudge" it in "interesting" directions, "when it gets stuck", or "runs out of steam". (Quotes indicate their phrasing, not mine)
Even Lee Spector noticed something analogous with his genetic programming system. When he tried to get it to discover optimal data structures (or maybe it was sorting algorithms, I forget), the system would quickly "run out of steam", without a solution. But when they added new verbs/opcodes to the system, that were a better fit for that domain (e.g. index-based memory loads + stores), it converged on a solution very quickly (even for GP, domain specific languages keep delivering unreasonable wins). You will note that this rhymes with the "micro-theories" of Cyc, which in turn rhyme with the SLMs of the AI labs.
In my personal experience, most of the "silver bullets" do not work (obviously), but some of them do nudge you towards being a better programmer (by refining your intuition about the problem specifically, and computers more generally).
EDIT: just remembered something. LLMs tend to produce larger and larger programs over time, and most people (IIRC) interpret this as a kind of entropy. This happens to rhyme with a similarly observed behavior in GP. Most genetic programs that do not have a fitness function that rewards smaller size, tend to grow in an unbounded way. The reason for this, is that most of the code/genes are useless, and random mutations do not lobotomize the program under evolution. I suspect that the coding LLMs tend to grow their code for similar reasons.
[0]: I suspect that, this was mostly a triumph of enormous amounts of hardware, more than the actual LLM technology. I further suspect that a traditional GP approach, on the same quantity of hardware, could have gotten there faster (if not better as well).
[0]: Because, in effect, we are decreasing the size of the search-space. Every programming-language project is basically a set of bets, that the design choices will decrease the size of the search space for the users of that language (most Unix commands fit this pattern, as do most well designed APIs). Mathematics is similar, in that the notation is specialized and sparse (even the named constants and variables have symbolic names, instead of meaningful names). Most system dynamics models could have the names of entities replaced with id-numbers, and they would continue to function. The whole point of (for example) a library is to give a tiny parameterized notation/language, that the user can use to express a solution to their problem, in terms of the problem domain itself. This decreasing of the search-space, is an act of compression. I have to say, I am a little confused by your reply, because it has the tone of a disagreement, but it does not really disagree with anything that I have written. Also, I have given various examples to support my analogies, but you have offered zero examples, and I suspect that there would be less confusion (on my part) if you did.
Think of it like human imagination may do anything (flying cars), but the real world has constraints and we use language/writing (symbols) and rules bound to them to simulate and reconcile our imagination with reality to actually flow our energy into something that may work in the real world.
Is my reading comprehension just completely broken or something? The above certainly sounds like "the powers that be want us to believe that attention is all you need".
(See also Cyc: https://en.wikipedia.org/wiki/Cyc)
I think approaches like this are going to be (or maybe already are?) the basis of effective grounding of LLM responses in authoritative data sources. It should be possible to pinpoint any error to an incorrect traversal or an incorrect "fact." This would work best for concrete, unambiguous facts, however; fuzzy, ambiguous or opinion-based information will probably remain the purview of LLMs.
It’s very hard to remove information - Claude has a habit of recording things all over the place and will happily treat things as facts even after they’ve been disproved.
What is currently true can get easily contaminated with old “facts”.
The mnemonic I use for that is "do not think of a polar bear".
I settled on a knowledge graph in Postgres and downloading/storing the source documents so it could iterate on past results without more scraping or network calls.
This blog post helped me understand security analysis in this context! A lot of the important systems around malware analysis or large scale system security (the parts people really care about) clicked for me. So thanks for writing it.
Anyways I hope we can find some pattern to converge on with this wrt "facts management" since I feel this is currently something a lot of people and LLMs are struggling with. In practice current LLMs working with episodic memory feels similar to a grandparent with dementia scrawling things down in notebooks, crossing things out, and getting very confused.
I settled on simplicity, extended it to serve clear, useful purpose.
Started with markdown database, single fact per line, structured/parseable (subject VERB object). This can be easily diffed/reviewed etc in git. Then added optional metadata (confidence, tags, persisted comments for natural language, uncertainty for numeric values, context, timestamps/spans), querying, alternative sqlite3 backend, self describing VERBS, z3 solver etc.
Those kind of graph information systems are great to quickly structure knowledge in a way that LLMs and humans can use/act on/loop on. Creating ontology, linking, some rules and actions and kicking it so it all munches and spits out results that feed back in so it self evolves. It's very natural for llms to query/update/restructure those graphs (also good for humans because it's very terse, essential information only).
There is no need to create k8s style complexity/services/what-not, it all works well from single sqlite db file or bunch of markdown (.cave in my case) files.
It's also interesting to see how well local open weight models are dealing with information arranged this way.
I ran into the very same problem of the LLM forgetting that we ruled out a conclusion that was verified not to be the cause as it came up further in the conversation history while I was exploring possibilities.
I had to keep reminding we ruled out that conclusion prior.. I just carried on with having the LLM capture some of the supporting sources of other people experiencing the same problem and kept having to refine those sources because it was focused only on summaries, but eventually i got the sources to a point where they were good enough hypothesis that we could formulate a better conclusion on what the potential cause was.
My way of handling that is a decision log. For every project since I started doing that it’s working great. My CLAUDE.md instruct the agent to store my every decision to the file with a metadata when I made this decision and what was the context. The agent is using this file as an index of decisions and rarely lose a track. It also helps team members to find out more about the development phases.
Does your system invalidate the parts of the memory if these are not valid or relevant anymore or just store/retrieve?
Could anyone with more experience give feedback on whether this approach would be useful for business rules? Particularly for debugging a data pipeline where dozens if not hundred of different values at different points in time may have different implications.
Would it be useful to provide this tools for Business Analysts so they have something more solid for they analysis?
What I found out during malware analysis is that LLM agents have a couple of quirks that you can solve by:
- optimize for short lived agent workflows
- use symbols as function contracts
- maintain decision and discovery state
- give LLMs CLI linters
- give LLMs access to knowledge bases
The linter part is mindblowing. I built linters that validate HTML or markdown or docx or Go or C files, for example, and they output what kind of structure is expected instead of useless token based errors (e.g. h4 inside h1? Must be h1 > h2 ...).
With linters the output quality of agents is just soo much better.
For program analysis, I'm currently exploring the idea of using an external ebpf daemon that programs can be observed with via a public API (which is the tool for the agent to use). Not sure if it'll do the trick yet, but I think it has lots of potential.
My stuff in case you're interested:
[1] https://github.com/cookiengineer/exocomp
Opposed to OP, DeepClause uses Prolog semantics, so running some more complex queries on knowledgebases might cause some issues (which is the use case where a Datalog might be more useful). For smaller scales it should be fine though.
[0] https://github.com/deepclause/deepclause-sdk [1] https://github.com/deepclause/deepclause-pi
btw. your comment is grayed out, not sure what it means. However, thanks for sharing, I'll look into it.
The LLMs are great at:
- understanding the flow
- making diagrams
- running the code with logging they add to to even better understand the flow
The flow being in Dot (or other machine readable format) makes it even easier for the LLM to use that as a reference going forward.
This is how I used to do it before LLMs too, it's just way faster now
E.g. A -> B, B -> C so A -> C (works, great). A -> B when A is sort of red and blue, also A is intermittent (what to do now?)
Formalisms should be in service to higher-level intelligences, not the other way around. It's pretty clear that LLM's are intelligent inherently; the lean doesn't just "prove math itself". (Admittedly, I'm not full blown AGI pilled either - there are some structural constraints that do make me think there is room to be gained in intelligence. And formalism will play a part in that. But it's not the end-all be-all to it).
The article touches on Datalog statements changing over time. One ingredient I think would be good to add to the system is to make every statement carry "providence" metadata. The providence should be sufficient to enable later confirmation that a statement is still valid or if the statement needs to be reformed without the need to remake the entire graph from scratch.
I would make at least some forms of providence follow a strict schema that is defined for the subject matter that is being captured. For example, statements about a code base should refer to the source files and their version (file modification date, content hash) from which the statements were concluded. When a source file is modified we may then find all statements made from them and reevaluate just those statements.
The next level would be to keep statements even if reevaluation breaks them and add a method to derive a subgraph for a given state of the subject. For example, over many releases of a code base, a lot of statements would not change, some would. Having a graph that spans all conclusions about all releases of a code base and a way to form the subgraph for a specific release would allow the system to efficiently target queries for a particular release.
Many people here might disagree; but they're holding it wrong. Those folks should ask:
1. Am I using free tier tokens? 2. Am I working on trivial software? 3. Am I expecting models to adapt to my ways of thinking?
Anyone affect by any of these three mistakes will maintain an impenetrable filter of perpetual ignorance about model capabilities. Since the OP came with receipts, I'm reproducing an example graph below.
From a plan in my active research project:
Phase 0 resolve -> vendor -> pin [USER+agent] -> G0 CORPUS-RESOLVED [PASS]
Track B B1 Abusalah [WRITTEN] [agent] -> G1B Q-BOUNDARY
B2 Guan-Riazanov-Yuan [WRITTEN] (KILL-BOUNDARY risk)
B3 Mahmoody-Smith-Wu [WRITTEN] + O-MSW-VERIFIER-COST closed (t = 588, MEASURED)
-> G1B PASSED: BOUNDARY-ESTABLISHED
Track A 05 Binius [WRITTEN] [agent] -> G1 AUDITS-COMPLETE [PASS] 2026-08-28
07 FRI-Binius 2024/504 [WRITTEN] — vendored by USER; calculated Q-FLOOR point obtained
06 HOBBIT [WRITTEN] — O-QUEUE-M escalated to 179 Phase 2
01 Wesolowski [WRITTEN] — hinge splits; C_overlap = 0, C_tail = 57.50% computed
02 Tight VDFs [WRITTEN] — no omega; O(log T) proof threads; black-box RO base impossible
03 LaBRADOR (light) [WRITTEN] — calculated, not measured; translation remains open
04 LatticeFold+ -- deferred to pre-141
Track C [PASS] C0a contract -> C0b exact simulator -> G0C TRANSLATION-READY
C2 Alwen-Serbinenko [TECHNIQUE-ONLY] -> C1 SoW [PASS] ANCESTRY-FOUND
-> C4 Seeded PoW [FORM-ONLY]
-> G1C [RED] WORK-LEMMA-MISSING
[WARN] ANCESTRY-CLASSICAL
-> L0 [PASS] SCOPE-FROZEN
|- E0 response [PASS] PRESENT
`- L1-L2 local [PASS] CARRIER-QUOTIENT
-> J0 [PASS] TECHNIQUE-FIT CONFIRMED
-> admission decision [PASS] CANONICAL RESULT
-> A0 [AMBER] REFERENCE-TESTED
-> A1 [PASS] ROOT-LEAF FEASIBILITY LEAD
-> semantic equivalence + epoch [USER]
C3, C5 -- deferred to pre-141
Phase 2 Q-TAIL / Q-FLOOR synthesis [agent] -> [PASS] G2: TAIL-MECHANISM-FOUND · FLOOR-OPEN
Phase 3 reference ledger for 141 [agent] -> CLOSED; awaits fresh USER authorizationthe other really handy thing here is that it very straightforward to differentiate datalog rule sets. so if you change a fact, you can run a smaller solution that tells you which consequences are affected by the change. under the assumption that the evaluator is pure, we don't need to keep the support graph as you suggest, we can just generate the deltas from evolution of the differentiated form.
detailed provenance can be of real application utility, but if you just care about the accounting, keeping track of the number of supports for each fact is sufficient.
another model which is fun is to make the version of the database (monotonic time) an explicit field in your base facts, assuming you can afford to keep the whole history. a deletion then is just a negative-support, and you can ask questions about the state of the world at any time.
I use workflows with sub agents handing off .md files: https://github.com/gregwebs/skills-sdlc/blob/main/skills/imp...
What the author is doing is probably the future- it should be a lot more efficient to maintain a database of relationships.
agent memory
|
+--------------+--------------+
| |
deductive state episodic memory
| |
facts / rules / time fuzzy context
provenance semantic retrieval
retractions source text
Well this turns out, just like human memory functions. (Semantic vs episodic memory)I’ve been battling the same problem, and I solved it by keeping the state in my brain, long focus hours, and breaking down the problem to smaller chunks that agents could almost one-shot. That made me the bottleneck, and although I can do it for codebases I’m familiar with, working on totally new projects has been very painful.
I’m going to test it in my own vuln research workflow.
Note: I wonder how many people reified their codebase as logical facts to query or investigate it more deterministically. I've been trying for a while, still not far but getting there.
I heard of Scallop, that also uses Datalog for neurosymbolic programming, I wonder where Lemmalog fits with Scallop? I know little about Datalog so sorry if this is a dumb question!
The next one is ontology and semantic web, for which the “trying to stem verbs and nouns” is a crude v0.1 attempt.
Ultimately I have stuck to the informal verification of defining my expectations and ensuring that tests cover them.
But IRL it's too vague. The exploit hunting is a better use case.
After googling for an hour, I gave up.
There seems to be this view in some circles that the LLM should do EVERYTHING. The most extreme version of this was "just commit the prompt, bro".
The more I've used LLMs, the more I think that the LLM should do either:
1. the fuzzy parts as mentioned in the post
2. helping to write deterministic tools to expand the "non-fuzzy" part
For #2, we invented code to run the same instructions the same way over and over again for very, very low cost. The code is also easy to read and modify as needed.
Why we would replace the above with a smart but stochastic system still seems strange to me.
Once again, on LLM being: a digital librarian, at its finest; logic a logic analyst, not so much.