Home/Blog/Prompt, Context, Harness: The Three Layers of Modern Agentic Engineering
Beginner DifficultyAutonomous Agents

Prompt, Context, Harness: The Three Layers of Modern Agentic Engineering

Prompt engineering, context engineering, and harness engineering are three interconnected layers of modern agentic engineering. Learn how they differ, how they work together, and how to identify which layer is responsible when an AI coding agent fails.

Prompt, Context, Harness: The Three Layers of Modern Agentic Engineering

You ask an AI coding agent to add an optional delivery_note field to an existing order API. It modifies the request schema, updates the database model, and reports that the task is complete. You review the changes and discover that clients can submit the field, but the API doesn't return it when retrieving an order.

Your first reaction is probably to rewrite the prompt. You explain the requirement again, add more details, and ask the agent to fix it.

Sometimes that works. Sometimes the agent makes another mistake, and you end up spending more time supervising it than writing the code yourself.

The problem might be your instructions. It might also be that the agent never received the relevant implementation details, or that its execution workflow doesn't verify the changes properly.

These are three different problems. They belong to three different layers of agentic engineering: prompt engineering, context engineering, and harness engineering.

Understanding where one ends and another begins makes a practical difference. It helps you decide what to fix instead of repeatedly changing prompts and hoping for better results.

Three layers, three responsibilities

The three terms describe different parts of how we work with language models. They aren't competing approaches, and one hasn't made the others obsolete.

1. Prompt engineering: What are you asking?

Prompt engineering is the practice of writing and organizing instructions so a model understands the task and produces the expected result.

A prompt describes the objective, constraints, expected behavior, and sometimes examples of what a successful output looks like.

Consider this request:

Add a delivery note field to the order API.

It's understandable, but it leaves several things open. Should the field be optional? Should it be stored in the database? Should it appear in API responses? What happens when an existing client doesn't provide it?

The model has to make assumptions about those details.

A more useful instruction would be:

Add an optional delivery_note field to the order creation API.

Requirements:

  • Accept the field when creating an order.
  • Persist its value with the order.
  • Include it in order retrieval responses.
  • Allow existing clients to omit the field.
  • Reject values longer than 300 characters.
  • Add tests covering these cases.

Don't change the existing order creation behavior beyond what's required for this feature.

The difference isn't the length of the prompt. It's the clarity of the requirements.

Good prompt engineering reduces ambiguity. It gives the model a defined task and a way to judge whether the result meets your expectations.

Prompt engineering still matters in agentic workflows. An agent might read hundreds of files, call multiple tools, and execute several steps, but it still needs to understand what you're asking it to accomplish.

Typical prompt failure: The model produces something different from what you intended because the instructions were incomplete, ambiguous, or contradictory.

What to improve first: Write explicit acceptance criteria. Describe what the finished implementation must do, not just the general direction of the work.

2. Context engineering: What does the model know?

A clear prompt doesn't guarantee a correct implementation.

Your model might understand exactly what you want but lack the information needed to implement it properly.

This is where context engineering comes in.

Context engineering is the practice of selecting, organizing, and maintaining the information available to a model when it makes a decision.

That information is broader than the user's latest message. Depending on the agent and the current step, it can include:

  • System and developer instructions.
  • The conversation history.
  • Repository instructions such as AGENTS.md.
  • Relevant source files and configuration.
  • Architecture documentation and API contracts.
  • Retrieved information from external systems.
  • Results returned by previous tool calls.
  • Summaries of earlier work.

All of this contributes to the context available to the model.

Anthropic's September 2025 engineering article, Effective context engineering for AI agents, describes context engineering as a natural progression from prompt engineering. The focus shifts from writing a good instruction to deciding what information should accompany that instruction.

There's a practical reason for this shift.

Imagine asking an agent to modify an existing payment service. You explain the feature perfectly, but the agent doesn't know how transactions are handled, which database repository is responsible for persistence, or which architectural rules the project follows.

The agent may still produce technically valid code. It simply won't fit the existing system.

Giving it the entire repository isn't necessarily the answer either. Context windows have limits, and irrelevant information competes with the details the model actually needs.

The goal is to provide relevant information at the right time.

For example, a coding agent might start with a repository map, inspect the API controller, follow the existing order creation flow, and then retrieve the relevant database and serialization logic. It doesn't need to load every file before starting.

Context also changes during execution. A test failure produces new information. A tool call returns output. A previous implementation decision becomes relevant to the next step.

The agent needs access to the information that matters at each stage, not just a large collection of files at the beginning.

