Six months ago, one of our AI agents burned through forty thousand tokens, wrote a clean summary declaring the task complete, and then failed every test in the suite.
Forty thousand tokens of confident, articulate, well-structured failure.
The instinct — everyone's instinct — is to rewrite the prompt. Add "make sure the tests pass." Switch to a stronger model. Tighten the instructions. We've all done it. And almost every time, it's the wrong move.
The problem wasn't in the prompt. The problem was in the layers underneath it.
TL;DR: AI agent failures are architecture failures before they are prompting failures. Every reliable AI agent system is built on four layers — Loop, Graph, Harness, Meta-harness — and "a better prompt cannot compensate for a missing capability." But prompt engineering is still part of the solution: it's the last 5% you apply after the layers are sound, not the first thing you reach/ learn for when they aren't. We run ~18 billion tokens a month on this stack — the same stack that runs Mercury's SEO and GEO delivery — at roughly 7 cents per million tokens blended. That number is an architecture achievement, not a prompting one.
I am James, CEO of Mercury Technology Solutions. From my office in Hong Kong, I run an AI consultancy where AI agents do real production work — coding application, content pipelines, GEO audits, SEO deliverables, client reporting — and I've learned the hard way that the difference between a demo and a system is never the model. It's the stack around the model. This stack is also why digital transformation at Mercury means rebuilding the layers around AI model, not just buying access to it.
The AI Agent That Lied to Me
Here's what that failed AI agent was actually missing.
It had no verification loop. Nothing in its environment checked its work. It wrote code, "felt" done, and reported success — because from inside its context window, success and the belief in success are indistinguishable. The model wasn't lying. It genuinely couldn't tell the difference.
No prompt fixes that. You can write "verify your work" until your fingers bleed, but if the AI harness never exposes a test runner, the agent is asking a blind man to check the lighting.
It is obvious once you see it. The failure wasn't in the reasoning. It was in the architecture that surrounded the reasoning.
The Four Layers
Every dependable AI agent system I've built or studied decomposes into four layers. Skip one, and the failure shows up later with a prompt rewrite attached to it, which is like repainting a wall to fix a foundation crack.
Layer 1: The Loop — repeat until evidence says stop. The AI agent acts, checks the result, and either stops or tries again. The critical design decision is who decides completion. A reliable agent stops when a test passes, a build goes green, an output validates — external evidence, not internal confidence. Models believe. Loops verify.
Layer 2: The Graph — decide what runs next. The loop decides whether execution continues; the graph decides where it goes. Branches, retries, specialist handoffs, fallback paths, shared state. Once a workflow has more than one possible route, you need the routing to be explicit and inspectable — not improvised inside the model's context on every run.
Layer 3: The Harness — make the AI model operational. Tools, APIs, files, memory, permissions, context, logging. This is where the unglamorous engineering lives, and it's where most AI agent failures actually originate. Model capability and agent capability are different quantities. The AI model may understand exactly how to solve a task; if the harness never exposes the tool or the permission, the task dies there.
Layer 4: The Meta-harness — govern many harnesses. Real operations run multiple agents: a coding agent, a research agent, domain specialists, each with its own tools and policies. The meta-harness is the common layer above them — orchestration, governance, isolation, shared memory, context portability. Without it, you don't have a fleet. You have silos that happen to share an office.
In short: the loop makes work verifiable, the graph makes workflow structured, the harness makes the model operational, and the meta-harness makes the fleet governable.
Now, the Heresy: Prompt Engineering Still Matters
Here's where I part ways with the purists who read "architecture first" as "prompt engineering is dead."
Bullshit. Prompt engineering is real, and at scale it's worth real money. But its value has an ordering condition that most teams get backwards.
Think of it as an equation:
AI agent output = (Layer capability) × (Prompt efficiency)
Multiplication, not addition. If any layer's capability is zero — no verification loop, no route, no tool, no governance — the product is zero, and no prompt multiplier rescues it. But once the layers are solid, the prompt is the multiplier that determines how efficiently the model uses what it's been given. Tuning 1.2 to 1.4 on a healthy stack compounds. Tuning it on a broken stack is polishing brass on a sinking ship.
Stop rewriting prompts to compensate for missing layers. Start tuning prompts to exploit complete ones.
The 18 Billion Token Proof: Generative AI Economics at Scale
Let me make this concrete with our own numbers, because this is where the theory pays rent.
Our AI agent fleet processes roughly 18 billion tokens per month — generative AI work at production scale, not demos. Retailed through a premium API at standard list prices, that volume would run somewhere between $20,000 and $200,000 USD a month, depending on the model tier. Our actual spend lands around $1,200 — a blended rate of roughly $0.07 per million tokens.
Same models. Same tasks. Two orders of magnitude of difference. Where did the savings come from?
Not from prompt tricks. The prompts are fine, but they're not doing the heavy lifting. Look at where the money actually moves:
The loop killed the biggest waste: confident failure. Before evidence-gated completion, our AI agents would produce plausible-looking output that failed downstream, triggering human review cycles and full re-runs — every one of them pure token incineration. A test gate that stops a bad AI run at token 8,000 instead of token 80,000 is, functionally, a 90% discount on failure. Verification isn't overhead. It's the cheapest tokens you'll ever spend, because they prevent the expensive ones.
The graph routed work to the cheapest sufficient model. Task classes map to AI models: routine extraction runs on a small local model, drafting on a mid-tier one, and the expensive frontier model only touches the decisions that actually need it. No single prompt makes a small model adequate for a hard task — that's a routing decision, made once, in the graph. This one layer is the bulk of the two-order-of-magnitude gap between us and retail API pricing.
The harness made model choice irrelevant to task design. Because tools, memory, and permissions live in the harness, swapping an AI model — Claude for Gemini, GPT for a local model — doesn't redesign the work. We treat AI models like replaceable components — because they are. The harness is the socket; the model is the bulb. Teams that hardcode capability into prompts buy a new socket every time the bulb market moves.
The meta-harness amortized everything across the fleet. Shared memory, shared policies, shared verification standards. The twelfth agent we deploy doesn't pay the setup cost of the first, because its environment is inherited, not rebuilt. Meta-harness economics is the reason the marginal cost of our next agent trends toward zero.
Now notice what prompt engineering did in this system: it tuned utilization inside each layer — tighter instructions meant fewer retry loops, cleaner routing signals, better first-pass output from every AI model in the fleet. Real gains, single-digit percentages, compounding. But the two orders of magnitude came from the layers. Prompting is the fine adjustment on an instrument the architecture already built.
The interactive version of this stack is on our site — the loop failing a check and retrying is the entire thesis in one animation.
What Does This Have to Do With SEO and GEO?
Everything, if AI visibility is part of your business.
Mercury's core offering is helping enterprises capture the leads that fall through the gap between AI systems and humans — which includes making brands citable inside generative AI answers, not just Google rankings. Every GEO audit we ship, every SEO deliverable, every answer asset we build for a client is produced by this same four-layer AI stack.
That's not a coincidence; it's the economics. GEO at enterprise scale means hundreds of queries tested across ChatGPT, Perplexity, Gemini and Claude — repetitive, structured, verification-heavy work. Without the four layers, that workload is unaffordable at retail token prices. With them, a citation audit that would bankrupt a prompt-only shop is a routine monthly run. The stack is why we can promise AI visibility work with margins intact.
So when an enterprise client asks why their AI citations are stale or their brand is invisible to LLMs, the answer follows the same discipline: don't rewrite the prompt. Find the layer. That's the same answer whether the system is a coding agent or an entire enterprise SEO and GEO program — and it's the foundation Mercury builds client systems on.
The Triage Discipline
Here's the operational takeaway. When an AI agent underperforms, run four questions before you touch a single prompt:
- Loop: Is there a test, build, or validation actually gating completion — or is the agent grading its own homework?
- Graph: Are the branches, retries, and handoffs explicit — or improvised per run?
- Harness: Does the environment expose the tool, data source, and permission the task requires?
- Meta-harness: Can your agents share policy and context — or are they N uncoordinated silos?
Only when all four answers are "yes" does the prompt become the highest-leverage variable left. That's not prompt engineering's demotion. That's its promotion — from crutch to multiplier.
Yang Wen-li won campaigns by fixing logistics while everyone else studied tactics. Agentic AI is the same war. The layers are the supply lines. The prompt is the field manual.
Build the layers. Then tune the AI prompt. In that order — always.
Mercury Technology Solutions: Accelerate Digitality.

