When an AI agent repeats a mistake, the useful lesson is a change to how the next task gets done.
Correcting the output fixes the current task. Project memory should help prevent the same failure in future work.
Investigate before adding a rule
Suppose an agent changes an API response and breaks an existing client. You restore compatibility.
Before adding another instruction, investigate what failed. Was the compatibility requirement missing from the supplied context? Was it documented but overlooked? Did the checks cover only the new response?
Match the guardrail to the failure
The answer determines the guardrail:
Missing context → document the compatibility requirement where future API work will encounter it.
Unprotected behavior → add a contract test covering the existing client’s expectations.
A check that was skipped → make it part of the required verification workflow.
These changes serve different purposes. Documentation explains the constraint. A test checks a specific behavior. The workflow determines whether that check runs.
Verify and maintain the guardrail
Then verify the guardrail: does the test fail against the breaking change and pass against the compatible version?
Not every failed attempt needs a permanent rule. Keep each guardrail tied to an understood failure, and review it when the underlying requirement changes.
After deciding what to change, capture the lesson where future work can use it—and, where practical, check it.