langchain-middleware

Implement human-in-the-loop approval and custom middleware hooks for LangChain agents.

Updated Jul 16, 2026
One-click install
npx skills add https://github.com/flemx/salesforce-langgraph-agent --skill langchain-middleware-flemx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: langchain-middleware
Source: https://github.com/flemx/salesforce-langgraph-agent/tree/main/.agents/skills/langchain-middleware
Command: npx skills add https://github.com/flemx/salesforce-langgraph-agent --skill langchain-middleware-flemx

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires langchain, langgraph.

What problem does it solve? Building production LangChain agents often requires pausing execution for human approval of dangerous tool calls, intercepting tool execution for retries or logging, and resuming runs after human decisions. This Skill provides the exact middleware patterns, hook signatures, and resume syntax needed to implement these workflows correctly in Python and TypeScript. ## Core Features & Use Cases - Human-in-the-Loop Approval: Configure HumanInTheLoopMiddleware with per-tool policies and allowed decisions (approve, edit, reject), then resume execution with Command objects. - Custom Middleware Hooks: Use wrap_tool_call, wrap_model_call, before_model, after_model, before_agent, and after_agent hooks for retry logic, guardrails, and logging. - Common Pitfall Fixes: Correct patterns for missing checkpointers, missing thread_id, and wrong resume syntax. - Use Case: An agent that sends emails pauses before each send_email call; a human reviews, edits the recipient address, and approves, after which the agent resumes with the corrected arguments. ## Quick Start Add human approval to my LangChain agent so it pauses before calling the send_email tool and resumes after I approve.

Frequently Asked Questions about langchain-middleware

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add human approval to LangChain agent tool calls?

Use HumanInTheLoopMiddleware with an interrupt_on mapping that lists which tools require approval and their allowed decisions. Pass the middleware to create_agent along with a checkpointer, then resume execution with Command(resume={"decisions": [...]}) after the human responds.

How to create custom middleware in LangChain agents?

Use decorator hooks like @wrap_tool_call, @before_model, and @after_model in Python, or createMiddleware in TypeScript. Wrap hooks receive (request, handler) and call handler(request) to proceed, while before/after hooks receive (state, runtime) to inspect or modify state.

Why does HumanInTheLoopMiddleware fail without a checkpointer?

HITL middleware requires a checkpointer such as MemorySaver to persist agent state across the interrupt and resume cycle. Without it, the agent cannot pause and later continue execution, so always pass checkpointer to create_agent.

How do I resume a LangChain agent after an interrupt?

Resume by invoking the agent with Command(resume={"decisions": [{"type": "approve"}]}) and the same thread_id config. Decisions can be approve, edit with edited_action containing name and args, or reject with feedback.

Can I set different approval policies per tool in LangChain?

Yes, the interrupt_on mapping accepts per-tool policies. Each tool can define its own allowed_decisions list such as approve, edit, or reject, and setting a tool to False disables HITL for that tool entirely.