What Is an AI Agent Harness? A 2026 Masterclass on Context and Long-Running Agents

Artificial Intelligence • Published Date: October 16, 2026 Last updated: October 16, 2026

Most AI agents fail not because of the model but because of the harness around it, the layer that manages context, tool access, evaluation, token budgets and human review. This masterclass walks through the six components of a reliable harness, compares frameworks like the Claude Agent SDK, LangGraph and the OpenAI Agents SDK, and shares a real quoting-agent case study that cut quote time from 5 to 7 hours to under 45 minutes.

Make Your AI Agents Production-Ready

Get a harness with budgets, evaluation, and review gates.

Get Started

What is an AI agent? An AI agent is a software system that uses a language model to plan, call tools and act toward a goal with limited human input. In my experience the model alone never makes a reliable agent. The harness around it does. Most teams ship the model, skip the harness, and then watch agents drift, loop and burn tokens on any task that runs past a few minutes.

The numbers back this up. Gartner (2025) predicts that over 40% of agentic AI projects will be canceled by the end of 2027 because of rising costs, unclear value or weak risk controls. All three of those are harness problems, not model problems. This masterclass walks through how I design the harness (context, evaluation, budgets, sandboxing and human review), compares the frameworks I would pick from today, and shares a case study from a quoting agent we shipped for an industrial supplier. If you want help taking agents to production, see tkxel's AI Agents practice.

  • Set a token budget, an iteration cap and a timeout per task before any coding agent runs.

  • Use a separate evaluator only when tests cannot verify the work. Anthropic's own full harness cost about 20x more than a solo agent.

  • Audit the evaluator monthly by seeding known defects. Out of the box, models are lenient graders.

  • Pick context resets or compaction based on how your model behaves near its limit, not by habit.

  • Put a sandbox and a human review gate between agent-written code and production.

  • Every harness part encodes an assumption about what the model cannot do. Re-test those assumptions when you upgrade models.

  • Expect the data, not the model, to be the hard part. In our RFQ agent, the real problems were a messy product master and knowledge that lived only in engineers' heads.

An agent harness is the runtime and rules wrapped around a model: context handling, tools, evaluation, budgets and safety gates. Put simply, the harness is everything except the model weights. Getting this layer right matters more each year: Gartner expects 33% of enterprise software applications to include agentic AI by 2028, up from less than 1% in 2024.

An AI agent is a model that decides its own next step, while the harness decides what that model can see, do and spend. The model reasons. The harness supplies memory, tools and rules.

Under the hood, an agent runs a loop: read context, pick an action, call a tool, read the result, repeat. A chatbot answers one prompt. An agent pursues a goal across many steps, sometimes hundreds.

A coding agent is an agent whose tools read repositories, edit files and run tests. An autonomous coding agent works for long stretches without a person approving each step.

That autonomy is growing fast. METR's research found the length of tasks frontier agents complete with 50% reliability has been doubling roughly every 7 months for six years. Longer tasks mean more context, more tool calls and more ways to fail. That is why harness design now matters more than model choice for most teams I work with.

Is Claude Code an agent harness? Yes. Claude Code wraps a model with tools, context handling and permissions for coding work. Anthropic exposes the same engine as the Claude Agent SDK, which its docs describe as giving you the same tools, agent loop and context management that power Claude Code. LangGraph, Deep Agents and the OpenAI Agents SDK give you building blocks to assemble your own.

I treat harness design as a product decision, not only an engineering one. UiPath CEO Daniel Dines puts it well: writing code is the easy part, and running it durably, safely and at enterprise scale is where trust is earned or lost. For the wider picture, see tkxel's guide to AI agents in software engineering.

The anatomy of an agent harness has six parts: context manager, generator, evaluator, tool sandbox, token budget and human review gate. Each part exists to stop one specific failure. Each part also costs money, so every component has to earn its place.

The anatomy of an agent harness: context manager, generator, evaluator, tool sandbox,

Component Failure it prevents What I put in it
Context manager Forgetting, drift, rushed endings Compaction or resets, handoff notes, progress files
Generator Unscoped work A narrow task, a spec and the fewest tools that work
Evaluator Self-praise of weak output Separate agent, explicit criteria, few-shot scored examples
Tool sandbox Damage to real systems Isolated container, allowlisted network and files, no prod secrets
Token budget Runaway cost from loops Token cap, iteration cap, wall-clock timeout
Human review gate Surprise merges and deploys Approval on merges, deploys and any irreversible action

