Rituals that close out the day, week, month and quarter in an agent's memory
Rituals that close out the day, week, month and quarter in an agent's memory
An agent without memory starts from zero every time: working out again what the project is, which decisions have already been made, and what we tripped over last Tuesday. A personal knowledge base grows faster than you can structure it, and without a ritual to close out each period it stays a raw log instead of memory you can use.
The storage is deliberately plain: markdown, JSONL and git, with no vector databases and no external services. The difficulty is not in storing things — it is in the discipline of writing and in keeping reads cheap.
The rituals
Five skills close out periods. Closing the day merges shards from parallel sessions into a single day file and finds unclosed days by searching transcripts. Closing the week rotates bloated project cards and retunes the other skills based on accumulated data. Closing the month cleans up the facts log and reviews decision records; closing the quarter compresses three monthly reports into one or two pages. Separately there is an interrogation protocol: the agent asks one question at a time and tags each of its own answers with a confidence level, so a guess cannot pass itself off as a fact.
The engineering underneath
Three hook scripts, 693 lines, 137 tests. The interesting part starts once there is more than one session.
An identifier race. Two parallel sessions generated the same record number, and editing a line rewrote the whole file. The fix is not a lock but recomputation: the number is worked out at write time, and the log itself became append-only — the only way in is through a wrapper script.
Sessions overwriting each other. While checkpoints were written into a shared day file, a neighbouring session could overwrite someone else’s section. I split them into shards: one file per session, merged when the day is closed.
The model has no clock. Checkpoint freshness was read from an “updated” field the agent filled in itself — and it invented a time fifty-two minutes into the future. It now uses the file’s modification time.
Silent data rot. An audit found 41 records (8% of the facts) invisible to search: they lived in older schemas the current parser did not know about. And 220 of 370 files in the topic index turned out to be invalid UTF-8 — BSD awk slices strings by bytes rather than characters, and Cyrillic fell apart. None of it crashed anything, which is exactly why nobody noticed.
Along the way the cost of the startup context dropped from 21,700 to 12,000 tokens per run, and test coverage grew from 30 to 135.