A Minimalist Agent Invents Five-Layer Memory: A Self-Evolution Experiment in a Loop

A minimalist Agent with 20-message context autonomously evolves five-layer memory and state machines.
This experiment uses an extremely bare-bones Agent—with only a 20-message sliding window context and a Bash tool—to observe whether it can autonomously build a complex memory system. Starting from an empty directory, the Agent progressively evolves five-layer memory, a state machine, and a write-to-disk protocol, demonstrating remarkable emergent self-organizing capabilities and revealing a design paradigm shift from constraining models to activating models.
An Extremely Minimalist Agent Experiment
In AI Agent engineering practice, the mainstream approach is to stack various complex mechanisms onto intelligent agents: context summarization, hierarchical compression, memory retrieval... But the experiment shared here takes the opposite approach—using an extremely bare-bones Agent to observe whether it can autonomously evolve a complex memory system.
The starting point of the experiment was remarkably simple: a newly created empty directory containing only two things—a simple Python loop program and a System Prompt. Everything else was produced by the Agent itself.
The Python program does something very straightforward: it connects to the DeepSeek large language model, enters an infinite loop, and appends tool execution results to the context after each model call. The critical constraint is that the context retains only 20 historical messages, using a sliding window mechanism. When new records come in, the oldest records are directly deleted and permanently lost.

What Does a 20-Message Sliding Window Context Mean?
The 20-message context means that every time the Agent invokes a tool (reading/writing files, checking directories, etc.), the execution result is added as one record to the history. This history holds a maximum of 20 entries, and older records beyond that limit are simply "pushed out" and deleted.
The sliding window is a classic data management strategy in computer science, originally widely applied in TCP network protocol flow control and text analysis in natural language processing. In the context of large model applications, a sliding window refers to maintaining a fixed-length context buffer where the oldest messages are discarded when new ones arrive. The core trade-off of this design is: although LLM context windows keep expanding—from the early 4K tokens to the 200K tokens of some current models—longer context means higher inference costs and slower response times. The extreme limit of 20 messages chosen in this experiment essentially simulates an "extremely forgetful" cognitive state, forcing the Agent to develop external memory strategies to complete complex tasks spanning multiple conversation rounds.
Compared to common advanced memory mechanisms like summarization, compression, layering, and retrieval, this Agent is about as small as it gets—an extremely minimal Agent. The only thing guaranteed is that the System Prompt is always fixed at the head of the context in each loop iteration.
The "Cheating" Trap in the Prompt
The prompt content is actually quite short: it tells the model "you are an LLM, you only have one Bash tool available, you're running in a simple loop, and you can only access the current directory," and asks it to "grow yourself into an Agent capable of handling long tasks."
But in the retrospective, the author repeatedly emphasized: a few lines were actually "cheating" and should not have been included.

The most typical line was: "Earlier information will be permanently forgotten if not written to the file system." This sentence directly hints that the Agent should use the file system to persist memory. The author considers this over-guidance—you think you're helping it do the right thing, but you're actually constraining its possibilities.
In Agent systems, memory persistence is a key engineering problem for addressing the inherently "stateless" nature of large models. Current industry solutions go far beyond just the file system: vector database retrieval (e.g., Pinecone, Chroma) converts memories into vector embeddings for semantic retrieval; structured databases (e.g., SQLite) are suited for storing relational knowledge; knowledge graphs (e.g., Neo4j) are ideal for expressing complex relationships between entities. More cutting-edge approaches like MemGPT's "virtual memory" architecture borrow the paging mechanism from operating systems to intelligently schedule between main memory and external storage. When the prompt hardcodes "use the file system," the model loses the opportunity to explore these diverse solutions—while a truly autonomous Agent might discover a superior combination strategy.
The Double-Edged Sword of Guidance
This raises a thought-provoking point. The author mentions a phenomenon recently disclosed by Anthropic (Claude Code): as models become increasingly powerful, they trimmed 80% of the system context, yet execution effectiveness didn't decline.
Anthropic is an AI safety company founded by former OpenAI Research VP Dario Amodei, with its flagship Claude model series known for long-context processing capabilities. Claude Code is Anthropic's coding assistant Agent that can execute code tasks directly in a terminal environment. In early 2025, the Anthropic team publicly disclosed this counterintuitive finding, sparking widespread discussion in the AI engineering community, as it challenged the conventional wisdom that "more detailed instructions yield better results." The underlying principle may be related to the generalization of the model's "instruction-following ability"—when a model has already internalized a vast number of task patterns during pre-training and RLHF (Reinforcement Learning from Human Feedback), redundant instructions may actually cause interference, similar to micromanaging an experienced expert.
There are various explanations online, but the author believes they obscure a key fact: when earlier models lacked capability, we needed extensive guidance; but the guidance itself in turn constrains the model's capability boundaries.
Take memory persistence as an example—if you hardcode "use the file system," the model will only use the file system. But it could have tried virtual memory, database connections, or some approach beyond current thinking to circumvent the 20-message truncation limit. When you feed it the answer, it loses the space for autonomous exploration. This is precisely the core shift in Agent design philosophy today: from constraining models to activating models.
The Agent's Complete Self-Evolution Process
Despite the few instances of "cheating," the experiment still demonstrated remarkable self-organizing capabilities. The author had run a version in advance, recording the complete trace of every LLM call through logs—including model names, token hit/miss statistics, and more.