Typical context failure: The model understands the task but makes incorrect assumptions because relevant implementation details, documentation, or previous decisions aren't available.

What to improve first: Inspect what information the model actually receives. Give it a repository map, relevant project instructions, and a reliable way to discover the source files it needs.

3. Harness engineering: How does the agent operate?

Now consider a different situation.

Your prompt is clear. The agent has access to the relevant source files, understands the architecture, and knows what needs to change.

But it still produces incomplete work.

Perhaps it can't execute the test suite. Perhaps it loses track of previous changes after a long session. Perhaps it repeatedly calls a failing tool without recovering. Or it reports success without verifying the implementation.

These problems go beyond prompts and context.

An agent harness is the software system surrounding a language model that allows it to perform tasks through tools, execution loops, state management, permissions, and feedback mechanisms.

Harness engineering is the work of designing and improving that system.

A coding agent isn't simply a model receiving one instruction and returning one answer. It typically operates through an execution loop:

  1. The model receives instructions and relevant context.
  2. It decides what action to take.
  3. It requests a tool call, such as reading a file or executing a command.
  4. The harness executes the requested action and returns the result.
  5. The model uses that result to decide what to do next.
  6. The process continues until the task is complete or the agent stops.

The harness controls much of what happens around this loop.

It determines which tools are available, how commands are executed, what permissions apply, how state is maintained, and how errors are returned to the model.

It can also manage context retrieval, memory, retries, and automated verification.

Consider an agent that modifies a Python application. It should be able to inspect files, edit code, run relevant tests, receive test failures, and make corrections.

Without that feedback loop, the agent might produce code that looks correct but has never been tested.

OpenAI's February 2026 article, Harness engineering: Leveraging Codex in an agent-first world, provides an interesting example of this broader approach. The team describes using repository documentation, architectural constraints, automated checks, and development infrastructure to make an agent-first workflow practical.

Cursor's engineering team makes another useful point in its article on continually improving its agent harness. Improving an agent isn't necessarily about changing the underlying model. The surrounding system also needs continuous evaluation and improvement.

This is why I consider the harness particularly important when moving from occasional AI assistance to autonomous coding workflows.

A single model response has limited operational requirements. An agent working through a large codebase over several hours needs a much more capable environment.

Typical harness failure: The model has the right instructions and information, but the surrounding system doesn't allow it to execute, recover, verify, or complete the task reliably.

What to improve first: Examine the execution loop. Make sure the agent can use the required tools, receive their results, run relevant checks, and respond to failures.

How the three layers fit together

The relationship is easier to understand when you look at their scope.

I find this mental model useful:

┌──────────────────────────────────────────────┐
│                  HARNESS                     │
│                                              │
│  ┌────────────────────────────────────────┐  │
│  │                CONTEXT                 │  │
│  │                                        │  │
│  │  ┌──────────────────────────────────┐  │  │
│  │  │              PROMPT              │  │  │
│  │  │                                  │  │  │
│  │  │       What should I do?          │  │  │
│  │  └──────────────────────────────────┘  │  │
│  │                                        │  │
│  │      What information do I need?      │  │
│  └────────────────────────────────────────┘  │
│                                              │
│       How does the agent operate?            │
└──────────────────────────────────────────────┘

In shorthand:

Prompt ⊂ Context ⊂ Harness

The prompt is part of the context supplied to the model. Context is assembled and managed by the surrounding agent system. The harness includes that context-management process along with the tools, execution environment, permissions, memory, and feedback mechanisms.

There's one technical distinction worth keeping in mind.

The entire harness doesn't sit inside the model's context window. The model might receive a tool description, but the actual tool implementation executes outside the model. Similarly, sandbox enforcement and permission checks happen in the surrounding system, not simply because the model was instructed to follow them.

This nesting is a conceptual model of responsibility, not a literal description of runtime architecture.

The terminology is also still evolving. Anthropic describes context engineering as a progression from prompt engineering, while discussions of harness engineering often include parts of context management. Birgitta Böckeler's Harness engineering for coding agent users explores these overlapping boundaries.

I wouldn't treat any single definition as an official industry standard. The useful distinction is what each layer is responsible for.

One task, three different failures

Let's return to the order API example and follow the same task through all three layers.

Assume the requirement is to add an optional delivery_note field to an existing order API. The field must be persisted, returned when retrieving an order, and remain optional for existing clients.

First failure: The prompt is incomplete

You ask the agent:

Add delivery note support to the order API.

