langchain-middleware

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

Updated May 1, 2026
One-click install
npx skills add https://github.com/ricardoo022/4dill --skill langchain-middleware-ricardoo022
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: langchain-middleware
Source: https://github.com/ricardoo022/4dill/tree/main/.gemini/skills/langchain-middleware
Command: npx skills add https://github.com/ricardoo022/4dill --skill langchain-middleware-ricardoo022

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building production LangChain agents that call dangerous tools (like sending emails or deleting data) without human oversight is risky. This Skill provides patterns for pausing agent execution before sensitive tool calls, letting humans approve, edit, or reject actions before they run. ## Core Features & Use Cases - HumanInTheLoopMiddleware: Pause agent execution before specific tool calls and resume with approve, edit, or reject decisions via LangGraph Command objects. - Per-tool policies: Configure different approval rules per tool, such as requiring approval for delete operations while allowing read operations to run freely. - Custom middleware hooks: Intercept tool calls with before_model, after_model, wrap_tool_call, before_agent, and after_agent hooks for logging, error handling, and retries. - Use Case: An agent that sends emails on behalf of users pauses before each send, a human reviews and edits the recipient address, then resumes execution 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 the action.

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 a LangChain agent tool call?▼

Add HumanInTheLoopMiddleware to create_agent and specify which tools require approval in the interrupt_on parameter. The agent pauses before those tool calls, and you resume execution by invoking with a Command object containing approve, edit, or reject decisions.

How to resume a LangChain agent after a human interrupt?▼

Resume by invoking the agent with Command(resume={"decisions": [{"type": "approve"}]}) from langgraph.types, passing the same thread_id config. Check the first result for the __interrupt__ key to detect that the agent is waiting for a decision.

Why does HumanInTheLoopMiddleware fail without a checkpointer?▼

HITL middleware requires a checkpointer like MemorySaver to persist agent state across the interrupt and resume cycle. Without it, the agent cannot restore its state after the human decision, so always pass checkpointer to create_agent along with a thread_id config.

Can I edit tool arguments before approving a LangChain tool call?▼

Yes, use a decision of type edit with an edited_action containing the tool name and corrected args. The agent resumes execution using your modified arguments instead of the originally proposed ones.

Can I configure different approval rules per tool in LangChain?▼

Yes, interrupt_on accepts a per-tool mapping where each tool gets its own allowed_decisions list, such as approve/edit/reject for send_email but only approve/reject for delete_email. Setting a tool to False disables HITL for it entirely.

What are the limitations of LangChain human-in-the-loop middleware?▼

Interrupts can only occur before tool execution, not after. HITL also cannot skip the checkpointer requirement, and every invocation must include a thread_id in the config to track conversation state.