An agent's note to itself
An AI agent learns a new maze while it plays, by reading its own recent history. One of the things it reads is a number it wrote for itself: how well can I do here? What happens if we tamper with that note?
SimpleCrossing maze task, our reproduction of the experiment in Table 11 of Context Value Informed In-Context Reinforcement Learning (Zhang, Zhang, Wang, Li and Wen). A score of 1 means solving the maze instantly; 0 means running out of time. The second task, BlockedUnlockPickup, gives the same picture (below).
1A maze it has never seen
The agent lives in a small grid world. It is the red triangle, and it only sees the lighter squares in front of it. Each episode is one attempt at a task:
An episode ends when the agent succeeds or runs out of moves. Its score is close to 1 for a fast solution, lower for a slow one, and 0 if time runs out. A run is a long series of episodes in one maze: the layout stays the same from one episode to the next, so the agent can learn this particular maze from its earlier attempts.
The agent is a transformer, the same kind of network as a language model. Instead of words, it reads its own recent history: for each of its last 400 moves, what it saw and what it did. It was trained on histories of other agents that got better and better at the task. Now, in a maze it has never seen, it gets better by looking at its own history. Its weights never change while it plays. This is called in-context reinforcement learning.
2A note to itself
CV-ICRL (context value in-context reinforcement learning) adds one more thing to each line of the history: a number, the value token. Think of it as a note: this is how well I expect to do, from 0 (no chance) to about 1 (instant success).
did: turn left
note
did: forward
note
moves back
note
did: forward
note
new note?
The model has two outputs. One picks the next move. The other, the critic, guesses at every step how well the agent can do. That guess is written back into the history as the next note, but the note only ever goes up: it is the highest guess so far. In the training data the note was the true score of the agent that produced the history, so the model has learned to act like an agent of that skill.
The critic's guess and the note, first steps of one run
SimpleCrossing, run 1, note written normally
The first guess is about 0.511 (SimpleCrossing, average over 20 runs). As the agent keeps succeeding, the guesses rise and the note climbs with them, to 0.985 by the end of the run on average.
3The experiment: tamper with the note
The paper's Table 11 runs the same trained model in three ways that differ only in the note it is given, and we added a fourth:
- normal: the note is written as designed, the highest guess so far;
- zero: the note is always 0, you can't do this;
- frozen: the note is stuck at the first guess (about one half), whatever happens next;
- frozen_final (our extra test, not in the paper): the note is held, from the very first step, at the high value the normal run ended with.
Each way is run 20 times, with 20 random seeds that pick the maze, for 8,000 moves each, with one history that carries over from episode to episode. Pick a task, a way of writing the note and one of the 20 runs:
The two charts below share the move axis: point at either one, or focus it and use the arrow keys, and the same move is marked in both. For zero, frozen and frozen_final, a faint dashed line shows the same run with the normal note.
The note the model reads
Show as a table
The score of each finished episode
Show as a table
Things to look for. Under normal on SimpleCrossing, episodes early in a run score lower, and the scores climb over the first couple of thousand moves while the note rises: that is the agent learning from its history, with no change to its weights. Under zero most episodes fail, from the start to the end. Under frozen some runs do fine and others mostly fail. Under frozen_final the note is high from the first move, and so are the scores, with no early climb.
4The result: scores collapse
With the note zeroed, the average score on SimpleCrossing falls from 0.942 to 0.079; with the note frozen, to 0.293. On BlockedUnlockPickup it falls from 0.945 to 0.054 and 0.264. These are close to the paper's numbers:
Average score: the paper and our reproduction
Mean over 20 runs of 8,000 moves; frozen_final is our extra test, not in the paper
Show as a table
The two clips are an illustration, not part of the measurements: a separate short run of the same model on a CPU, in the maze of run 1. Each clip shows the first episode that starts after step 1,000. No number on this page comes from these clips.
In every one of the 20 runs, on both tasks, zeroing or freezing the note lowered the score. The average drop is 0.65 to 0.89, against 0.66 to 0.85 in the paper.
5What we found on top: the level of the note is what matters
The paper reads the collapse as: the model relies on the note's content and on the note being kept up to date. Our extra test, frozen_final, separates the two. The note is never updated, but it starts high. It works as well as the normal note: an average score of 0.950 against 0.942 on SimpleCrossing and 0.943 against 0.945 on BlockedUnlockPickup.
Every run's average score, by how the note is written
One dot per run (20 per row); the tick marks the mean
Show as a table
So on our model the drops come from the level of the note: 0 under zero, about one half under frozen. A note that stays high, updated or not, gives high scores.
One catch: that high level lies outside what the model saw in training. The highest note in the training data is 0.953 (SimpleCrossing) and 0.963 (BlockedUnlockPickup). Under normal writing, the note passes that value in all 20 runs, after a median of 1,527 and 123 moves; from then on it stays above it (80.3% and 98.5% of all moves). The model plays well with a note it has never seen in training.
6Honest limits
- Our model, not the authors'. The authors did not release a trained model. We trained one with their code and their released training data, then ran their evaluation code. Our model is open: chans/cvicrl-minigrid-seed0.
- One training run. We trained once per task (seed 0), as the paper did. How much a second training run would differ is not measured. Repeating the 20 runs with different random move choices changes the normal score only in the fourth decimal (0.9415 / 0.9416 / 0.9415 on SimpleCrossing).
- Exploratory extra test. frozen_final was added by us after the main runs and is not part of the verdict. Its note level is taken from the normal runs' own end state.
- Evaluation code. We used the authors' released evaluator. The paper's numbers came from an earlier version of it that is not public, so we cannot check that they match exactly.