The agent adds the field to the request DTO and updates the database model. However, it doesn't modify the response serializer.

The implementation is incomplete, but the agent hasn't necessarily misunderstood the instruction. You never explicitly said the field must appear in order retrieval responses.

Diagnosis: Prompt problem.

Fix: Clarify the acceptance criteria. Explicitly mention persistence, retrieval, optional behavior, and required tests.

There's no reason to change the agent's architecture or introduce a more complicated context retrieval system yet.

Second failure: The context is incomplete

Now the prompt is clear. You explicitly describe the expected behavior.

However, the agent only inspects the order controller and request DTO. It doesn't discover how the application maps database entities to API responses.

It implements the field in the places it knows about, but misses the existing serialization pattern.

The instruction wasn't the problem. The agent lacked relevant information about the codebase.

Diagnosis: Context problem.

Fix: Give the agent a way to discover the complete implementation path. It should inspect the existing order model, persistence logic, response mapping, API contract, and related tests.

You could improve the repository's AGENTS.md file with a short architectural map and instructions about where to find those components.

The important point is that the model needs the relevant files and project conventions when making the implementation decisions.

Third failure: The harness is incomplete

This time, the agent receives the correct instructions and discovers all the relevant files.

It updates the database model, migration, request handling, and response serialization.

But the task is still incomplete because the harness doesn't provide a working test execution workflow. The agent can't reliably run the relevant integration tests, or its execution loop doesn't require test results before declaring the task finished.

The code looks reasonable, but there's no evidence that the implementation works.

Adding another paragraph to the prompt won't fix a missing execution or verification mechanism.

Diagnosis: Harness problem.

Fix: Make the relevant test command available through the agent's tools. Ensure its output is returned to the model, and require successful verification or an explicit report of anything it couldn't verify.

Now the agent has a way to detect implementation problems and respond to them.

The important distinction is that we're addressing three different causes of an incomplete result. The visible symptom might be identical, but the engineering fix isn't.

A practical way to diagnose agent failures

When an AI coding agent produces a bad result, resist the temptation to immediately rewrite the prompt.

Start by identifying where the failure occurred.

What you observe Likely problem What to investigate first
The agent misunderstands the requirement. Prompt Instructions, constraints, acceptance criteria
The agent makes incorrect assumptions about the project. Context Files, documentation, repository instructions, previous tool results
The agent gets stuck, repeats failed actions, or skips verification. Harness Tool execution, permissions, state management, feedback loop

These categories aren't mutually exclusive. A poorly designed harness can produce incomplete context. An ambiguous prompt can also cause an agent to retrieve the wrong information.

Still, the distinction gives you a useful starting point.

For a prompt problem, compare the requested behavior with the actual implementation. Find the missing requirement and make it explicit.

For a context problem, inspect the information available to the model when it made the incorrect decision. Don't assume that a file being present in the repository means the model has actually read it.

For a harness problem, inspect the execution trace. Were tool calls successful? Did the agent receive the returned output? Did tests run? Could the agent recover from an error? Was there a clear stopping condition?

One particularly useful practice is to keep records of recurring failures. If the same issue appears across multiple tasks, there's probably a structural problem worth fixing.

Don't introduce permanent infrastructure to solve a one-off mistake. Look for patterns first.

Where should you invest first?

The three layers aren't a ranking of old and new engineering skills.

Prompt engineering didn't become obsolete. It became the innermost layer of a broader system.

For a simple task, a well-written prompt might be all you need. For work involving multiple files, project conventions, and several implementation decisions, context engineering becomes increasingly important. When an agent needs to operate autonomously, run tools, recover from failures, and work across multiple sessions, the harness deserves more attention.

I'd approach improvements in this order:

At the prompt layer: Start writing acceptance criteria instead of relying on broad task descriptions. Be explicit about expected behavior and what shouldn't change.

At the context layer: Create a useful repository map. Document architectural conventions and give the agent reliable tools to discover relevant files. Avoid loading large amounts of unrelated information.

At the harness layer: Make verification part of the execution workflow. Give the agent access to the appropriate tests, return meaningful errors, and establish clear conditions for completing a task.

You don't need to build a sophisticated agent framework to start benefiting from these ideas. Even a small coding-agent setup with repository instructions, file-reading tools, controlled command execution, and a test feedback loop already addresses responsibilities across all three layers.

The next time your coding agent produces an incomplete implementation, look beyond the prompt. Check what you asked, what the model knew, and what the surrounding system allowed it to do. Fix the layer responsible for the failure.

Share this guide:

Related Guides & Articles