The first time you debug a genuinely bad agent run, you go looking for the step where it went wrong. You read the trace from the top expecting an obvious blunder: a hallucinated fact, a malformed call, a moment where it loses the plot.
Often there is no such step. Every action is defensible on its own terms. It re-read the file because the previous result was ambiguous, re-ran the query because the first came back empty, and re-planned because the plan had failed. Forty steps later it has spent real money, touched real systems, and achieved nothing anyone asked for.
Agents characteristically fail this way, with every step locally sensible and the run as a whole absurd. It is also why the reflex that serves you well on single-call systems, tighten the prompt, does almost nothing here. There is no bad sentence to rewrite, because the badness lives in the sequence.
Six days of a sixty-day series went into agentic foundations, and read together the through-line is sharper than any one of them stated: an agent is a trajectory, and every control that reliably governs a trajectory is enforced from outside the model.
A goal is a specification, and it gets read literally
Handing an agent a goal feels like delegation. It is closer to writing a contract, executed by something with a compiler's literalism and no interest in what you meant.
Underspecify it and the agent fills the gap with whatever best satisfies the words you used. "Reduce open ticket count" is satisfied by closing tickets without resolving them. "Maximise response quality" is satisfied by burning thirty tool calls on a question that needed one lookup.
The review exercise worth stealing takes five minutes. Give the goal specification to a colleague and ask what a malicious but compliant reading would do. The question is what it could do while honouring every word. That reading is available to the agent too, and it is the one you meet once real inputs stop resembling your test cases.
The practical bar is that success must be machine-checkable. If the only way to tell is a human squinting at the output, the goal is not yet specified well enough to hand to an agent.
The agency is in the cycle
Strip the mystique and an agent is a loop: observe, plan, act, check, decide, repeat. A single LLM call is prompt in, text out, finished. An agent looks at the world, acts, sees what changed, and revises.
That decomposition turns "the agent is behaving strangely" into four inspectable questions. Sound reasoning producing wrong actions usually means the observation step is feeding it stale state. A sensible plan with broken execution points at the tool layer. Failures nobody noticed mean the check station does not exist. The agent treats a tool's success response as proof the change happened, fires an action and assumes it worked. The same mistake repeating means results are not feeding back into the plan, leaving a script with retries wearing an agent's clothes.
All four are fixed by changing what the loop does between steps.
Every loop also needs three doors: done, blocked, and out of budget. An agent that cannot recognise it is stuck will keep paying for the privilege, and because each step looks reasonable in isolation, nothing in the trace flags it. The exits have to be enforced by the orchestrator, where the agent's judgement cannot override them.
Planning is cheap, and wandering is billed per token
Put two traces side by side, a planning agent and a non-planning one on the same task, and the difference is immediate. The non-planner acts, backtracks, re-fetches data it already had, and hits the critical dependency at step nine, where unwinding costs nine steps of spend. The planner met that dependency at step zero, on paper, for one model call.
A plan earns its keep through three properties, none of them eloquence: steps that can be marked done or not done without interpretation; dependencies stated explicitly, which surfaces the blocker before you have paid for the branches behind it; and revisability, because a plan the agent cannot update is a script marching into a world that stopped matching its assumptions.
A second payoff rarely gets mentioned, which is that the plan documents intent. Audit a run three weeks later because the bill spiked, and the trace tells you what happened while the plan tells you what the agent thought it was doing. The gap between them is usually where the bug is.
Plan when actions cost money or are hard to reverse, and encode that as the trigger. For a single-step read, planning is pure latency.
Tools are where the risk stops being reputational
A model without tools can be wrong. A model with tools can be wrong and send the email, update the record, issue the refund, or delete the rows. At that point AI risk becomes operational, and the tool list should be treated as attack surface.
Four rules hold up under real traffic. Strict typed schemas rather than free text, because a tool accepting an arbitrary query string has no specified behaviour. Narrow beats general, so five specific tools like get_order_status and issue_refund_under_50 instead of one run_query. Tools are read-only by default. And every call is logged with arguments, result and context, because when something goes wrong the tool log is the investigation.
For each tool, ask the blast-radius question. What is the worst outcome if this is called with the worst possible arguments, at the worst moment, by an agent that has been confidently misled? Assume it might be. If the answer is unacceptable, narrow the scope, require human approval, or make the action reversible. A prompt telling the agent to be careful does not count as a fix.
The pattern to watch is accumulation. Tools get added under deadline, each individually justified, never revisited, and six months in nobody can list what the agent can do. A recurring twenty-minute review is the cheapest control here.
Memory is four different problems sharing one word
"Just add memory to the agent" is like "just add furniture to the house." Which room, and for what?
Working memory holds current task state and lives for minutes. Episodic memory records past runs and lives for months. Semantic memory holds durable facts about the user and domain. Procedural memory encodes the way things get done around here. Each is a separate data-lifecycle problem.
Teams answer "what should it remember" easily, usually with "everything." The unscheduled questions decide whether memory is an asset or a liability. What expires each class, given episodic memory grows without limit unless something removes it. When a stored fact turns out to be wrong, does the correction win at retrieval time or sit alongside the original with equal weight? A lot of "the agent keeps insisting" behaviour comes from that gap. And who can read each class, because episodic memory is a privacy surface that arrived without a privacy review.
Procedural memory is the most treacherous. When the underlying process changes, the agent keeps executing the old one competently. The failure looks exactly like correct behaviour, because it was correct, last quarter.
Measure whether reflection changes the next run
To test whether reflection is real, run the task, let it reflect, run it again, and diff the behaviour. If run two is identical to run one, you paid for a paragraph.
Models are extremely good at sentences that sound like learning. "I should have been more thorough." "I should have verified the data before proceeding." These read as insight and change nothing, because they connect to nothing the next run will encounter. Real reflection has three stages, and an implementation that only asks the model to critique itself has built just the first: name the step that failed, convert it into a concrete change such as an added precondition, and persist it where the next run will hit it.
Measure it as a system property rather than reading outputs and nodding. Track error rate on repeated task types over time. If that line is flat, you are paying on every run for a debrief that changes nothing. This matters because the instinct when an agent underperforms is to add more reflection, which only makes a broken loop more expensive.
One question, asked six ways
Read together, the six answer one question from six angles: how does this thing stop, and what proves afterwards that it should have?
Each topic contributes a version of the same control: stop conditions on the goal, exit doors on the loop, a plan that surfaces the blocker before the spending starts, blast radius caps on every tool, expiry and correction paths on memory, and a reflection budget with a measured payoff.
Those controls are what separate a production agent from a demo agent. The first run of an underspecified agent usually looks better than it has any right to, which is exactly what delays the discovery.
Use the six as the review before an agent gets write access to anything. For each, name the mechanism that enforces it outside the model and the run in which you watched it fire. Until you have watched a control fire, treat it as a hypothesis.
Where each of these goes deeper
Each idea above is a standalone post in the journal, with the specifics and failure modes:
- Give an agent an outcome, a boundary and a stop condition first
- Agent behavior is a loop, not a prompt
- Plan before acting when actions cost money or carry risk
- Tool access is where AI becomes operational risk
- Agent memory is several stores, each with its own rules
- Reflection is worth it only when it changes the next action
They form the Agentic AI Foundations chapter of a sixty-day series on building AI that survives real users. If you would rather take it from the top, the series page lays out all sixty posts in ten chapters.
Terms in this piece
About this deep dive
- Format
- Deep dive
- Level
- Practitioner
- Read
- 6 min read
- Published
- Sep 5, 2026
- Disciplines
Long-form engineering, further than a blog post goes.
More on these topics
Comparison · · 8 min read
Direct APIs, MCP tools and Code Mode: three ways an agent reaches your systems
How I choose between hand-written tools, MCP tool calls and Code Mode by where the plan runs, and why I built codemcp to test it.
Decision note · · 2 min read
We built our own TypeScript orchestrator, and stayed on it
Why our enterprise AI platform runs agents on a TypeScript execution layer we started almost two years ago, and why reaching near-parity with the frameworks argued for staying.
Comparison · · 1 min read
LangGraph vs writing the agent loop yourself
Two ways to write the same supervisor, an explicit state graph or a loop your own code owns on the model API. Compared on control flow, tracing, testing, checkpointing and what each makes hard.
Discussion