If you’ve used Large Language Models to write code for longer than 10 minutes, you’ve likely run into the Context Wall.
It always starts the same way. You open a fresh chat, explain your project, and the AI splits out flawless code. Encouraged, you keep chatting. You add features, fix bugs, and alter requirements. But by Prompt 30, something breaks. The AI begins forgetting core constraints, hallucinating functions and generating messy, cyclical code.
This isn’t an execution problem; it’s a context fatigue problem. When an LLM’s context window is crammed full of conversational chatter, tangential debugging loops, and shifting requirements, its cognitive capability degrades.
To solve this, researchers at Google introduced a new framework: The Elephant-Goldfish Model.
Introduced in the foundational Google Research paper, Elephants, Goldfish and New Golden Age of Engineering, this framework completely flips the traditional developer-AI relationship.
Instead of treating the AI as an on-demand code monkey, the Elephant-Goldfish model forces the developer into the role of an Architect. It splits your interactions into 2 distinct phases, handled by 2 completely different mental modes.
Like the proverb says, an elephant never forgets. In this phase, you use a long-lived continuous AI session. Together, you and the Elephant brainstorm features, challenge architectural assumptions, and map out edge cases. The ultimate goal of Elephant is to not to write code, but to draft a flawless, highly detailed Design Document (PRD or functional specification).
A goldfish has no long-term memory. In this phase, you spin up brand-new, completely stateless AI sessions. These “Goldfish” agents have 0 historical knowledge of your previous conversations. Their sole job is to act a cold-reader to stress-test the Elephant’s design document.
The core rule of Elephant-Goldfish model is simple: No production code is written until the design document passes the Goldfish Gates.
Before execution, the design document is fed to isolated Goldfish agents through a three-stage lifecycle:
A stateless Goldfish reads the document. Can an outside observer with zero historical context understand exactly what this software is supposed to do ? If the Goldfish asks a clarifying question, the document fails.
Specialized Goldfish agents (acting as Security, UX or Performance specialists) aggressively audit the design. They hunt for hidden logic flaws, missing edge cases, and architectural bottlenecks.
An implementation Goldfish looks at the blueprint and answers one question: Could a junior developer build this entire system right now without asking a follow-up question ?
If the document fails any of these gates, you take the Goldfish’s feedback back to the Elephant session, refine the blueprint, and run it through the gates again. Once it passes, the Elephant is finally allowed to generate the code. Because the blueprint is airtight, the resulting code is modular, clean, and free of technical debt.
A common objection to this model is: “This sounds great for greenfield projects, but how do I apply this to an enterprise codebase with millions of lines of legacy code?”
The framework handles this through a context-compression technique metaphorically called Peanuts and Hay:
Micro-Context Chunking: Large codebases are broken down into microscopic directories (the “peanuts”).
Bottom-Up Summarization: Isolated Goldfish agents scan these tiny directories and write hyper-dense, highly structured local
readme.mdfiles detailing local logic dependencies.Hierarchical Indexing: A higher-level agent summarizes those readmes into a parent structure (the “hay”).
This creates a highly compressed, completely accurate map of institutional memory that the Elephant can consult instantly, without ever overloading its context window.
The old way of using AI—writing code line-by-line in a messy, endless chat room—is dead. It creates fragile codebases and exhausting debugging loops.
The Elephant-Goldfish model proves that the design document is the code. By rigorously separating long-term strategic context (The Elephant) from isolated, stateless execution validation (The Goldfish), you can harness the maximum cognitive power of LLMs.
Next time you start a feature, resist the urge to ask your AI for code. Ask it for a design doc, bring in the goldfish to tear it apart, and watch your development velocity skyrocket.

Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.