Agent middleware
The composable unit of an agentic-coding-harness: a piece of scaffolding that hooks into the agent’s core loop at defined points and handles one concern, so a harness is assembled by stacking middleware rather than adopting a monolithic framework langchain-custom-harness.
The hook points
A base agent loop is just model → calls tools → repeat until done. Middleware can intervene before/after each model call, before/after each tool call, and at agent startup & teardown langchain-custom-harness. That gives the harness its real job — delivering the right context to the model at each step — a place to act.
Four levers
- Deterministic logic — business rules / dynamic control (do mechanical work in code, not tokens).
- Tool lifecycle — setup, teardown, registration.
- Custom state — tracking across the run (cf. durable-agents’ workflow-state separation).
- Stream handlers — transforming model/tool output.
Prebuilt examples (LangChain)
Catalogued in the LangChain middleware docs.
Context engineering (SummarizationMiddleware, ContextEditingMiddleware), memory
(MemoryMiddleware, cf. gbrain), environment (ShellToolMiddleware), delegation
(SubAgentMiddleware — the agent-orchestration fan-out as a drop-in), retries
(ToolRetryMiddleware), policy/governance (PIIMiddleware, HumanInTheLoopMiddleware — the
supervised-gate pattern of agent-kanban), and cost (PromptCachingMiddleware).
Sold as a service (2026-07-28)
Middleware has been a thing you assemble in your own harness. gemini-managed-agents-hooks ships the
same hook points as a managed-service feature: drop .agents/hooks.json into the environment and
Google’s runtime fires your handlers on pre_tool_execution / post_tool_execution, with regex
matchers to target tools and either in-sandbox commands or http POSTs as handlers.
Two of the four levers above appear directly — deterministic logic (a deny gate) and stream/output handling (a lint-and-format pass). What’s new is where the middleware runs: inside a vendor’s remote sandbox rather than your process. That inverts the usual reason for this primitive. You don’t reach for hooks here to compose a harness; you reach for them because the managed model took your machine away and hooks are the only place left to put your own code. Google’s customer says it plainly — “the sandbox is remote, so our validation code had nowhere to run.”
Why it matters
It’s the mechanism under the harness thesis. Where agentic-coding-harness says structure substitutes for capability, middleware names the structural primitive: small, single-concern, composable. It reframes harness-building as selecting and ordering middleware for the task — the engineering surface behind “task-harness fit > raw model capability” langchain-custom-harness. The named LangChain middleware also map cleanly onto concerns this wiki already tracks separately (orchestration, durability, supervision, skills/memory), suggesting the harness is a middleware stack over those threads.
Related
agentic-coding-harness · langchain-custom-harness · langchain · agent-orchestration · durable-agents · spec-driven-development · gemini-managed-agents-hooks