Context management: what context engineering means

Anthropic defines context engineering as the set of strategies for curating and maintaining the best set of tokens during inference. The goal is the smallest set of high-signal tokens that gets the job done. More context is not better. Chroma's Context Rot study tested 18 models from Anthropic, OpenAI, Google and Alibaba and found performance gets less reliable as input length grows, even on simple tasks.

Context resets vs compaction

Context compaction vs context reset in an AI agent harness: compaction summarizes old

Compaction summarizes old turns in place and keeps going. A context reset clears the window and starts a fresh agent from a structured handoff note. Compaction keeps continuity but does not give the agent a clean slate. Resets give a clean slate but add orchestration, tokens and latency.

The right choice depends on the model. In Anthropic's harness design write-up (March 2026), Sonnet 4.5 showed "context anxiety": it started wrapping up early as it neared what it thought was its limit, so compaction alone was not enough and resets were needed. Opus 4.5 largely removed that behavior, and the team dropped resets.

My rule: use compaction by default, and switch to resets when you see the agent rushing, truncating work or forgetting earlier decisions. A good handoff note lists the goal, decisions made, files changed, open defects and the next step. I keep it under one page.

Progress files and structured notes

For multi-session work, Anthropic's long-running agents guide (November 2025) uses an initializer agent that sets up an initialization script, a progress log and a first git commit. A JSON feature list, over 200 features in their example, starts with every item marked failing. They chose JSON because the model is less likely to overwrite it than Markdown. Each later session picks one feature, tests it end to end, commits and updates the log. I copy this pattern almost directly.

The generator and the independent evaluator

An evaluator is a second agent that grades the generator's work against explicit criteria. Anthropic says plainly that, out of the box, Claude is a poor QA agent: it finds real issues and then talks itself into approving the work. Shiplight, a startup that builds QA tooling for AI coding agents, reports the same pattern and notes that tuning a standalone evaluator to be skeptical is far easier than making a generator critical of itself.

Anthropic fixed leniency with few-shot examples that include detailed score breakdowns, then several rounds of reading logs and tightening the QA prompt. Their evaluator used the Playwright MCP server to click through the running app, and generator and evaluator agreed a "sprint contract" of testable criteria before each sprint. One sprint had 27 criteria.

Without a token budget, multi-pass agent runs have no ceiling, and one stuck loop can eat a week of spend in an afternoon. Deloitte notes that token costs are shaped by a cascade of technical decisions, from compute to storage. In an agent harness, model choice, context size, retries and evaluator passes add to that bill.

Real data shows how fast this adds up. According to Anthropic's March 2026 harness design write-up, a solo agent built a retro game maker in 20 minutes for $9. Anthropic's full planner, generator and evaluator harness took 6 hours and cost $200. A later, simpler harness built a browser-based audio workstation in 3 hours 50 minutes for $124.70, with three QA passes costing just over $10 combined.

I set three limits on every run:

  1. A hard token cap per task.

  2. A maximum number of evaluator iterations.

  3. A wall-clock timeout.

I also log spend per run so finance sees cost per merged change, not a monthly surprise.

A generator-evaluator loop pays off when quality is subjective or errors are expensive. It is overkill when tests can verify the result. Anthropic's summary is the one I use: the evaluator is worth the cost when the task sits beyond what the current model does reliably on its own. Calibrated well, the evaluator does not have to be the expensive part: in Anthropic's audio workstation run, three QA passes cost $10.39 of a $124.70 total, about 8% of spend.

The table below uses planning ranges for a single mid-size task. These are planning assumptions, not benchmarks. Replace them with your own measurements.

Approach Extra model passes per task Added latency (minutes) Best fit
CI tests only 0 2 to 5 Verifiable logic, bug fixes, refactors
Single end-of-run evaluator pass 1 5 to 15 Features with clear acceptance criteria
Iterative evaluator loop (5 to 15 rounds) 5 to 15 30 to 240 Design quality, UX and vague specs

