Building Agents? Stop Treating messages[] Like a Database
Stop using messages as your agent's memory. Learn how structured state makes AI agents more reliable, efficient, and production-ready.

Recently I started asking our developers and quality assurance (QA) engineers, “What keeps getting sent back in review on agent-written code?”
Knowing what slows us down helps us improve outcomes for our own teams and our clients, and the same kinds of answers keep coming up, including duplicate utility functions (one codebase had the same cookie getter in several places), new UI built where a component already existed or on a legacy one, pull requests that touch lots of unrelated files with out-of-scope “fixes,” and tests that fall out of sync after a change.
Each of those is a gap the agent filled with a reasonable-looking guess because nothing in the spec or the repo told it otherwise, and since the guess looks finished, it gets through review and turns up later in QA, or in production.
Today, most teams use coding agents as assistants: the agent writes the code, and a developer feeds it context, steps in when it goes sideways, and fixes what's left by hand. In the consults we run, that arrangement levels off at a 20–30% productivity gain. Getting past it comes down to four building blocks that let an agent finish a ticket on its own and bring you only the decisions that need a person.
In agent-assisted development, the developer holds the context, like which component to reuse or what the ticket really meant, and feeds it to the agent one chat at a time. Agent-driven development puts that context in the spec and the repo, so the agent can plan, build, and check its own work and only comes back to you when a decision needs a person.
Our maturity model for agent-driven delivery calls this the move from Level 1, where a person vouches for every change, to Level 2, where the team agrees on acceptance criteria before the agent writes any code.
Agents can only work from what's written down, and unless something defines done, they decide for themselves when to stop. The blocks below close those gaps, in the same order as the labs in the lesson kit we use in our workshops.
Claude Code and tools like it all run the same loop, gathering context, editing code, and checking the result until the agent decides it's done. The harness is what you set up around that loop, and in the kit it's the three pieces in the 01-harness folder.
A Map and Rules the Agent Reads First
Most coding agents look for a Markdown file called AGENTS.md at the root of the repo and read it at the start of every session. Claude Code only reads CLAUDE.md, so we make that file a single line, @AGENTS.md, which points it to the same instructions every other tool is using.
What goes in it is what you'd tell a new hire on their first day: which folders matter, where this repo does things differently from what they'd expect, and the one command that lints, typechecks, and tests. We keep it to about 20 lines, because the agent reads every one of them in every session, and a long file crowds out the context the task needs.
A Definition of Done It Can Check
Left alone, an agent stops when it thinks it's finished, so we give it a better rule with two lines in AGENTS.md:
That turns the loop into a test loop, where the agent writes a test for each criterion and keeps fixing until the check passes. It only works when the criteria are specific enough to test and someone has agreed to them before any code exists, and it's what stops tests from drifting out of sync after a change.
A Plan a Person Approves
Before the agent touches a file, we have it write a plan listing the files it will change, the components it will reuse, and a test for each acceptance criterion. A wrong assumption costs a sentence to fix in a plan and an hour in code, so this is where your review counts most, and where you'll catch the duplicate helper or legacy component before it's built.
Stop rules tell the agent when to pause and ask, for instance when it needs a file outside the plan or the same check fails three times, which keeps out-of-scope fixes out of the pull request. Self-review has it mark each criterion met, partly met, or not met, with the file and line that prove it, before it calls anything done.
AGENTS.md loads every session, so anything else should come in only when a task needs it, starting with the spec. The quickest way to see what a spec is missing is to have the agent read the ticket and list every assumption it would have to make before it builds. That list is your spec review, and each answer goes where it belongs (the ticket if it applies to this change, AGENTS.md if it applies to every change, or a decision record if it's a trade-off worth explaining once) before you regenerate.
For the rest, the Model Context Protocol (MCP), an open standard for connecting agents to other systems, lets the agent look things up as it works. I'd start read-only with Jira for tickets, GitHub for past pull requests on similar changes, and Context7 for current library docs, adding one at a time and keeping tokens out of git. To see what a source is worth, run the assumptions list with and without it and count the guesses that disappear.
Every session starts from nothing, so the agent's memory is whatever you've written down. Rules live in AGENTS.md, and one habit keeps them current: if you've corrected the agent on the same thing twice, add a line.
Procedures live in skills, folders with a SKILL.md file that holds a name, a short description, and numbered steps. The agent loads only each skill's description until a task matches it, which keeps context use low because a full skill can be much longer. The catch is that a vague description means the skill never runs. The kit chains three together: prepare turns a ticket into an approved plan, tdd builds from it one test at a time, and pr-review checks the diff against the ticket and AGENTS.md.
Once the first three blocks are in place, one developer can supervise several agents at once. Splitting one feature across them is harder, because collisions happen silently: one agent overwrites another's edit, and the main agent still reports everything done.
The fix is the one you'd use for two developers, a short CONTRACTS.md that defines the shared types, gives each shared file a single owner, and sets the merge order. After that, trust the diff and the test run over the agent's summary, and skip splitting for small tasks or tangled ones where every part touches the same files.
Run the same ticket twice with the same model and prompt, changing only the setup: once with AGENTS.md and the skills moved aside, and once with the block you're testing. You're looking for whether the agent stopped asking things it asked the first time and whether anyone had to step in less, and for context sources, how many assumptions show up in each plan.
To see where each team sits before you pick a first step, our maturity model for agent-driven delivery lays out five levels and the one question that places a team against them.
Stop using messages as your agent's memory. Learn how structured state makes AI agents more reliable, efficient, and production-ready.
Traditional approaches to change management weren’t working before. AI just makes the gaps impossible to ignore.
How smart companies are evolving with agent-powered delivery models, and what it takes to lead in the new era of intelligent services.