Memory and State Management

Memory and State Management

Procedural Memory — Patterns

Procedural memory › Patterns

27 of 69 in this book · 3 min read

Promote on evidence, demote on evidence

Problem. A routine stored after one success is a guess with authority. Because retrieval does not distinguish a guess from a reliable procedure, the agent applies both with equal confidence, and the store's quality drifts in whichever direction chance pushes it.

Approach. Keep an attempt ledger per routine — uses, successes, failures, and the context each occurred in — and make both promotion and withdrawal functions of it. A routine enters a trial state where it is suggested but its outcome is always recorded, becomes trusted after a stated number of independent successes, and returns to trial or is withdrawn when failures cluster. Retrieval filters by state, so trial routines never run unsupervised.

Trade-off. The ledger requires reliable outcome attribution, which is the hardest part: tasks succeed for reasons unrelated to the routine, and partial successes defy classification. Statistical thresholds also need enough traffic per routine to mean anything, and the long tail of rarely-used routines never accumulates enough evidence to leave trial.

Capture the shape, not the instance

Problem. A routine captured verbatim from a successful run contains that run's record identifiers, timestamps, tokens, and tenant-specific values. Replayed, it either fails confusingly or acts on the wrong object.

Approach. Generalise at capture time: identify the values that came from the task and lift them into named parameters, leaving the sequence, the order, and the constant arguments behind. Store the original run alongside as the worked example, so a human can see what the generalisation was made from. Refuse to store a routine whose generalisation still contains values that match known identifier or secret patterns.

Trade-off. Automatic generalisation gets the boundary wrong in both directions — lifting a constant that was actually essential, or leaving in a value that was incidental — and the error is invisible until a replay misbehaves. Parameterisation also assumes the next task has the same shape, which is exactly the assumption that fails when the environment has moved.

Bind a routine to the environment it was learned in

Problem. Know-how is true of a deployment, not of a task. A sequence learned against one tenant's configuration, one API version, or a staging instance is retrieved for a similarly-worded task elsewhere and applied where its assumptions do not hold.

Approach. Record the environment fingerprint with the routine — target service version, tenant, region, tool schema hash — and make retrieval require a match rather than treat it as a ranking signal. When a fingerprint component changes, every routine bound to the old value drops to trial automatically rather than remaining trusted, so an upgrade invalidates learned workarounds by construction instead of by someone remembering to.

Trade-off. Strict matching fragments the store: the same lesson is relearned per tenant and per version, which wastes most of the value of having learned it. Fingerprints also need a source, and tool schema hashes change for cosmetic reasons, producing invalidation storms that train people to loosen the matching until it stops protecting anything.

Negative routines are first-class

Problem. Knowing what not to do is at least as valuable as knowing what to do, and nothing records it. The agent rediscovers the same dead end repeatedly because only successful paths are written.

Approach. Store failed approaches as explicit items with the condition under which they failed and the observed symptom, retrieved into the same context as the positive routines and labelled as such. The agent is then choosing among known-good and known-bad approaches rather than among known-good and unknown, and the record of a dead end survives the person who hit it.

Trade-off. Negative items are far more context-dependent than positive ones — an approach that failed because of a transient outage is recorded as if it were structurally wrong — so they need the same evidence thresholds and age out faster. They also add bulk to every retrieval, and the model may over-weight a prohibition into refusing an approach that would now work.