Memory: what an agent keeps
You will learn
What an agent still sees of a long chat, what falls out of its window, and what a file in the project keeps.
An agent does not remember your project; it sees the last messages of the chat, as many as fit in its window. The spec uses a window of 6 and a chat of 10, small enough to trace by hand. The agent keeps 6 messages and forgets 4: messages 0 to 3 have fallen out, and the oldest one it still sees is number 4. What you write into a file of the project stays, because the agent can read the file again in a new chat. That is why a rule you want kept goes into a file, not into one more message. Plant the bug by setting WINDOW to 7 and two tests turn red, because the window no longer ends where the chat does.
Try it
Open the widget and find how many messages a chat of 10 forgets in a window of 6; then run the spec, set WINDOW to 7, and read which two tests fail. Put the line back and run it again.
A chat of 10 messages in a window of 6: which messages the agent still sees, which it has lost, and what a file in the project keeps. Lesson 21 of the Vibecoding from zero course.
specs/vibecoding/agent_memory.t27
// SPDX-License-Identifier: Apache-2.0
; specs/vibecoding/agent_memory.t27 -- vibecoding lesson 21: what an agent keeps between messages.
; An agent sees only the last messages of a chat, as many as fit in its window. When the chat grows
; past the window the oldest messages fall out and the agent no longer sees them. What you write
; into a file of the project stays; the chat does not. The numbers here are small so the lesson
; can be traced by hand: a window of 6 messages and a chat of 10.
; Run the tests, then plant the bug named at the bottom and watch one test turn red.
module vibecoding_agent_memory;
pub const WINDOW : u8 = 6;
pub const CHAT : u8 = 10;
; What the agent still sees, and what it has lost.
pub const KEPT : u8 = 6;
pub const FORGOTTEN : u8 = 4;
; Messages are numbered from 0, oldest first. This is the oldest one still seen.
pub const OLDEST_SEEN : u8 = 4;
pub const FIRST : u8 = 0;
test the_agent_keeps_a_window_of_the_chat {
assert KEPT == WINDOW;
assert CHAT > WINDOW;
}
test what_is_not_kept_is_forgotten {
assert CHAT - KEPT == FORGOTTEN;
}
; The negative control. The window is the last WINDOW messages, so counting back from the end of
; the chat gives the oldest one still seen. Plant the bug by setting WINDOW to 7: this test turns red.
test the_window_ends_at_the_oldest_seen_message {
assert OLDEST_SEEN + WINDOW == CHAT;
}
test the_first_message_has_fallen_out {
assert FIRST < OLDEST_SEEN;
}
All lessons
Module 1 · What vibecoding is
You describe, an agent writes, you run it and check. What a program is, and five myths put to a test.
Module 2 · Your desk
An editor with an agent beside it, ten terminal commands, and reading an error message.
Module 3 · Save points with git
A commit is a save point, a branch is a safe try, and a key is a pair of which one stays private.
Module 4 · Prompting
The parts of a prompt, an example in place of an adjective, and one small step at a time.
Module 5 · The working loop
Four phases from idea to ship, the loop of ask, run, read and fix, and what to do when it is stuck.
Module 6 · A test as the judge
A test says yes or no, a planted bug shows the test works, and a diff is read before it is accepted.
Module 7 · The parts of an agent
What an agent answers with, what it can do with tools, and what it keeps between messages.
Module 8 · A first bot
A bot is a message loop, a bot comes from a spec, and a secret stays out of the repository and the prompt.
Module 9 · Your own project
A spec for your own idea, one thing measured after it runs, and an honest plan for the next month.