How to Build a Custom Agent Harness (LangChain)
langchain‘s how-to argument for building agents as model + harness, where the harness
is “the scaffolding around the model that connects it to the real world.” Its sharpest claim is
the agentic-coding-harness thesis stated cleanly: task-harness fit determines agent
usefulness more than raw model capability. The contribution this source adds is a concrete
composition mechanism for that scaffolding — agent-middleware.
The core loop + middleware
- Base agent loop: a model calls tools repeatedly until the task is done. The harness’s job is delivering the right context to the model at each step.
- agent-middleware is the customization layer: each piece “hooks into the agent loop at each step — before/after model calls, before/after tool calls, at startup and teardown,” handles one concern, and composes with others (vs. a monolithic framework).
- Four levers: (1) deterministic logic / business rules & dynamic control, (2) tool lifecycle (setup, teardown, registration), (3) custom state tracking across execution, (4) stream handlers transforming output.
Prebuilt middleware catalogued
Context (SummarizationMiddleware, ContextEditingMiddleware), memory (MemoryMiddleware),
environment (ShellToolMiddleware), delegation (SubAgentMiddleware → agent-orchestration),
failure (ToolRetryMiddleware), policy (PIIMiddleware, HumanInTheLoopMiddleware → supervised
gates like agent-kanban), cost (PromptCachingMiddleware), and autonomy steering.
Frameworks it names
create_agent(langchain) — “the easiest way to build a custom harness.”- Deep Agents — a production-ready harness built on
create_agent. - Claude Agent SDK (anthropic) — pre-assembled with opinionated middleware.
- Pi — “a highly configurable coding agent harness” (cf. the Pi-based oh-my-pi).
- LangChain says its own GTM and coding agents use
create_agent+ tailored middleware stacks rather than monolithic frameworks.
Why it matters here
It’s the mechanism page the harness thesis was missing: prior instances (agentsys, gstack, …) asserted “structure substitutes for capability” as architecture; this names the unit of that structure — composable middleware on a minimal loop — and restates “everything else > the model” as task-harness fit.
Related
agent-middleware · agentic-coding-harness · langchain · agent-orchestration · oh-my-pi · anthropic