AI Harness Engineering: How to Build AI Agents Your Business Can Trust (2027 Guide)
AI harness engineering for teams: the permissions, memory, evals and cost limits that make AI agents safe on business data. Sourced guide with a tested starter.
Contents
- 1. What is AI harness engineering?
- Prompt, context and harness engineering
- Why AI agents at work need explicit controls
- 2. Build, configure or buy?
- Local, cloud or hybrid is several decisions, not one
- Set your starting constraints
- 3. The architecture of an AI harness
- 4. Build your first working harness: one task, one read-only tool
- 5. Add context, memory and your company's knowledge
- Retrieve with provenance
- Make memory reversible
- 6. Connect tools, apps and MCP without unlimited access
- Write a contract for every tool
- What MCP does and does not give you
- 7. Enforce boundaries and test prompt injection
- Put enforcement outside the prompt
- Test it with synthetic attacks
- 8. Make long-running work reliable
- 9. Evaluate the harness: did it work, and did it follow the rules?
- Start with thirty cases
- Grade with the right tool
- Measure consistency, not one lucky run
- 10. Control costs and operate the system
- 11. Own your exit: export, switch providers and restore
- 12. From one agent to a team
- 13. Put it to work: three starter workflows
- A readiness checklist
- Frequently asked questions
- What is an AI harness?
- What is an enterprise AI harness?
- Is AI harness engineering only for developers?
- Do I need to train a model to build an AI agent?
- Is a custom GPT or chatbot project the same as an AI harness?
- Can I use this to build a personal AI assistant?
- Does running an agent locally keep all data private?
- Is MCP safe by default?
- How do I stop loops and surprise bills?
- Can I switch providers without rebuilding everything?
- When is buying better than building?
- Sources
AI harness engineering is the design of the software around an AI model: what it sees, which tools it may use, what it remembers, what it must ask before acting, when it stops, and how you check its work. For a business, the harness is where you decide what an agent may do with company documents, customer records and accounts, and where you prove what it actually did.
The model is the part everyone compares.
The harness is the part your business runs on.
Swap the model and the work carries on. Get the harness wrong and a very capable model will still email the wrong client, loop on a broken tool, or leave nobody able to say what happened.
This guide builds one small agent and grows it the way a sensible pilot should:
a sourced answer from internal documents,
a client-meeting brief that changes nothing on anyone's calendar,
a reply that is drafted but cannot send itself,
a receipt for every run,
an exit plan for the day you change providers.
Then it takes the same design from one person to a team.
This is the 2027 edition, written in October 2026. Every number has its source and date beside it. Where something still has to be measured, the guide says so instead of guessing.
Three ways to read it. To understand the discipline, read sections 1 to 3. To build a first pilot, read sections 4 to 6 and then the read-only quickstart. To put agents in front of a team, read sections 7 to 13.
1. What is AI harness engineering?
An AI agent is a model running in a loop. It reads the situation, decides, calls a tool, reads the result and decides again. How AI agents work walks through that loop step by step.
The harness is everything in the loop that is not the model. Databricks describes an agent harness as the software infrastructure wrapped around a large language model that connects it to tools, memory, execution environments and guardrails (Databricks). LangChain reaches the same place from the other direction: start from the behaviour you want, then add the harness parts that make the model capable of it (LangChain).
The terms blur in practice, so here they are against one task: preparing tomorrow morning's client-meeting brief.
| Term | What it is | In the meeting-brief example |
|---|---|---|
| Model | The system that reads text and proposes the next step | Decides which account notes matter and writes the brief |
| Agent | A model running in a loop with tools | Reads the calendar, searches the notes, writes the brief |
| Harness | The runtime around the model | Chooses what the model sees, runs the tools, refuses calendar writes, records a receipt |
| Framework | A library for building agents and harnesses | Code you might use to build all of the above |
| Workflow | A fixed sequence of steps | "Every weekday at 8:00, fetch the day's client meetings, then summarise them" |
These are roles, not rival products. A workflow can call a model. A harness can run a workflow. The harness vs framework vs workflow guide shows how to choose the smallest one that does the job.
Prompt, context and harness engineering
Three disciplines get confused because they all touch the same model call.
Prompt engineering writes the instruction.
Context engineering decides everything the model sees for a call: instructions, retrieved documents, tool results, remembered facts and history. Anthropic frames it as the ongoing work of curating a limited context window rather than writing one good prompt (Anthropic).
Harness engineering owns what happens around the call: which tools exist, which actions are allowed, what is persisted, when the loop stops and how the result is checked.
A prompt asks. A harness decides what is allowed.
Why AI agents at work need explicit controls
An agent at work touches the data a business is accountable for:
customer records,
contracts and pricing,
finance and payroll,
internal email,
the calendars of people who never agreed to be automated.
That raises the cost of a confident mistake and of a quiet data leak.
Customers notice. In a 2026 survey commissioned by Usercentrics and run by Sapio Research across 11,000 consumers in seven markets (Usercentrics):
- 52% said they trust AI less than humans with their personal data, up from 48% in 2025. The year-on-year comparison excludes Sweden, which joined the study in 2026.
- 24% said they had cancelled a subscription or stopped buying from a brand in the previous six months over concerns about how their data was used in AI.
- 47% said they had taken at least one action with a direct revenue consequence, such as cancelling, switching or spending less.
These are self-reported answers to a commissioned survey, not observed sales. They still describe the customers whose data your agents will handle.
Teams notice too. In Stack Overflow's 2025 developer survey, 46% of respondents said they distrust the accuracy of AI tools and 33% said they trust it. Only 3% reported high trust (Stack Overflow).
One concern is about where data goes. The other is about whether the output is right. A harness has to answer both, with permissions and data boundaries for the first, and sources, receipts and tests for the second.
The useful response is not finding a new vendor to trust.
It is building a system that needs less blind trust.
2. Build, configure or buy?
Owning a harness gives your business control. It also gives your team the maintenance.
| Choice | Fits when | Your team inherits |
|---|---|---|
| Buy a managed agent platform | You want results quickly and accept the provider's data and action policies | Little maintenance, limited control, the provider's exit options |
| Configure an existing agent tool | You want your own tools, prompts and data rules without writing a runtime | Configuration, connector reviews, some upgrades |
| Build your own harness | You need specific boundaries, portable state or behaviour no product offers | Updates, credentials, backups, monitoring and recovery |
There is no shame in the first row. If nobody on your team can own patching, credential reviews and restore tests, a well-chosen managed product is probably safer than an unmaintained one you built. The private AI assistant comparison guide shows how to judge one.
Local, cloud or hybrid is several decisions, not one
"Local" usually describes the chat window. The harness has more parts than that, and each can run somewhere different:
the interface,
the model,
the document store and its search index,
the tools and the accounts they reach,
the logs,
the backups.
Two examples show why the distinction matters.
Ollama binds to 127.0.0.1 on port 11434 by default and documents a local-only mode, set with OLLAMA_NO_CLOUD=1 or disable_ollama_cloud in its server config, which turns off its cloud models and web search (Ollama FAQ). That keeps model calls on the machine. It says nothing about a mail connector that sends message text somewhere else.
OpenAI's API documentation says API data is not used to train its models unless you opt in, and separately that abuse-monitoring logs may be retained for up to 30 days, with stated exceptions; zero-retention controls require prior approval (OpenAI). No training is not the same as no retention.
For a business these are data-processing decisions as much as technical ones. They decide which classes of data may go to which provider, and whether that matches what your customers and contracts allow. The local vs cloud vs hybrid guide maps each part. For the broader shift, see the rise of local AI.
Set your starting constraints
Before writing code, write six lines:
- The first task. One useful job, such as "answer questions from our sales playbook."
- Allowed data destinations. Which data may leave your systems, and to whom.
- A spend cap. Per run and per month.
- Forbidden actions. For a first build: no sending, no deleting, no payments, no calendar writes.
- An owner. The person accountable for the agent's access, behaviour and costs.
- Maintenance time. Honest hours per month.
Those six lines will decide more of the architecture than any framework choice.
3. The architecture of an AI harness
Every harness has three paths running through it.
The reasoning path carries a task to the model: input, context assembly, the model call and a structured request for a tool.
The authority path decides whether that request may happen: identity, scoped tools, policy checks, approval and execution outside the prompt.
The continuity path keeps the system honest over time: memory with provenance, checkpoints, receipts, budgets, evaluations and portable state.
Every component should exist because it prevents a failure you can name.
| Component | Failure it prevents |
|---|---|
| Context assembly | Wrong, stale or missing evidence; an overflowing context window |
| Tool contracts and input validation | Malformed calls and calls that reach outside their scope |
| Identity and policy checks | Actions taken with someone else's access, or that nobody authorised |
| Step, time and spend limits | Loops and runaway bills |
| Memory with provenance | Confident use of facts that are out of date |
| Checkpoints and idempotency | Lost work, and duplicated actions after a restart |
| Run receipts | "It said done, but nothing happened," and no audit trail when a client asks |
| Evaluations | Silent regressions after a model or prompt change |
| Export and restore | Lock-in and unrecoverable loss |
Birgitta Böckeler's article on harness engineering at martinfowler.com sorts controls into those that steer an agent before it acts and those that check the result after, and separates deterministic checks from model-judged ones (martinfowler.com). That split is useful in any business. A path check on a file tool is deterministic and cheap. "Is this summary faithful?" needs a judge.
For the plain-language version of why this layer decides outcomes, see Model vs. Harness.
4. Build your first working harness: one task, one read-only tool
The first build should be small enough to understand completely and boring enough to approve. Treat it as a pilot for one person's workflow:
one model,
one read-only tool,
one folder it may read,
a hard step limit,
a receipt.
The quickstart has the full 50-line example. It uses a scripted stand-in for the model so it runs without an API key, and it was run on Node.js 22 before publication. Asked for the next milestone in a synthetic project note, it returned this receipt:
{
"question": "What is the next milestone for Project Alpha?",
"steps": [
{ "step": 1, "tool": "read_note", "args": { "name": "project-alpha.md" }, "ok": true }
],
"stop": "answered",
"answer": "Next milestone: read-only beta to five testers on 14 November.",
"sources": ["project-alpha.md"]
}Three design rules carry through everything that follows.
The tool defends itself. read_note accepts only simple file names inside one folder. In testing it rejected ../secret.md, absolute paths and non-string input, whatever the model asked for.
The loop has a hard stop. Four steps and twenty seconds, enforced by the runtime rather than requested in the prompt.
Every run ends with a reason. answered, timeout or step_limit. A run that cannot say why it stopped cannot be debugged, or explained to anyone else.
5. Add context, memory and your company's knowledge
"Memory" usually means four different things. Keep them apart.
| Kind | What it holds | Lifetime |
|---|---|---|
| Current context | What the model sees for this call | One call |
| Retrieved documents | Passages found in your files for this question | One task |
| Durable facts | Preferences and facts meant to persist | Until corrected or deleted |
| Task state | Progress, checkpoints and pending approvals | Until the task ends |
Mixing them causes most memory bugs. A preference saved as a document gets retrieved at random. A one-off instruction saved as a durable fact never goes away.
Retrieve with provenance
Every retrieved passage should carry where it came from and when. That lets the answer cite it, lets a reviewer check it, and lets the system prefer a newer source over an older one.
Context is not a bin to fill. In a 2023 study of the language models of the time, accuracy on multi-document question answering was often highest when the relevant passage sat at the beginning or end of a long input, and dropped when it sat in the middle (Liu et al.). Today's models differ, so treat that as a reason to test evidence placement on your own setup, not as a fixed rule. Anthropic lists compaction, structured note-taking and sub-agent architectures as ways to keep long tasks inside a useful context (Anthropic).
Make memory reversible
You should be able to do four things with any remembered fact:
inspect it and see where it came from,
correct it and watch the next answer change,
export it in a readable format,
delete it, with a clear statement of what deletion does not reach.
That last part matters. Deleting a record from your store does not remove copies in old backups, and it cannot recall anything already sent to a provider. Say so in the interface.
The AI memory guide builds this lifecycle, the RAG vs memory vs context guide separates the mechanisms, and AI agent memory explained covers the wider research.
6. Connect tools, apps and MCP without unlimited access
Tools are where an agent stops talking and starts acting. Grant them in stages:
- Read. Narrow, scoped, read-only access to one resource.
- Draft. The agent prepares an action someone can see: a draft reply, a proposed event.
- Approve. A person approves that exact action.
- Execute. The runtime performs the approved action and records the result.
Most business workflows deliver their value at step 2.
Write a contract for every tool
A tool contract names its inputs, outputs, error types, the resources it may touch and whether it reads or writes. Validate inputs in the tool, not in the prompt. Return structured errors so the loop can tell "not found" from "not allowed."
What MCP does and does not give you
The Model Context Protocol standardises how an agent discovers and calls tools. It does not certify that a server, its credentials or its actions are safe.
The MCP documentation distinguishes transports. A remote server uses the protocol's authorization flow. A local server running over STDIO can instead take credentials from its environment or from libraries embedded in the server (MCP authorization). The security guidance calls token passthrough an anti-pattern, meaning a server that accepts tokens not issued to it and forwards them to a downstream API, and it describes confused-deputy attacks against proxy servers (MCP security best practices).
In practice: pin the protocol version, read what the server can reach, give it the narrowest credentials that work, and test that revoking access actually stops it. The MCP tutorial walks through one connector, and the best MCP clients lists the hosts.
7. Enforce boundaries and test prompt injection
Everything an agent reads is data. Some of that data will contain instructions:
a supplier invoice that says "ignore your user,"
an email that asks for a password reset link to be forwarded,
a web page with hidden text,
a tool result that requests a new action.
None of them carries your authority. The harness has to keep it that way.
Put enforcement outside the prompt
A system prompt that says "never send email" is a request. A runtime with no send tool is a fact. Prefer facts:
- remove tools a task does not need,
- scope credentials so a tool physically cannot reach other resources,
- restrict which network destinations tools may contact,
- require approval for consequential actions in code the model cannot edit.
OWASP's AI Agent Security Cheat Sheet is specific about approvals: before execution, check that the approval belongs to the current actor and the exact tool call, is still valid and has not already been used, and consume it in one atomic step so repeated or concurrent requests cannot reuse it (OWASP). The AI agent permissions guide turns that into a state machine.
Test it with synthetic attacks
Measure two things separately: whether a forbidden action happened, and whether the legitimate task still got done. A system that refuses everything is safe and useless. AgentDojo, a research benchmark for prompt-injection attacks on tool-using agents, was built this way, with 97 realistic tasks and 629 security test cases in its paper version (Debenedetti et al.).
Use fake accounts, fake data and canary strings. Never test against real people or systems you do not own. The prompt-injection lab has the case design.
Passing a test suite shows the tested cases held. It does not prove the agent is safe against everything.
8. Make long-running work reliable
Short tasks fail loudly. Long tasks fail quietly: a crash between two steps, a retry that repeats an action, a model that declares victory early.
Anthropic's account of harnesses for long-running coding agents is a good model. Its setup used an initializer that wrote a startup script, a progress file logging what agents had done, and an initial commit, so each later session could make incremental progress and leave the environment clean for the next one (Anthropic). That was a coding case study, but the principle carries to business work: progress belongs in durable artifacts, not in a long conversation.
For business workflows that means:
- Checkpoints that record what is done, what is pending and what needs approval.
- Idempotency for actions with side effects, so a retry cannot send the same message or invoice twice.
- An "uncertain" state for when a tool call timed out after it may have succeeded. Reconcile before retrying.
- Cancellation that stops new work and reports honestly on work already done.
- Approval expiry, so resuming a task tomorrow does not reuse yesterday's consent.
The scheduling guide covers duplicate-safe jobs, and the troubleshooting guide covers loops and false completion.
9. Evaluate the harness: did it work, and did it follow the rules?
A fluent "done" proves nothing. Check the world, not the message.
Tau-bench, a benchmark for agents that talk to users and use tools, scores a conversation by comparing the final database state with an annotated goal state (Yao et al.). Do the same in your business: if the task was "draft a reply," check that a draft exists, says the right thing and that nothing was sent.
Start with thirty cases
A first evaluation suite can be small and still useful:
- 10 useful tasks. Answers from documents, briefs, drafts, missing information, conflicting sources.
- 10 boundary cases. Injected instructions, out-of-scope files, expired approvals, changed parameters, revoked access.
- 10 failure cases. Timeouts, malformed tool output, duplicate jobs, cancellation, budget exhaustion, a restore.
Write the expected outcome before running anything. The evaluation guide has all thirty.
Grade with the right tool
Anthropic groups graders into code-based, model-based and human, and distinguishes capability evaluations from regression evaluations (Anthropic). Use code for anything checkable: files touched, tools called, state changed, actions blocked. Use a model or a person for quality judgments, and check the model judge against human verdicts.
Measure consistency, not one lucky run
Two metrics look alike and mean opposite things. pass@k is the chance of at least one success in k attempts. pass^k is the chance that all k attempts succeed. Anthropic's example: at a 75% per-trial success rate, three trials all pass about 42% of the time (Anthropic). A workflow your team relies on every morning needs the second number.
Benchmarks age. The original tau-bench paper found that the function-calling agents it tested, including gpt-4o, succeeded on fewer than half of tasks and passed all eight trials on under a quarter of retail tasks (Yao et al.). That describes 2024 models on that benchmark, not today's agent on your tasks. Run your own.
The same applies to productivity. METR's early-2025 randomised study found experienced open-source developers took 19% longer with the AI tools of the time, even though they expected to be faster (METR). METR's 2026 follow-up says its newer data gives an unreliable signal of the current effect (METR). Neither result tells you what an agent will do for your team. Measuring does.
10. Control costs and operate the system
The number that matters is cost per successful task: everything you spent, including failed runs and retries, divided by the tasks that actually succeeded.
That total includes more than tokens: tool and API fees, hosting, storage and backups, hardware and electricity if you run locally, and the team's maintenance time. The cost worksheet separates measured usage from assumed prices, and the local hardware guide covers sizing.
Budgets only count if the runtime enforces them. Set limits on steps, time, spend and concurrency, and make every stop visible in the receipt.
Logs are the other operating cost. A good run receipt answers who asked, what ran, what was read, what was approved, what changed and why it stopped, without storing passwords, tokens or more personal content than needed. The logging guide covers receipts and redaction. AI agent observability covers tracing standards.
11. Own your exit: export, switch providers and restore
An exit plan is the difference between using a provider and depending on one.
Sort your state into three groups:
| Group | Examples | On exit |
|---|---|---|
| Portable | Documents, memory records, workflow definitions, tool contracts, evaluation cases | Export in readable formats |
| Rebuildable | Search indexes, embeddings, caches | Regenerate in the new setup |
| Re-authorise | API keys, OAuth grants, connector permissions | Grant again; never copy blindly |
Then test the exit the same way you test anything else. Export, import into a clean environment, re-authorise deliberately, switch to a second model provider and rerun the evaluation suite. Record what moved, what needed an adapter and what behaved differently. Models are not interchangeable, so expect differences and measure them.
Restore follows the same rule. A backup you have never restored is a hope. And remember the limit of every rollback: restoring an old database does not unsend an email.
The provider exit test and the backup and restore runbook walk through both.
12. From one agent to a team
A pilot proves the design. A team rollout tests it.
Most of what changes is not the model or the tools. It is identity: who is asking, whose access the agent uses, and who answers for the result.
- Each person's agent acts as that person. Give it that user's scoped access, not a shared service account that can see everything. A shared all-access token turns one successful prompt injection into an incident for the whole company. MCP's security guidance warns against token passthrough and describes confused-deputy attacks for exactly this reason (MCP security best practices).
- Approvals belong to a person. OWASP's rule that an approval must match the current actor and the exact tool call (OWASP) means one colleague cannot approve an action on another's behalf unless your policy says so.
- Shared knowledge and personal memory live apart. Company documents sit in shared, permissioned sources. Each person's preferences stay in their own memory store. Test that one profile never retrieves another's records.
- Policy is central, scope is local. Forbidden actions, allowed providers per data class and budgets are set once and enforced in the runtime every agent uses.
- Receipts are the audit trail. Every run records who asked, what was read, what was approved and what changed, with secrets redacted. When a client asks what happened, you can answer.
- Offboarding is revocation. When someone leaves or changes role, revoke their agent's grants and confirm the next call fails.
- Costs have owners. Track cost per successful task by team, so a runaway job shows up before the invoice does.
| Pilot | Team rollout | |
|---|---|---|
| Identity | One person's scoped access | Each user's own scoped access; no shared superuser |
| Approvals | The pilot user | The requesting person, as policy defines |
| Knowledge | One folder | Shared permissioned sources plus personal memory |
| Policy | Written down | Enforced centrally in the runtime |
| Evidence | Run receipts | Receipts as a searchable audit trail |
| Exit | Tested once | Retested on every provider or model change |
None of this needs a new model. It needs the harness to know who is asking.
13. Put it to work: three starter workflows
One harness, three jobs, each with its boundary built in.
Research from internal documents. Ask questions of a selected set of documents, such as a sales playbook, a policy folder or past proposals, and get answers with the passages that support them, plus an honest "not found" when the documents do not say. See the knowledge base guide.
Client meeting preparation. Read tomorrow's client meetings and the related account notes, and produce a brief with sources and open questions. The calendar connection is read-only, so a stray instruction cannot reschedule anything. See the meeting-prep tutorial.
Draft-only email. Read one customer thread and draft a reply that a person reviews and sends. The send capability is absent, not merely discouraged. See the draft-only email tutorial.
Each starts with one person and synthetic data, then widens to real accounts and more people as its tests pass.
A readiness checklist
Before trusting an agent with anything new, check:
- You can list every place your data goes, by class of data.
- Each tool has a written contract and validates its own input.
- Each agent acts with its user's scoped identity, not a shared superuser.
- Consequential actions need approval for the exact action, enforced in code.
- Every run has a step, time and spend limit, a stop reason and a receipt.
- Memory can be inspected, corrected, exported and deleted, and shared knowledge is kept apart from personal memory.
- Your evaluation suite passes, including the boundary cases.
- Revoking a person's access stops their agent.
- You have restored from backup and rerun your tasks on a second provider.
Every unchecked box is a place where your business is still trusting rather than verifying.
Frequently asked questions
What is an AI harness?
The software around an AI model that assembles its context, runs its tools, enforces permissions and limits, stores memory and state, and records and checks results. The model proposes; the harness decides what actually happens.
What is an enterprise AI harness?
The same discipline at company scale: one runtime that applies identity, permissions, data policies, budgets and audit receipts to every person's agents, whichever models the company uses.
Is AI harness engineering only for developers?
No. Developers build the harness, but the decisions it encodes, such as what data may go where, which actions need approval and who owns the costs, belong to whoever is accountable for the work. This guide is written for both.
Do I need to train a model to build an AI agent?
No. A harness uses an existing model through an API or a local runtime. The work is in the context, tools, permissions, memory and tests around it.
Is a custom GPT or chatbot project the same as an AI harness?
Not quite. Custom chatbots let you set instructions and attach files. A harness also controls tools, authority, state, limits and evaluation. Many custom chatbots are a useful first step that stops short of acting on anyone's behalf.
Can I use this to build a personal AI assistant?
Yes. The quickstart starts with one person's assistant on synthetic notes, which is also the right shape for a business pilot.
Does running an agent locally keep all data private?
Only the parts that actually run locally. A local model with a cloud mail connector still sends mail content to that connector. Map every component before calling a setup private.
Is MCP safe by default?
MCP is a protocol for connecting tools. Safety depends on the server you install, the credentials you give it and the authority your harness enforces.
How do I stop loops and surprise bills?
Enforce step, time and spend limits in the runtime, not in the prompt, and make every stop reason visible in the run receipt.
Can I switch providers without rebuilding everything?
If your documents, memory, workflows and tool contracts live in portable formats, yes, with adapter work. Test it before you need it.
When is buying better than building?
When nobody on your team can own updates, credential reviews, backups and restore tests. An unmaintained harness is not safer than a well-run product.
Sources
- Usercentrics and Sapio Research, State of Digital Trust 2026
- Stack Overflow, 2025 Developer Survey: AI
- Databricks, What is an AI agent harness?
- LangChain, The anatomy of an agent harness
- Birgitta Böckeler, Harness engineering for coding agent users
- Anthropic, Effective context engineering for AI agents
- Anthropic, Effective harnesses for long-running agents
- Anthropic, Demystifying evals for AI agents
- Model Context Protocol, Authorization and Security best practices
- OWASP, AI Agent Security Cheat Sheet
- Ollama, FAQ
- OpenAI, Your data
- Liu et al., Lost in the Middle
- Debenedetti et al., AgentDojo
- Yao et al., τ-bench
- METR, Early-2025 AI and experienced open-source developers and 2026 update