← all systems
AGENT INFRAAI AGENTEVALS

Learning-Loop — Self-Improving Agent Memory

Agents that log lessons, retrieve them at the right moment, and measure whether the memory actually changed behavior.

Python · Claude Code Hooks · 144-test suite · Weekly cron · IDF-ranked retrieval

The Problem

Most "agent memory" counts retrievals and calls it learning. Retrieving a lesson is not the same as using it. I built Learning-Loop to close that gap: a drop-on engine for any Claude Code project or managed agent that injects memory at startup, retrieves at targeted stage checkpoints with IDF ranking, and — the part that matters — records confirmed-use telemetry: did the retrieved memory change what the agent did? Lessons that get retrieved forever without a confirmed use decay out. Lessons that prove out graduate from an episodic log into a pattern library, into the project contract, and finally into enforcement code that cannot be skipped.

Stack

🐍
Python
22 domain-neutral scripts; idempotent install.py; cross-project host registry
🪝
Claude Code Hooks
PostToolUse marks the session; Stop blocks until closeout runs
🧪
144-test suite
Run by the weekly audit gate
⏰
Weekly cron
Transcript mining + curation; risky changes staged for human review
🔍
IDF-ranked retrieval
Targeted stage checkpoints, not a firehose at startup

How It Works

The execution path

ready7 steps
Inject at startup
Session start01
Inject memory at startup
Project contract and top patterns
Retrieve at checkpoint
IDF ranking02
Retrieve relevant lessons
Targeted stage checkpoints, not a firehose at startup
Confirm use
PostToolUse hook03
Mark the session on first edit
Stop hook04
Block Stop until closeout runs
Needs a learning decision and a use decision
both decisionsStop stays blocked
both decisions
Stop stays blocked
Use telemetry05
Did the memory change what the agent did?
confirmed usenever used: decays
confirmed use
never used: decays
Graduate or decay
Weekly cron06
Mine transcripts for unlogged lessons
Risky changes staged for one human review file
Learning-Loop07
Graduate proven lessons
Episodic log to pattern library to CLAUDE.md contract to enforcement code
TriggerStepGateOutput
A closeout gate that actually gates. A PostToolUse hook marks the session on first edit; a Stop hook blocks until closeout runs; closeout requires both a learning decision and a use decision. A weekly cron mines transcripts for lessons nobody logged and stages anything risky for one human review file. A fresh install starts bare on purpose — the loop's own instrumentation should tell you what its categories should be. Memory that adopts its own structure unreviewed is how loops poison themselves.

Key Design Decisions

📏
Measure Use, Not Retrieval
Confirmed-use telemetry records whether a retrieved memory changed the agent's action. Counting retrievals is vanity.
🚪
A Gate That Gates
Stop is blocked until closeout runs, and closeout requires decisions, not acknowledgements. No session ends unrecorded.
🎓
Lessons Graduate
Proven lessons move from log to pattern to contract to code that cannot be skipped. Unused ones decay.
🌱
Start Bare on Purpose
A fresh install has no categories. The loop's own data decides them, and a human reviews before anything sticks.

By The Numbers

22
Domain-neutral scripts
144
Tests in the audit gate
1
Human review file per week
0
Sessions that end without closeout
← back to all systemsmatthew batterson · gtm engineer