langchain-middleware

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

Updated Jun 7, 2026
One-click install
npx skills add https://github.com/agnivon/viral_thread_generator --skill langchain-middleware-agnivon
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: langchain-middleware
Source: https://github.com/agnivon/viral_thread_generator/tree/main/.agents/skills/langchain-middleware
Command: npx skills add https://github.com/agnivon/viral_thread_generator --skill langchain-middleware-agnivon

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires langchain, @langchain/langgraph, @langchain/core, zod.

What problem does it solve? Building production LangChain agents often requires pausing execution before dangerous tool calls for human approval, intercepting tool calls for retry or guard logic, and resuming interrupted runs correctly. This Skill provides the exact middleware patterns, hook signatures, and resume syntax needed to implement these controls without trial and error. ## Core Features & Use Cases - Human-in-the-Loop Approval: Configure HumanInTheLoopMiddleware with per-tool policies (approve, edit, reject) so sensitive actions like sending emails or deleting data pause for human review. - Custom Middleware Hooks: Use wrap_tool_call, before_model, after_model, before_agent, and after_agent hooks to add retry logic, logging, and short-circuit guards around tool and model execution. - Interrupt Resume Patterns: Resume interrupted agents with Command objects, including editing tool arguments or rejecting calls with feedback. - Use Case: You are building an agent that can send emails and delete records. Use this Skill to require approval before sending, allow only approve/reject for deletions, and let read operations run freely, all backed by a checkpointer and thread_id. ## Quick Start Ask the agent to set up a LangChain agent with human-in-the-loop approval that pauses before calling a send_email tool and resumes after an approve decision.

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 before tool calls in LangChain?▼

Add HumanInTheLoopMiddleware to create_agent with an interrupt_on mapping of tool names to allowed decisions like approve, edit, and reject. You must also pass a checkpointer such as MemorySaver and invoke with a thread_id config.

How do I resume a LangChain agent after an interrupt?▼

Resume by invoking the agent with a Command object containing resume decisions, for example Command(resume={"decisions": [{"type": "approve"}]}), using the same thread_id config. Passing a plain dict instead of Command will not work.

Can I edit tool arguments during human approval in LangChain?▼

Yes, use a decision of type edit with an edited_action containing the tool name and corrected args. The agent then executes the tool with your modified arguments instead of the original ones.

Why does HumanInTheLoopMiddleware fail without a checkpointer?▼

HITL middleware requires a checkpointer to persist agent state across the interrupt and resume cycle. Without MemorySaver or another checkpointer, plus a thread_id in the config, the pause-and-resume flow cannot function.

What middleware hooks are available in LangChain agents?▼

Six hooks exist: wrap_tool_call and wrap_model_call use a (request, handler) signature for interception, while before_model, after_model, before_agent, and after_agent use (state, runtime) to inspect or update state.

Can I set different approval policies per tool in LangChain?▼

Yes, the interrupt_on mapping accepts per-tool policies. You can allow approve, edit, and reject for one tool, restrict another to approve and reject only, and set a tool to False to skip HITL entirely.