langchain-middleware
Agent skill fromlangchain-ai/langchain-skills
INVOKE THIS SKILL when you need human-in-the-loop approval, custom middleware, or structured output. Covers HumanInTheLoopMiddleware for human approval of dangerous tool calls, creating custom middleware with hooks, Command resume patterns, and structured output with Pydantic/Zod.
How to install langchain-middleware
install langchain-middleware
# install the langchain-skills pack with the skills CLI
npx skills add langchain-ai/langchain-skills# or add only this skill to Claude Code: copy the folder
config/skills/langchain-middleware/
# into
~/.claude/skills/langchain-middleware/ (all projects)
.claude/skills/langchain-middleware/ (one project)
1<overview>2Middleware patterns for production LangChain agents:34- **HumanInTheLoopMiddleware** / **humanInTheLoopMiddleware**: Pause before dangerous tool calls for human approval5- **Custom middleware**: Intercept tool calls for error handling, logging, retry logic6- **Command resume**: Continue execution after human decisions (approve, edit, reject)78**Requirements:** Checkpointer + thread_id config for all HITL workflows.9</overview>1011---1213## Human-in-the-Loop1415<ex-basic-hitl-setup>16<python>17Set up an agent with HITL middleware that pauses before sending emails for approval.1819```python20from langchain.agents import create_agent21from langchain.agents.middleware import HumanInTheLoopMiddleware22from langgraph.checkpoint.memory import MemorySaver23from langchain.tools import tool2425@tool26def send_email(to: str, subject: str, body: str) -> str:27 """Send an email."""28 return f"Email sent to {to}"2930agent = create_agent(31 model="gpt-4.1",32 tools=[send_email],33 checkpointer=MemorySaver(), # Required for HITL34 middleware=[35 HumanInTheLoopMiddleware(36 interrupt_on={37 "send_email": {"allowed_decisions": ["approve", "edit", "reject"]},38 }39 )40 ],41)42```43</python>44<typescript>45Set up an agent with HITL that pauses before sending emails for human approval.4647```typescript48import { createAgent, humanInTheLoopMiddleware } from "langchain";49import { MemorySaver } from "@langchain/langgraph";50…
Excerpt shown under the repository's MIT license.
