DEV Community

Cover image for How we made AI agents actually use their lessons
Serhii Zhabskyi
Serhii Zhabskyi

Posted on

How we made AI agents actually use their lessons

Two weeks ago I argued that AI coding agents keep repeating the same project-specific mistakes because they have no memory, and that the fix isn't a bigger prompt — it's a graph of "lessons," small rules linked to the files, commands, and contracts they apply to. AgentsMesh builds that graph and feeds it back to the agent.

The post did fine. The comments did better. A few readers walked straight past the pitch and put a finger on the parts I'd hand-waved. This is a follow-up on that discussion — the three problems they raised, and what actually shipped since.

"You can store the lesson beautifully and still never read it"

That's Nazar Boyko in the comments, and it's the whole game. Marco Somma said the same thing from another angle — the hard part isn't the store, it's the trigger. Does the agent query its memory before it makes the mistake, or does it store the lesson and blow right past it next time?

My honest answer back then was: it's supposed to. Recall was instruction-gated — a rule told the agent to check its lessons before editing, then trusted it to actually do it. The first touch of a file, the exact moment you want the warning, rode on the model remembering to ask. Models don't.

So recall stopped being an instruction and became a hook. On every target that supports them, it now fires on both events — a PreToolUse hook injects the matching lessons before the edit runs, so the very first touch is guarded, and a PostToolUse hook covers the rest. The relevant lessons show up on their own now, deterministically. Nobody has to remember to ask.

"Approval answers may this enter memory. It doesn't answer will this protect us"

Mike Czerwinski drew a line I hadn't: there are two separate gates. One decides whether a lesson is allowed into memory — the approve/deprecate lifecycle, which I had. The other asks whether the right lesson fires when the mistake recurs, and stays quiet when it shouldn't. He floated a "planted-fault harness" to test it. I built it.

It runs the real recall ranker against fixture graphs where every lesson is labeled up front: this one should fire on this edit, that one must stay silent. It scores both directions — catch rate and false-positive rate — because a memory that fires on everything is as useless as one that fires on nothing.

Then the part that made it mean something: I mutation-tested the harness. Broke the ranker seven different ways — zeroed a scoring weight, reversed a tie-break, ripped out the status filter — and checked the gate went red each time. Seven for seven. A green test that doesn't turn red when you sabotage the thing it's testing is just decoration.

"A stale lesson is worse than no lesson"

Lolo and others mentioned staleness. My gut said a big chunk of my own 358 lessons were probably dead — pointing at files that moved, commands that changed. So instead of guessing, I built a reachability audit to count it.

I was wrong. Zero inert lessons. 76% point at a file that still exists in the tree; the rest are valid command patterns. The auto-pruning I'd already shipped was quietly doing its job. (I watched it happen mid-session: a lesson I'd just captured had its file glob auto-pruned when the file wasn't where it claimed. Felt like catching the disease — then the audit showed it's the immune system, and it's rare.) That's the whole argument for measuring. My instinct was confidently wrong in both directions in the same week.

The one I'm still working on

Here's the honest part. Reachable, discriminating, injected-before-the-edit — all verified now. What happens after the lesson lands is softer. I've watched an agent pull a queried lesson into its reasoning mid-task — you can see it weigh the rule in its thinking before it acts, which is exactly the point. But I can't promise every agent takes every lesson into account every time. Sometimes the warning shows up and changes nothing, and I don't yet have a reliable read on how often. That's the field for work.

That's the frontier, and the newest work has started chipping at it: an opt-in outcome log that tracks whether a delivered lesson actually prevented the repeat, then down-ranks the ones that don't earn their keep — plus a scope: always for the handful of rules that apply everywhere. Early days. But it's the right question, and it's the one the comments pointed me at.

If you left one of those comments: thank you — genuinely. The discussion did more to shape where this went than the upvotes did. AgentsMesh is open source. And if you think "memory that fires before the edit" is the wrong bet, tell me why below. That's apparently where the good stuff is.

Top comments (0)