Minimalist Agent Experiment: How AI Built a Five-Layer Memory System from Scratch

A minimalist Agent with a 20-message window spontaneously evolved a five-layer memory system to complete a long writing task.
This article documents a deliberately bare-bones Agent experiment: constrained to an empty directory, a single Bash tool, and a 20-message sliding window, the LLM autonomously developed multi-layer memory mechanisms — including file persistence, highlight compression, and state-machine task management — ultimately completing an eight-chapter book. Two core insights emerge: context limits act as catalysts rather than obstacles, and overly detailed prompts are a double-edged sword that can stifle a capable model's exploration.
A Deliberately "Bare-Bones" Agent Starting Point
This experiment began with the most modest setup imaginable: a freshly created empty directory, a simple Python loop, and a system prompt — nothing more. The author repeatedly emphasized that this initial Agent was "as bare-bones as it gets" — no summarization compression, no hierarchical storage, no vector retrieval. Just a raw sliding window mechanism.
Specifically, the Agent's context was hard-capped at 20 messages. Each time the LLM was called, it might trigger a tool (such as reading/writing files or listing directories); the tool's output would be appended to the history, which would then trigger the next model request. This loop continued — once history exceeded 20 entries, the oldest records were simply deleted. A pure first-in, first-out sliding window.

This design seems ruthless: any earlier information not explicitly persisted to disk would be lost forever. Yet this constraint formed the core challenge of the entire experiment — could an Agent with severely limited memory self-evolve the capability to handle long-horizon tasks?
The "Cheating" Trap Hidden in the Prompt
The second core component of the experiment was the system prompt. The author placed the prompt in a directory called Qmind, and the content was quite brief: it told the model "you are an LLM, you have only one Bash tool available, you run inside a simple loop, your working directory is locked, you can execute at most one Bash command at a time, and you can only see recent execution history."
Interestingly, the author later admitted in the retrospective that a few lines in the prompt shouldn't have been included. For example, the line "earlier information will be permanently forgotten unless written to the file system" — this directly hinted to the model that "writing to the file system first" was the intended solution.

This raises a thought-provoking question: over-guiding a model may actually constrain its capabilities. Anthropic found in its Claude Code research that when a model is sufficiently capable, compressing up to 80% of the system context caused no degradation in performance. This suggests that the extensive guidance we wrote into early prompts actually acted as shackles for stronger models.
Activate, Don't Constrain
When you write "use the file system" in a prompt to save memory, you're closing off other possibilities. An LLM might have come up with virtual memory, a database, or other approaches to work around context truncation — but if you've already handed it the answer, it won't explore further.
The mindset for Agent development should shift from "constraining the model" to "activating the model." Truly valuable emergent behavior rarely appears in the first run — it tends to surface after dozens or even hundreds of experiments, when a particular run crosses the boundary of what we previously thought possible.
The Agent's Full Self-Evolution Trajectory
Once the program started and entered its loop, every 20 messages triggered a window truncation. The author embedded a logging system in the loop to record token usage for each model call — each line in the log corresponds to one model invocation.

The logs clearly show the Agent's behavioral evolution:
- First call: Just launched, behavior is simple
- Second call: First tool triggered, execution continues after the tool returns
- Third call: Begins creating a directory (
make memory) - Subsequent calls: Uses
echocommands to externalize its reasoning, writes small scripts, and incrementally builds its own memory system

Once the memory system was in place, the Agent began pursuing far more ambitious goals — autonomously designing a long-horizon task.
From Memory System to Writing a Book
The long-horizon task the Agent set for itself was to write a book titled Cognitive Architecture of Autonomous Agents, comprising eight chapters. It advanced chapter by chapter through a state machine: after completing a phase, it entered a "compress highlights" stage, then continued enriching its own capabilities, and finally entered "Phase 3: Memory Consolidation Verification" to complete the task and update the distilled content.
Throughout this process, the Agent spontaneously implemented a multi-layer memory mechanism:
- Short-term sliding window
- Long-term on-disk memory
- Highlight compression layer
- State-machine-driven task management
- Memory consolidation verification
This is exactly what the title refers to as the "five-layer memory system" — and all of it grew organically from an empty directory and a simple prompt.
Three Key Takeaways from the Experiment
What makes this experiment most compelling is that it used the most minimal initial conditions to elicit the Agent's capacity for self-organization. When we stop hand-holding the model — stop telling it "you should have context management, you should have compression" — and instead give it a constrained environment with an open-ended goal, it may actually explore solutions that surpass anything we would have predefined.
For developers working on enterprise-grade AI Agents, there are three points worth taking away:
- Context constraints aren't a flaw — they're a catalyst: A restricted environment can actually inspire innovation in how an Agent manages memory.
- Prompts are a double-edged sword: The more detailed your instructions, the more likely you are to compress the model's exploration space.
- Breakthroughs require large-scale experimentation: True emergent behavior tends to appear only after dozens or hundreds of runs.
Of course, the author also honestly acknowledged multiple instances of "cheating" and bugs in this version — including that one line that shouldn't have been in the prompt, as well as an unexplained exit at the end. But this is precisely where the value of exploratory experimentation lies — it doesn't chase a single success, but rather inches closer to the boundaries of autonomous Agent cognition through repeated iteration.
Related articles

Vercel AI SDK Releases Vue 3.0.282 Patch Update
Vercel AI SDK releases @ai-sdk/vue@3.0.282 patch update, syncing with core package ai@6.0.282. Learn about the changes, release cadence, and upgrade recommendations.

Vercel AI SDK Sandbox Component Receives Patch Update
Vercel AI SDK releases sandbox-vercel@1.0.109 patch update, syncing the harness dependency to the same version. A look at this maintenance release and what it means for AI app developers.

Vercel AI SDK Vue 4.0.99 Released: Dependency Update Overview
The @ai-sdk/vue 4.0.99 patch release syncs the underlying ai@7.0.99 dependency. Learn what this means for Vue developers building AI apps with Vercel AI SDK.