My decision path:

  1. Can automated tests verify the outcome? If yes, run CI and stop.

  2. Is the output subjective or high-risk? If yes, add an evaluator with a capped iteration count.

  3. Otherwise, run a single pass and sample outputs for human review.

Flowchart for deciding between CI tests, a capped generator-evaluator loop, or a single

An evaluator is only trustworthy if it fails work that deserves to fail, so I test it like any other control. Its reliability decays as prompts, models and codebases change.

  • Seed known defects into sample outputs and measure the catch rate.

  • Compare evaluator scores with human reviewer scores on a fixed sample each month.

  • Track the pass rate over time. A rate drifting toward 100% means the grader went soft.

  • Rotate criteria and, where possible, the evaluator model so the generator cannot learn to game it.

You rarely need to build a harness from scratch. The real question is which framework gives you the controls above with the least glue code. Here is how the main options compare as of October 2026, based on their official docs. Adoption is broad: on GitHub, LangGraph has about 43,000 stars, CrewAI about 60,000 and the deepagents repo about 30,000. The main difference between them is how much control flow you write yourself. Choose carefully: Gartner (2025) estimates only about 130 of the thousands of vendors selling agentic AI are real, so I stick to frameworks with active maintainers and public docs.

Decision guide showing when to choose the Claude Agent SDK, LangGraph or Deep Agents,

Framework Maintainer, license Languages Context management Durable state Human-in-the-loop and safety Model support Best for
Claude Agent SDK Anthropic, commercial terms Python, TypeScript Claude Code's built-in context management and compaction Sessions you can resume or fork Per-tool permissions, approval prompts, lifecycle hooks Claude Coding and file-heavy agents that want a ready-made harness
OpenAI Agents SDK OpenAI, MIT Python first Sessions with automatic compaction SQLite, Redis, SQLAlchemy, MongoDB and more session stores Guardrails, approvals on interrupted runs, Docker sandbox agents OpenAI by default, others via adapters Handoff-based multi-agent apps with built-in tracing
LangGraph LangChain, MIT Python, JS/TS Checkpointers for short-term memory, stores for long-term Durable execution that resumes from the exact step Interrupts to inspect and edit state Model-agnostic Custom, explicit control flow you want to own
Deep Agents LangChain, MIT Python, TypeScript Summarizes long threads, offloads tool output to a filesystem Inherits LangGraph persistence Approve, edit or reject tool calls; pluggable sandboxes Any tool-calling model Long research and coding tasks on an open stack
Microsoft Agent Framework Microsoft, MIT Python, .NET Pluggable compaction: summarization, sliding window, truncation (experimental) Workflow checkpointing and time-travel Human-in-the-loop workflows, OpenTelemetry Azure OpenAI, OpenAI, Foundry and others .NET and Azure shops; AutoGen users migrating
CrewAI CrewAI, MIT Python Built-in memory and knowledge Checkpointing, event-driven Flows Human input and review steps Multiple providers Role-based teams and business workflows
Google ADK Google, Apache 2.0 Python, TypeScript, Go, Java, Kotlin Summarizes older turns, filters events, tracks tokens Sessions, state and resumable tasks Action confirmations, graph workflow human input Gemini first, adapters for others Google Cloud teams and A2A multi-agent setups

A note on AutoGen: its GitHub repo now says it is in maintenance mode and points new users to Microsoft Agent Framework. I would not start a new project on it.

How I choose

  • Coding agent, want results this week: Claude Agent SDK. You get compaction, permissions, subagents, hooks and MCP tool connections without writing them.

  • Need to swap models or avoid vendor lock-in: LangGraph for full control, or Deep Agents if you want a batteries-included harness on top of it.

  • Already on OpenAI and need tracing plus guardrails: OpenAI Agents SDK.

  • Enterprise .NET or Azure: Microsoft Agent Framework.

  • Google Cloud or polyglot teams: Google ADK.

For a deeper look at orchestration options, see tkxel's agentic AI frameworks comparison.

Before agents run code on their own, require a sandbox, scoped credentials and a human approval step on anything that reaches production. Safe execution is where trust is decided, and weak risk controls are one of the main reasons agentic AI projects get canceled.

I apply four checkpoints:

  1. Isolate execution in a sandbox with no production secrets.

  2. Restrict network and file access to a named allowlist.

  3. Require human approval for merges, deploys and irreversible actions.

  4. Keep an audit log of every tool call, ideally exported through OpenTelemetry or your framework's tracing.

