Home / Articles

Prompt, Context, Harness, Loop: The Four Layers Behind an AI Agent

Prompt, context, harness and loop: the four layers behind every AI agent, from prompt engineering up, and why each exists because the layer below fell short.

Publisher: REACTAPP.TOP7 min read1650 words

This article is published in English.

Sources: Prompt, Context, Harness, Loop: An Agent’s Anatomy

A common starting question: if a chat model is just words in and words out, how do AI agents book flights or write code? The answer comes in four layers, and each exists because the one beneath it cannot explain a working agent alone. A short way to hold them together: a great prompt without context is a fine sentence spoken into an empty room. Great context without a harness is a perfect plan with no hands. A full harness without a loop is a skilled worker who still waits for a person to keep saying "now the next task".

Layer one: the prompt

The unit of work here is a single input. The model remembers nothing from before the call, so the prompt must carry everything it needs: a role, background, instructions, examples and an output format, all packed into one message. When results disappoint, the skill lies in finding which ingredient is failing and not in rewriting everything.

The toolbox is substantial:

  • Zero-shot prompting asks directly with no examples and hopes the model understands.
  • Few-shot prompting supplies two or three input-output samples, and the model pattern-matches from them.
  • Chain-of-thought asks the model to reason step by step first, which can noticeably help math, logic and multi-part problems.
  • Role prompting, such as "you are a senior editor" or "you are a skeptical reviewer", shifts tone and rigor.
  • Meta prompting and self-consistency build on these for harder problems.

All of it amounts to good instructions, much like a clear email, and it answers one narrow question: which words should be used right now for this one request? A carefully written prompt for a research summary can produce sharp output with clean structure and no fluff.

The weakness appears with a follow-up. Ask something in the same chat that refers to a point three messages back, and the model may miss it entirely, confidently answering a slightly different question. It does not remember the room it is standing in. A good sentence turns out to be necessary but not sufficient, and something upstream of the prompt is missing.

Why not simply keep writing better prompts? Because prompt engineering was built for one-off tasks: ask, answer, done. Once the goal is something that acts over many steps, remembers events, uses tools or runs without a person typing each instruction, the clever sentence stops being the bottleneck. The bottleneck becomes everything around it. Prompting does not stop mattering. It just stops being the whole story.

Layer two: context

Here the unit of work is what stays inside the model's window at each step. The window is finite while available information is not, so curation becomes essential. Without it, important details sink beneath stale tool outputs and old conversation turns, and the model's attention degrades. A curator decides what stays, compresses what is useful but bulky and discards the rest. The skill is in knowing what to throw out, not in packing more in.

The room the model stands in has a name: context. That means everything the model sees on a particular call, not only the prompt: system instructions, retrieved documents, tool definitions, conversation history, long-term memory and earlier tool outputs. Context engineering can be summed up as curating what the model sees to get a better result. Prompting asks which words to use. Context engineering asks what the model knows at this exact moment.

An analogy from construction work helps. Onboarding a contractor for a day, one can hand over a perfectly worded work order, but without the floor plan, the permit history and yesterday's inspection notes, the wording will not save the day. The contractor will do the wrong thing with confidence. That mirrors the follow-up failure above: the model was not dumb, only under-informed. Most agent failures are context failures, not model failures. The model works fine, but nobody supplied the floor plan.

The obvious fix is to feed it everything: the full conversation, every document, every past interaction. More information, better answer. Practitioners found the opposite and gave it a name, context rot. Even models with huge windows measurably get worse when the window fills with marginally relevant material. The model does not run out of space. Signal drowns in noise, and irrelevant details start being treated as important. The better instruction is to give the right folder and not the whole filing cabinet. The discipline in one phrase is curation over accumulation: deciding what belongs in the room and, just as important, what stays outside.

Even with a perfectly curated room, a second wall arrives quickly. Flawless context yields a beautiful plan for what to do next, and then the model simply stops. It cannot open the file, run the code or check whether the plan worked. It is the contractor with the perfect floor plan and no hands.

Layer three: the harness

The unit of work now is the machine itself. A bare model only generates text. The harness turns it into something that can act, check its own work and recover from failure, through three phases:

  • Gather: assemble what is needed.
  • Act: run the model, call tools or sub-agents.
  • Verify: check the output with tests or a judge.

On failure, the whole cycle retries with updated context. That difference separates calling an API from running an agent.

A handy formula: agent = model + harness. Everything surrounding the model counts as harness, meaning code, configuration and execution logic alike. That covers callable tools, readable and writable memory, limits on permitted actions, the orchestration that picks the next step, and state that outlives a session.

The word itself fits. A horse is powerful, but without a harness it cannot farm, because straps and reins direct raw strength into useful work. Swap the horse for a model: it has the intelligence, but without tools, memory, guardrails and orchestration, that intelligence has nowhere to go.

One point reframes the picture. The harness does not make the model smarter. Replace the model with a better one and the harness stays the same, since it is a pluggable component underneath and not the star. What it contributes is structure: a clever model with no state of its own becomes one component in a closed system that takes actions, checks results and picks up tomorrow exactly where today ended.

That also explains what it means when an AI appears to remember something across sessions. The model is not remembering. The harness wrote it down somewhere and handed it back later. Every model call starts from zero, and the harness fakes continuity by pulling in yesterday's notes, today's task list and the state of the file system, handing all of it over as context before the model starts to think. Context engineering and harness engineering are therefore tightly coupled, because the harness decides what context is assembled on every call.

Layer four: the loop

A model with tools and memory seems like the summit. What more could an agent need? A heartbeat. Loop engineering is the newest layer, still being named as people build it.

Here is the gap. Even with a full harness, someone must still sit at the keyboard deciding what the agent does next: type a prompt, read the result, choose the next prompt, repeat. That is a human in the loop, one turn at a time, always.

Loop engineering swaps the manual back-and-forth for a system that drives the cycle on its own: think, act, look at what happened, choose the next move, go again, with no person retyping instructions in between. It resembles the difference between driving a car and building cruise control. The person is no longer pressing the gas every second, but has defined what cruising speed and stopping mean.

A concrete example makes it click. An agent assigned to fix a bug reads the error, forms a plan, edits the code and runs the test suite. The tests still fail, so it adjusts its approach, edits again and reruns the tests. Only when the tests pass, or when it has tried enough times to conclude it is stuck, does it come back to a human. Each of those cycles is the loop, and no one typed "try again" in between.

What can go wrong? A loop that acts without supervision can also repeat the same mistake, faster, with nobody noticing for a while. Careful designs therefore build a grader into the loop: a checkpoint, occasionally a second model playing judge, that scores the result against a rubric. Only after passing it may the loop consider the job done. Once nobody watches each step, verification stops being optional and becomes part of the loop's job description.

All four together

Prompting is telling someone what to do, once. Context is making sure the right folder is on their desk before they start. The harness gives them hands, tools and a memory that survives the weekend. The loop means no longer standing over their shoulder: they work, check their own output, retry if it is wrong, and come find you only when it is really finished.

Four stacked questions, each unanswered by the one before. Combined, they form what people now simply call an agent, as though it were obvious and always going to be this simple. It was not. Each layer became clear only because someone kept asking why until the previous layer's limits showed.