t27.aiEnglish

Память: что агент хранит

Вы узнаете

Что агент ещё видит из длинного чата, что выпадает из его окна и что хранит файл в проекте.

Агент не помнит ваш проект; он видит последние сообщения чата, сколько их помещается в окно. Спецификация берёт окно в 6 сообщений и чат в 10, чтобы всё можно было проследить вручную. Агент хранит 6 сообщений и забывает 4: сообщения с 0 по 3 выпали, а самое старое из тех, что он ещё видит, имеет номер 4. То, что вы записали в файл проекта, остаётся, потому что в новом чате агент может прочитать файл снова. Поэтому правило, которое нужно сохранить, записывают в файл, а не в ещё одно сообщение. Внесите ошибку: поставьте WINDOW равным 7, и два теста покраснеют, потому что окно больше не заканчивается там, где чат.

Попробуйте

Откройте виджет и найдите, сколько сообщений забывает чат из 10 в окне из 6; затем запустите спецификацию, поставьте WINDOW равным 7 и прочитайте, какие два теста падают. Верните строку и запустите снова.

Открыть интерактивный урок →

Vibecoding 21: what an agent keeps ↗

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;
}

Открыть спеку урока в плеере ↗

Все уроки