Skip to main content

Prompt, Context, Harness, Loop: The Real Agent Engineering Stack

· 9 min read
Hassan Tariq
Engineer · AI agents, cloud

Last week I asked my coding agent to delete an unused workflow harness, keep the docs honest, and ship a release. It reviewed the change, bumped the version, opened a PR — tripped three CI gates, from four self-inflicted root causes — fixed every one, went green, and shipped. A human signed exactly one thing: the irreversible step.

That small episode is the whole argument of this post. The thing that made the agent trustworthy wasn't a clever prompt. It was the layers around the prompt.

Five words everyone's arguing about

"Prompt engineering." "Context engineering." "Harness engineering." "Loop engineering." "Spec-driven development" — people say "speckit." The discourse treats them like competing fads, each year's skill obsoleting the last. On real enterprise agents they're nothing of the sort. They're layers in a stack — and most failures I see come from over-investing in one layer while ignoring the one that would actually have caught the bug.

Here's the map I use.

DisciplineThe unitWhat it optimizesThe failure it preventsWhen it's enough
Prompt engineeringone instructionclarity of a single askvague, ambiguous outputone-shot, low-stakes tasks
Context engineeringthe window's contentswhat the model sees — sources, memory, tool resultsconfident hallucinationmost enterprise reliability
Harness engineeringgates and validatorsdeterministic enforcementmistakes reaching productionwhen "looks right" isn't proof
Loop engineeringthe act → verify cycleself-correctionone bad step becoming a bad outcomeautonomous, multi-step work
Spec-driven devthe specshared intent before codebuilding the wrong thing wellnon-trivial, multi-file changes

Look at the last column. Each discipline has a narrow regime where it is sufficient — and a much larger regime where it is necessary but nowhere near enough.


They stack, they don't compete

Read it from the inside out. A prompt wraps a model call. Context decides what that prompt can even see. A harness is the deterministic shell that refuses to let bad output through. The loop drives the whole thing — act, observe, verify, repeat — and an explicit spec sits on top as the definition of "done."

You can be a world-class prompt engineer and still ship nonsense if the outer layers are missing. The reverse is rarely true: with strong context, a real harness, and a tight loop, even an unremarkable prompt has a real shot at a useful, checkable answer.


Context engineering: the biggest lever in the enterprise

If you upgrade only one layer, upgrade this one.

In an enterprise, the model's parametric memory is the least trustworthy thing in the room. Your policies, your architecture standards, your approved patterns, last quarter's decision — none of that is in the weights. The job of context engineering is to put the right, current, authoritative material in front of the model before it generates, and to make ungrounded output visible instead of plausible.

The pattern I keep coming back to is ground before you generate:

The branch that makes it enterprise-grade is "cite or flag." If there is no approved source, the agent doesn't smooth over the gap — it labels the output ungrounded and says so. A confident "I can't confirm this is standard" beats a fluent fabrication every time. (I wrote about the same instinct for code in the Baymax post: don't guess an API, read the source.)

Prompt engineering tweaks the question. Context engineering changes the evidence. At scale, evidence wins.


Harness engineering: deterministic gates beat ceremony

A harness is everything around the agent that fails closed — schema validators, a build that must stay green, a registration contract, an eval suite, a policy check before a tool fires.

The mistake is to confuse ceremony with rigor. Ceremony is paperwork that makes a process feel serious. Rigor is a check a reviewer can re-run that turns red when something is actually wrong. They are not the same — and only one of them is load-bearing.

Which brings me to the harness I deleted.


The "speckit" lesson: I removed a harness and shipped faster

The change my agent was shipping last week was itself a harness removal — which makes it a clean illustration.

We had vendored the full GitHub Spec Kit harness: a /speckit.specify → /speckit.plan → /speckit.tasks → /speckit.implement pipeline (plus a constitution and optional clarify/analyze steps), around fifteen generated agents, and a pile of scripts and templates. It is a genuinely good methodology. But in our repo it had never been run. Every guarantee it was meant to provide — grounding, an artifact-registration contract, a green build before merge — was already enforced by two things that run on every change: a one-page spec reviewed in the PR, and a deterministic build.py --check gate.

So we deleted the harness and kept the gate. The rigor was never in the ceremony — it was in the gate.

The principle generalizes: right-size the harness to the failure mode. A heavyweight pipeline nobody exercises isn't rigor — it's rigor cosplay. The deterministic gate a reviewer can rerun in five seconds is the real thing. If your ceremony and your gate enforce the same property, delete the ceremony.

(For the full "build it, test it, delete it" instinct — including a whole execution plane I tore down — see the Baymax post. Knowing what to remove is part of the engineering.)


Loop engineering: the layer everyone underestimates

Here's the part of last week's episode I find most instructive.

The agent did not get it right the first time. It removed speckit from the spell-check dictionary while a changelog still used it; it tripped two separate markdown-lint rules — a blockquote it stacked wrong, and a generated file whose lint-disable header it dropped; and it left two links pointing at a repo that doesn't exist. Three red checks, four root causes. Then it read the failures, traced each to a cause it had introduced, fixed all of them, and only then asked a human to merge.

That cycle — act → observe → verify → correct → repeat — is what converts a capable model into a dependable colleague. And notice the dependency: the loop only has teeth because the harness gave it something real to fail against. Loop and harness are symbiotic. A loop with no gates is just an agent confidently walking off a cliff in a very tight circle.

This is also where the human belongs — not babysitting every token, but signing the irreversible step. The agent ran the whole review-fix-verify loop on its own; a person approved exactly one thing: the merge that cut a public release.


So how much ceremony does this change need?

The map collapses into a single decision I make dozens of times a week:

  • Trivial (typo, dependency bump, doc tweak) → ship the diff. A reviewer can fully judge it.
  • Non-trivial (new behavior, multi-file) → a one-page spec for shared intent, then let the gate enforce correctness.
  • Irreversible / high blast radius (publish, migrate, delete data) → spec plus a threat model, plus a human on the irreversible action.

Match the weight to the risk. Most teams either gate everything (and grind to a halt) or gate nothing (and page themselves at 2am). The skill is calibration.


The field map

  • Prompt is table stakes. Necessary, lowest leverage. Stop polishing it past "clear."
  • Context is the lever. Feed the agent real, current, cited source. Make ungrounded output visible, not plausible.
  • Harness is the safety net. Deterministic gates that fail closed. A green check beats a confident sentence.
  • Loop is the trust. Act → verify → correct. It earns autonomy — but only because the harness gives it something honest to fail against.
  • Spec is the steering. A one-page statement of intent stops you building the wrong thing well. Anything heavier has to earn its keep against the failure mode.
  • Delete the ceremony the gate already covers. Rigor cosplay is worse than nothing — it costs time and manufactures false confidence.
  • Humans sign the irreversible step. Everything else, let the loop run.

The agents that behave like senior engineers aren't the ones with the cleverest prompts. They're the ones wrapped in real context, honest gates, and a loop that refuses to declare victory until the checks are green.

Ship the gate. Delete the cosplay. Let the loop run — with a human on the one button that has no undo.