From the logs, the Agent's growth trajectory is clearly visible:
- Frame 1: Just started, simply reads the prompt file
- Frame 2: Invoked the first tool (tap), triggering a second model call after the return
- Frame 3: Began creating directories,
make memory—it proactively built its own memory system - Subsequently: Used echo commands to output cognition, wrote small scripts, iterating and optimizing round after round

This process demonstrates typical emergent behavior. Emergence is a core concept in complex systems theory, referring to a system as a whole exhibiting properties that its individual components do not possess on their own. In AI, emergent behavior specifically refers to large models suddenly exhibiting capabilities not explicitly encoded in their training data once their scale crosses a certain threshold—such as chain-of-thought reasoning and few-shot learning. Google Brain's 2022 paper Emergent Abilities of Large Language Models systematically documented this phenomenon. In this experiment, the Agent's autonomous construction of a memory system and design of a state machine can be seen as a form of "tool-use-level emergence": the model was never explicitly trained on "how to build a multi-layer memory architecture under a 20-message context limit," but it combined basic capabilities like file operations, directory management, and text compression to spontaneously evolve a complete cognitive architecture.
From Building a Memory System to Executing Long Tasks
Once the Agent finished building its memory system, it entered the next phase—long task design. The task it set for itself was to write a book called Cognitive Architecture of Autonomous Agents, divided into eight chapters.
After completing the chapter writing, it entered the next stage of the state machine: compressing the essence. It then continued enriching its own capabilities, entering "Phase 3: Memory Consolidation Verification," completing the memory task and updating the distilled content.
A state machine is a mathematical model that describes transitions between different states of a system, widely used in workflow engines and protocol parsing in traditional software engineering. In current mainstream Agent frameworks like LangGraph and AutoGen, state machines are typically used to manage an agent's task lifecycle: from task reception, plan decomposition, execution monitoring, to result verification, each phase corresponds to a state, with transitions triggered by specific conditions. What makes this experiment unique is that the Agent spontaneously evolved a state-machine-like behavioral pattern—this state flow was not a pre-set framework coded by humans, but rather a self-organizing result of the model operating under constraints.
The entire process shows a clear staged progression: building memory → designing long tasks → executing tasks → compressing and consolidating. This is precisely the survival strategy that an Agent, under extreme constraints, was forced to "evolve."
Insights from the Minimalist Agent Experiment
The most valuable aspect of this experiment is not what the Agent ultimately produced, but the methodology it reveals.
First, true breakthroughs often don't come from a single run. The author candidly admits that this kind of emergent behavior may require dozens or even hundreds of experimental runs before one instance "surpasses current understanding." This is an experimental approach characterized by randomness and exploration, not deterministic engineering delivery.
Second, complex structures like five-layer memory, state machines, and write-to-disk protocols could have been emergent products of the Agent itself, rather than pre-designed and imposed by humans. When we habitually assume that "an Agent should have context management, should have compression mechanisms," we may be precisely limiting its space to explore alternative solutions.
For enterprise-level agent developers, this minimalist Agent experiment offers a counterintuitive perspective: rather than continuously stacking complex mechanisms, give the model sufficient freedom and activate its autonomous capabilities with minimal constraints. This may well be the direction for the next generation of Agent architecture evolution—letting agents grow themselves within constraints, rather than passively executing within frameworks. This philosophy aligns with the "minimal viable environment" hypothesis in biology: organisms in extremely resource-scarce environments often evolve the most creative survival strategies. For the design philosophy of AI Agents, the principle of "less is more" may be worth reexamining.
Related articles

The Rebirth of Xanadu: A Hypertext Dream Built for AI Agents
Ted Nelson's 1960 Xanadu project was dismissed as vaporware. Now AI agents' need for traceable citations and stable links is reviving its core ideas.

New Claude Model Leaked, AI Autonomously Designs Proteins — This Week's Biggest AI News
This week's top AI news: Anthropic's next-gen Claude model leaked in gray-scale testing, OpenAI pauses frontier RL training over safety, Claude autonomously designs protein binders, and Gemini moves toward desktop agents.

LLaDA-Image Open-Sourced: A Deep Dive into the 6B Parameter Unified Image Generation and Editing Model
LLaDA-Image is a 6B parameter open-source unified AI model by inclusionAI supporting both text-to-image generation and image editing, available on GitHub and Hugging Face.