langchain-ai avatar

Langchain Middleware

For production LangChain agents that need human oversight on risky operations like sending emails or deleting data. Sets up human-in-the-loop middleware that pauses execution before dangerous tool calls, letting humans approve, edit arguments, or reject with feedback. Also covers custom middleware hooks for logging, retries, and error handling. The resume pattern with Command objects handles the back-and-forth flow cleanly. Requires a checkpointer and thread_id configuration, which trips up developers initially but makes sense once you need to pause and resume agent execution across different processes.

skills.sh installs
17K
GitHub stars
1.3K
last updated
Aug 21, 2026

Install

$ npx -y skills add langchain-ai/langchain-skills --skill langchain-middleware --agent claude-code

Installs into .claude/skills of the current project.

Files

Middleware patterns for production LangChain agents:
  • HumanInTheLoopMiddleware / humanInTheLoopMiddleware: Pause before dangerous tool calls for human approval
  • Custom middleware: Intercept tool calls for error handling, logging, retry logic
  • Command resume: Continue execution after human decisions (approve, edit, reject)

Requirements: Checkpointer + thread_id config for all HITL workflows.


Human-in-the-Loop

Set up an agent with HITL middleware that pauses before sending emails for approval.
from langchain.agents import create_agent
from langchain.agents.middleware import HumanInTheLoopMiddleware
from langgraph.checkpoint.memory import MemorySaver
from langchain.tools import tool

@tool
def send_email(to: str, subject: str, body: str) -> str:
    """Send an email."""
    return f"Email sent to {to}"

Sponsors

Details

Repository
github.com/langchain-ai/langchain-skills
Categories
Frontend Development, Backend & APIs, AI & Agent Building, Python

More from langchain-ai/langchain-skills

All 15
1tw93 avatarhealthtw93/wazaRuns a budget-aware agent-assisted engineering health audit for instruction/config drift, hooks/MCP, verifier surfaces, and AI maintainability. Use when users a16.4Kskills.sh installs
2agentspace-so avatargpt-image-2agentspace-so/runcomfy-agent-skillsImage generation and editing with OpenAI's GPT Image 2, optimized for embedded text, logos, and layout precision.16Kskills.sh installs
3yuan1z0825 avatarnature-readeryuan1z0825/nature-skillsBuild full-paper Chinese-English side-by-side, figure/table/equation-aware, source-grounded Markdown readers for journal or conference papers from PDF, DOI, arX15.9Kskills.sh installs
4vercel avatarbuilding-componentsvercel/components.buildGuide for building modern, accessible, and composable UI components. Use when building new components, implementing accessibility, creating composable APIs, set15.1Kskills.sh installs
5clerk avatarclerk-swiftclerk/skillsImplement Clerk authentication for native Swift and iOS apps using ClerkKit and ClerkKitUI source-guided patterns. Use for prebuilt AuthView or custom native fl15Kskills.sh installs
6fastapi avatarfastapifastapi/fastapiFastAPI best practices and conventions. Use when working with FastAPI APIs, Pydantic models, dependencies, streaming responses including Server-Sent Events (SSE14.9Kskills.sh installs