Skip to content
mentoor

Topic 4 of 5 · 5 min read

Testing whether a memory file changes agent behaviour

Goal: Design a small with-and-without test for a memory-file rule and decide from the transcripts whether the rule works, is ignored or should become a hook.

A memory-file rule is a hypothesis about agent behaviour, so test it: run the same task with and without the rule, read the transcripts and keep only what measurably changes the result.

Check yourself · 1 of 3

What is the cleanest way to test whether a memory-file rule matters?

Choose one answer

Why it matters

Writing a rule feels like fixing the problem. It is not. The agent may never load the file, may read the rule and still ignore it, or may follow it only when the task is short. Models drop instructions, especially in long sessions. Without a test you carry rules that do nothing and believe you are protected.

A small with-and-without test

  1. Pick one rule and its failure. Example: "Use AppError, never plain Error". The failure is visible in a diff: a throw new Error(.
  2. Write 3 to 5 tasks that tempt the failure. "Add validation to the signup handler" is a good one, because the lazy path is a plain Error.
  3. Run each task twice from a clean state: once with the rule removed, once with it present. Use a fresh session each time, and the same model and settings.
  4. Check the result mechanically. A grep for the forbidden pattern is better than your impression.
  5. Read at least one transcript. Did the agent open the memory file? Did it mention the rule? Did it violate it knowingly?
  6. Repeat a few times. One run proves little, because outputs vary.

A simple scoring script:

# count violations in the agent's diff
git diff main -- src | grep -c '^+.*throw new Error('

Reading the result

  • Rule off: violates. Rule on: follows. The rule works. Keep it.
  • Both violate. The rule is ignored. Check that the file loaded; then reword (be specific, give the alternative), move it higher, or shorten the file around it.
  • Both follow. The rule is unnecessary. Delete it.
  • Follows in short tasks, fails in long sessions. The rule decays as the context grows. Reconsider.

If a rule must hold every time, such as "never touch .env" or "run the formatter", prose is the wrong tool. Turn it into a hook (a script the agent harness runs automatically), a permission setting or a CI check. These enforce; memory only asks.

Before and after

Before: "Try to avoid plain errors." Result in 5 runs: 3 violations with the rule present. After: "Throw AppError(code, message) from src/errors.ts. Plain Error fails CI." Result: 0 of 5. The rule became specific, named the alternative and had a consequence.

What goes wrong

  • Testing once and trusting luck.
  • Judging by feel instead of a diff check.
  • Reusing a session that already saw the rule, which contaminates the "without" run.
  • Never checking that the file loaded, so the test measures nothing.

Examples

A five-run test table

Rule Runs Violations without Violations with
Use AppError 5 4 0
Keep functions small 5 2 2
Run pnpm lint --fix 5 3 1

The first rule works. The second changes nothing, so drop it. The third helps but leaks: make it a hook.

Promoting a rule to a hook

The rule "never edit .env" was broken once in ten runs, and one leaked file is too many. Replace the sentence with a pre-edit hook or a deny permission for that path. The agent can no longer do it, whether or not it remembers the file.

Key points

  • Treat each rule as a hypothesis and test it with the same tasks run with and without the rule.
  • Use fresh sessions and a mechanical check such as grep on the diff, not an impression.
  • Read a transcript to see whether the agent opened the file and acknowledged the rule.
  • A rule violated in both runs is ignored; a rule followed in both runs is unnecessary.
  • Rules that must always hold should become hooks, permissions or CI checks, not prose.

Common mistakes

  • Concluding a rule works from one successful run.
  • Running the 'without' and 'with' tasks in the same session, so the rule leaks into both.
  • Skipping the check that the file was actually loaded.
  • Keeping a critical rule in prose when a hook or permission would enforce it.

Check yourself · 2 of 3

In five runs the agent violates a rule both with and without it in the file. What is the most useful next step?

Choose one answer

Check yourself · 3 of 3

Which rule is the strongest candidate to become a hook instead of a sentence?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic