What is an AI agent harness
An AI agent harness is the software infrastructure that wraps around a language model to run it as an autonomous agent. As defined in our previous post on agent harnesses, the harness is responsible for the tool and MCP catalog, context management, guardrails and verification, the observability layer and the execution loop, and it provides safety boundaries through a sandbox. The model reasons and the harness does everything else.
LangChain states the same idea as a short equation, which is agent equals model plus harness. The harness is everything around the model loop, meaning the prompt, the tools and any middleware that shapes behavior. This post examines how that definition is implemented across the LangChain stack and how to assemble a harness with it.
The core architecture in LangChain
The core of a LangChain harness is a single loop with hooks around it. The model is called, it chooses tools to execute and the run ends when it requests no further tools. create_agent implements exactly this loop and leaves everything else to configuration.
Middleware is the extension mechanism. Each middleware attaches to one or more of six hooks, namely before_agent, before_model, wrap_model_call, after_model, wrap_tool_call and after_agent. Summarization, approval gates, retries and PII filtering are all expressed as middleware and not as changes to the loop itself.
Middleware is not a separate runtime. The hooks execute inside the compiled LangGraph graph that create_agent returns, so the whole agent can be placed inside a larger graph as a single node.
Agent harnesses vs model runtimes
A runtime decides how an agent executes and a harness decides what the agent is equipped with. LangChain separates its open source packages along this line. LangGraph is the runtime, LangChain is the framework and Deep Agents is the harness.
The layers are stacked and not exclusive. Deep Agents is built on create_agent, which is in turn built on LangGraph, so a team can start with the full harness and descend one layer only when the default loop is the wrong shape. Temporal and Inngest belong to the same runtime category, while the Claude Agent SDK and Manus sit in the harness category.
The boundary is not sharp. create_agent is itself a minimal harness, since it already bundles the loop, the tools and the middleware, and this is the reading adopted in the rest of this post.
Key components of a LangChain agent harness
A LangChain agent harness consists of three groups of components, which are context and state, tool execution with guardrails and observability. Each group maps either to middleware or to a service of the underlying runtime.
Context engineering and state management
Context engineering in LangChain means controlling what the model sees on each call and what persists between calls. Model context is transient and rebuilt for every call, whereas tool context and life cycle context are written to state and persist. This distinction matters because a transient change is safe to experiment with while a persistent one alters every later step.
The harness draws context from three data sources.
State is persisted by a checkpointer, which saves the thread after each step. This is what allows a run to pause for approval and resume later, and it is why several middleware require a checkpointer to be configured.
Deep Agents adds automatic compression on top of this model. A tool result above 20,000 tokens is written to the filesystem and replaced in context by a file path with a short preview. Summarization starts once the conversation reaches 85% of the model's input window and keeps the most recent 10% of tokens intact.
Subagents provide the third mechanism. The task tool delegates work to a subagent with a fresh context window, and only its final report returns to the main agent.
Tool execution and security guardrails
Tools run inside the wrap_tool_call hook, and guardrails are middleware placed before the model, after the model or around the tool. A tool can be a plain function, a LangChain tool or a tool loaded from any MCP server. Because every call passes through the same hook, a guardrail is written once and applies to the whole catalog.
The prebuilt middleware covers the most common risks.
Deep Agents adds declarative filesystem permissions. Each rule names the operations, the path patterns and an allow or deny mode, and the first matching rule wins.
Code execution is isolated through sandbox backends. The execute tool is exposed to the model only when the configured backend implements the sandbox protocol, so an agent without a sandbox never sees a shell. Supported providers include LangSmith, Daytona, E2B, Modal, Runloop and Vercel.
Two integration patterns exist. The agent can run inside the sandbox, or it can run outside and call a remote sandbox as a tool, which keeps credentials and the control loop away from generated code.
Monitoring and observability layers
Observability in a LangChain harness is tracing. Every model call, tool call and middleware step of a run is recorded as a trace, and agents built with create_agent support this without extra code.
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY=<your-api-key>
The same traces can be emitted in OpenTelemetry format by setting LANGSMITH_OTEL_ENABLED=true. This allows a team to route spans to an existing collector and avoid coupling the harness to a single vendor.
Middleware supplies the second layer. A custom hook can log latency, token counts or guardrail decisions that a generic trace would not capture.
Traces are also the input for improvement and not only for debugging. A harness that already emits OpenTelemetry traces can feed them into an evaluation and improvement pipeline without an SDK rewrite.
How to build your own agent harness with LangChain
A custom harness is built by calling create_agent with a model, a tool catalog, a checkpointer and an ordered list of middleware. Each responsibility of the harness then corresponds to one argument or one middleware.
from langchain.agents import create_agent
from langgraph.checkpoint.memory import InMemorySaver
agent = create_agent(
model="anthropic:claude-sonnet-4-6",
tools=[search, run_query],
system_prompt="You are a data analyst. Verify results before answering.",
checkpointer=InMemorySaver(),
)This already runs the full loop with persistence. The remaining work is deciding where the agent operates and how the loop is bounded.
Configuring the execution environment
The execution environment is defined by three choices, which are where state is stored, where files live and where code runs. The checkpointer answers the first. An in memory saver is sufficient during development, while production requires a database backed checkpointer so that threads survive a restart.
Files and code are handled by a backend. create_agent does not ship one, so the practical route is to move to create_deep_agent, which accepts the same tools and middleware and adds a backend argument.
from deepagents import create_deep_agent
agent = create_deep_agent(
model="anthropic:claude-sonnet-4-6",
tools=[search, run_query],
backend=sandbox,
interrupt_on={"execute": True},
)In this configuration the agent receives the filesystem tools and execute, and every shell command waits for approval. The interrupt_on argument is the Deep Agents shorthand for the human in the loop middleware.
Implementing loop controls and fallbacks
Loop controls are middleware that bound how many steps a run may take, and fallbacks are middleware that retry or switch models when a call fails. Neither appears in a demo. Both are necessary in production because an unbounded loop is the most expensive failure an agent can produce.
from langchain.agents.middleware import (
HumanInTheLoopMiddleware,
ModelCallLimitMiddleware,
ModelFallbackMiddleware,
ModelRetryMiddleware,
SummarizationMiddleware,
ToolCallLimitMiddleware,
ToolRetryMiddleware,
)
agent = create_agent(
model="anthropic:claude-sonnet-4-6",
tools=[search, run_query, send_report],
checkpointer=InMemorySaver(),
middleware=[
ModelCallLimitMiddleware(run_limit=25, exit_behavior="end"),
ToolCallLimitMiddleware(tool_name="search", run_limit=5),
ModelRetryMiddleware(max_retries=3, backoff_factor=2.0),
ModelFallbackMiddleware("openai:gpt-5.4-mini"),
ToolRetryMiddleware(max_retries=2, tools=["search"]),
SummarizationMiddleware(
model="openai:gpt-5.4-mini",
trigger=("fraction", 0.8),
keep=("fraction", 0.3),
),
HumanInTheLoopMiddleware(interrupt_on={"send_report": True}),
],
)The two limit middleware distinguish run_limit, which applies to a single invocation, from thread_limit, which applies to the whole conversation and therefore needs a checkpointer. The exit_behavior argument decides whether the run ends quietly or raises an error. Ending quietly suits user facing agents and raising suits batch pipelines where a silent stop would hide the problem.
Failure handling proceeds in two stages. ModelRetryMiddleware repeats the call on the same model with exponential backoff, and ModelFallbackMiddleware then tries the alternative models in the order given. A refusal is a separate case, since without ModelRefusalMiddleware the run ends as if it had succeeded.
The limits above are illustrative values and not recommendations. They should be set from the traces of real runs, which is the point where the observability layer feeds back into the harness configuration.
Open source agent harness ecosystems on GitHub
The open source harness ecosystem on GitHub is organized around three projects, which are LangChain Deep Agents, the Claude Agent SDK and the OpenAI Agents SDK. All three are MIT licensed and all three implement the same tool calling loop. They differ in model coupling, in where the agent runs and in how behavior is extended.
LangChain Deep Agents
Deep Agents is LangChain's opinionated harness, a ready to run agent built on create_agent with a virtual filesystem, subagents, context compression, skills and memory already wired in. It is published as langchain-ai/deepagents for Python and langchain-ai/deepagentsjs for TypeScript, and it ships both as an SDK and as a terminal agent.
Internally it is a fixed stack of middleware over the same loop described earlier. Any element can be extended, overridden or replaced, with the exception of the filesystem middleware, which the harness treats as required scaffolding. Planning through write_todos has been opt in since version 0.7.
Two details are relevant for production use. Harness profiles allow the tool surface to be tuned per provider or per model, which matters when the same agent is evaluated on several models. LangChain also reports running the harness in its own products, namely Open SWE and LangSmith Fleet.
Comparisons with Claude and OpenAI harnesses
Deep Agents is model neutral and backend pluggable, whereas the Claude Agent SDK and the OpenAI Agents SDK are designed around the models of their vendors. The Claude Agent SDK exposes the agent loop, tools and context management of Claude Code as a library. OpenAI extended its Agents SDK in April 2026 with what it calls a model native harness and sandbox agents.
The main architectural difference concerns the execution pattern. The Claude Agent SDK runs the agent inside the sandbox, while Deep Agents supports that pattern as well as a remote sandbox called as a tool. The OpenAI Agents SDK follows the second direction by treating the harness as a control plane and the sandbox as compute.
The second difference is what surrounds the harness. Deep Agents deployments include an agent server with threads, streaming and authentication, whereas with the Claude Agent SDK that server is written and operated by the team.
The choice follows from the constraints of the project. A team committed to Claude that wants the Claude Code toolset gains the most from the Claude Agent SDK, and the same reasoning holds for OpenAI models and the Agents SDK. A team that needs to compare models, isolate tenants or keep the option of changing provider is better served by Deep Agents, or by a custom harness on create_agent when the defaults are more than the task requires.
FAQs
Is Codex considered an AI agent harness?
Yes, Codex is considered an AI agent harness. OpenAI itself describes the Codex harness as the agent loop and execution logic behind the Codex CLI, the cloud product and the IDE extension, and it publishes that harness as open source. It is a harness specialized for software work, whereas Deep Agents targets general tasks.
How does a LangChain agent harness differ from LangGraph?
A LangChain agent harness differs from LangGraph in the layer it occupies. LangGraph is the runtime that provides durable execution, streaming, persistence and interrupts, whereas the harness is the loop, the tools and the middleware that run on top of it. The harness decides what the agent can do and LangGraph decides how that work is executed and resumed.
Can you integrate a LangChain agent harness with Claude Code plugins?
You can integrate a LangChain agent harness with most of what Claude Code plugins contain, although not with a plugin as a single unit. A plugin is a directory of skills, subagents, hooks and MCP servers, so its MCP servers connect through the LangChain MCP adapters and its SKILL.md files can generally be reused by Deep Agents, which follows the same Agent Skills standard. Hooks and subagent definitions do not transfer and have to be rewritten as middleware and subagent specs.
Why is an agent evaluation harness necessary in production?
An agent evaluation harness is necessary in production because an agent is non deterministic, so a change to a prompt, a tool or a model can degrade behavior without raising any error. The evaluation harness replays a fixed set of tasks or recorded traces against each version and scores the outcome, which turns a regression into a measurable signal before release. Without it the only evidence of quality is user complaints.