Then connect the harness to your existing code review and CI, so agents follow the same process as engineers.

Here is how these ideas held up on a real project. We built a quoting agent for a US company that sells industrial electrical products and consulting. Before the agent, a solutions engineer spent 5 to 7 hours turning each request for quote (RFQ) into a quote.

What the agent does

The agent reads the RFQ, searches the product master, builds a bill of materials, finds the best logistics option and drafts the quote. A human reviews every quote before it goes out. That is the human review gate from the anatomy above, applied to a real business process.

The setup

We built it on LangGraph with Claude. The agent pulls data from Microsoft Dynamics, a custom CRM, carrier portals and Excel sheets on SharePoint. One quote takes 28 to 56 steps, so this is a long-running agent in every sense this post covers.

What broke

The model was not the hard part. The data was.

  • Messy product master. It had duplicate parts, and the agent struggled to tell variants of the same part apart.

  • Knowledge in people's heads. Vendor relationships, logistics discounts and which options to prefer were never written down. Engineers just knew them.

No prompt fixes a messy product master. The agent can only be as good as the data and context the harness gives it.

What we fixed

  • Data: cleaned the product master and built data pipelines that keep it up to date without manual work.

  • Tacit knowledge: captured it through engineer interviews and past RFQs and quotes, so the agent could use what the engineers knew.

  • Guardrails: added guardrails plus pre and post tool use hooks, so we can check what the agent does before and after every tool call.

  • Staying on track: gave the agent a scratchpad file and a to-do list, the same progress-file pattern covered earlier, so it stays focused across runs of up to 56 steps.

  • Model change: switched from Opus 4.6 to Sonnet 5.5 for lower cost and faster runs, then re-ran our evaluations before trusting the new setup.

Results

Metric Before After
Time per quote 5 to 7 hours 20 to 30 min + under 15 min review
Quotes per week ~10 ~25
Cost per quote n/a $1.20 to $1.60 (was $2 to $2.50 on Opus 4.6)
Quotes sent with no edits n/a 83%
Variance vs engineer's quote n/a 8% average

Very large RFQs can still cost up to $3 per quote, but those come up only a few times a quarter.

What this taught us

  • Fix the data before you tune the agent. In our project, the duplicate parts caused more trouble than anything the model did.

  • Write down what your experts know. The agent cannot learn vendor deals or carrier preferences any other way.

  • Treat a model switch as a test event. Moving to Sonnet 5.5 cut cost per quote by 36 to 40%, but we only shipped it after our evaluations passed again.

To build an agent harness, start small and add one control at a time. The same steps apply if you are building your first agent: begin with a narrow task, a model and two tools. Plan for change from day one: agents keep taking on longer tasks with each model generation, so I re-test every harness component at least twice a year.

  1. Write the task and success criteria in plain language.

  2. Build a single agent with the minimum tools it needs.

  3. Add a token budget, iteration cap and timeout.

  4. Add a progress file and handoff notes once runs pass one context window.

  5. Add an evaluator only where tests cannot verify quality, and calibrate it with scored examples.

  6. Add the sandbox and review gate before any production access.

  7. Re-test every component when you change models, and remove what the new model no longer needs.

That last step is the one most teams miss. Anthropic's principle is that every harness component encodes an assumption about what the model cannot do alone. When they moved to Opus 4.6, they removed the sprint structure and moved the evaluator to a single end-of-run pass. A harness should get simpler as models improve, not only bigger. The models named in this post (Sonnet 4.5, Opus 4.5 and Opus 4.6) are useful history, but newer ones have shipped since, which is exactly why this re-test step matters. In the case study above, moving to Sonnet 5.5 made the agent cheaper and faster, and we only switched after re-running our evaluations.

tkxel is a B2B software engineering and AI services company that designs and deploys agentic systems with the controls covered here: budgets, independent evaluation, sandboxed execution and human review. We work in phases. Teams start with one workflow, prove value, then extend the harness. Learn more about our AI Agents services.

A reliable agent comes from the harness, not the model alone. Budget tokens, manage context on purpose, keep evaluators independent and audited, gate execution with human review, and simplify the harness every time the model gets better. Next, read tkxel's guide to AI agents in software engineering to see where these controls fit in a delivery workflow.

