langchain-middleware

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

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

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, plus custom middleware hooks for logging, retries, and error handling. ## Core Features & Use Cases - HumanInTheLoopMiddleware: Pause before dangerous tool calls with per-tool policies controlling allowed decisions (approve, edit, reject) in both Python and TypeScript. - Command Resume Patterns: Continue agent execution after human decisions, including editing tool arguments and rejecting calls with feedback. - Custom Middleware Hooks: Intercept tool calls with before_model, after_model, wrap_tool_call, before_agent, and after_agent hooks for logging, retry logic, and error handling. - Use Case: An agent that sends emails on behalf of users pauses before each send, shows the draft to a human who can edit the recipient address, then resumes execution with the corrected arguments. ## Quick Start Ask the AI to add human-in-the-loop approval to your LangChain agent so it pauses before calling a specific tool and resumes after approval.

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 (Python) or humanInTheLoopMiddleware (TypeScript) passed to create_agent's middleware parameter. Configure interrupt_on with the tool name and allowed decisions like approve, edit, or reject, and provide a checkpointer.

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

Resume by invoking the agent with a Command object containing resume decisions, such as Command(resume={"decisions": [{"type": "approve"}]}), using the same thread_id config. Import Command from langgraph.types in Python or @langchain/langgraph in TypeScript.

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 the edited arguments instead of the original ones.

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 pause and later continue execution, so always pass checkpointer to create_agent.

Can different tools have different approval policies in one agent?▼

Yes, interrupt_on accepts a per-tool mapping. For example, send_email can allow approve, edit, and reject, delete_email can allow only approve and reject, and read_email can be set to False to skip HITL 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.