About the author

Muhammad Waiz Zeeshan
Muhammad Waiz Zeeshan
linkedin-icon

Lead AI Engineer at tkxel applying agentic AI, machine learning, analytics, and data-driven solutions to enterprise business challenges.

Frequently asked questions

What is an AI agent?

An AI agent is a model-driven system that plans, calls tools and acts toward a goal with limited supervision. Unlike a chatbot, it works across many steps instead of answering one prompt.
+

What is an agent harness used for?

An agent harness is the control layer around a model. It manages context, tools, evaluation, budgets and safety gates so the agent can finish long tasks reliably.
+

What is an AI coding agent?

An AI coding agent is an agent that reads code, edits files and runs tests to complete software tasks. Autonomous coding agents do this for long periods without step-by-step approval.
+

What is the best AI coding agent framework?

For fast results on coding tasks, the Claude Agent SDK. For model flexibility and full control, LangGraph or Deep Agents. For OpenAI-based stacks, the OpenAI Agents SDK.
+

How do you create an AI agent?

Pick a narrow task, choose a model, give it two or three tools and add a token budget. Get that working first, then add progress tracking, evaluation and review gates before it touches production.
+

What is the difference between LangGraph and Deep Agents?

LangGraph is a low-level framework for building stateful agent graphs. Deep Agents is a ready-made harness built on LangGraph that adds planning, a filesystem, subagents and context summarization.
+

What is coding agent orchestration?

Coding agent orchestration is how a harness routes work between agents, such as a planner, generator and evaluator, and manages their shared state, budgets and handoffs.
+

How do you make an AI agent without a framework?

You can make an AI agent with a model API, a loop and a few tool functions. Once runs get long, a framework like LangGraph, deepagents or the Claude Agent SDK saves you from rebuilding memory, checkpoints and permissions yourself.
+

SHARE

SUMMARIZE WITH AI

Build Agents That Actually Finish

Ship reliable, governed AI agents with expert engineering help.

Talk to Experts

Subscribe Newsletter

Ready to get started?

Clutch

“tkxel completely transformed the way we manage our customer relationships. Their customized CRM system streamlined our processes and improved customer satisfaction. We highly recommend their services to any business looking for real results.”

Nick Drogo

Nick Drogo

Global Director IT, Knowles

“They helped us build a docketing app with an intuitive user interface, allowing our attorneys to track over 10,000 U.S. and international patent systems.”

Robert K Burger

Robert K Burger

COO, Sterne Kessler

“tkxel has proven beyond par that they excel not just in building and integrating with our team but building at a level that is at par with any US development team. Working with tkxel is one of the best decisions we have made.”

Umair Bashir

Umair Bashir

CTO, Replenium

“tkxel shared our vision right from the get go, and helped us achieve the unthinkable through perseverance and a thorough attention to detail. Their team was highly professional and possessed a firm grasp on technicalities, a combination that is hard to find in the industry.”

Pam Chitwood

Pam Chitwood

Product Manager, ABB

Invalid email address

Loading

“tkxel completely transformed the way we manage our customer relationships. Their customized CRM system streamlined our processes and improved customer satisfaction. We highly recommend their services to any business looking for real results.”

Nick Drogo

Nick Drogo

Global Director IT, Knowles

“They helped us build a docketing app with an intuitive user interface, allowing our attorneys to track over 10,000 U.S. and international patent systems.”

Robert K Burger

Robert K Burger

COO, Sterne Kessler

“tkxel has proven beyond par that they excel not just in building and integrating with our team but building at a level that is at par with any US development team. Working with tkxel is one of the best decisions we have made.”

Umair Bashir

Umair Bashir

CTO, Replenium

“tkxel shared our vision right from the get go, and helped us achieve the unthinkable through perseverance and a thorough attention to detail. Their team was highly professional and possessed a firm grasp on technicalities, a combination that is hard to find in the industry.”

Pam Chitwood

Pam Chitwood

Product Manager, ABB

Upcoming Webinar

FinOps for AI Workflows: Controlling Cloud Costs for Businesses

August 12, 2026 10:00 am EST

00 Days
00 Hours
00 Minutes
00 Seconds