langchain-middleware

Pauses LangChain agent tool calls for human approval via middleware.

Updated Jul 13, 2025
One-click install
npx skills add https://github.com/Reofdev07/osai --skill langchain-middleware-reofdev07
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: langchain-middleware
Source: https://github.com/Reofdev07/osai/tree/main/.windsurf/skills/langchain-middleware
Command: npx skills add https://github.com/Reofdev07/osai --skill langchain-middleware-reofdev07

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Human-in-the-loop supervision is essential to prevent unsafe, costly, or unintended actions by LangChain agents, enabling controlled decision-making through middleware.

Core Features & Use Cases

  • Pause before dangerous tool calls with HumanInTheLoopMiddleware for human approval
  • Create custom middleware with hooks for before_model, after_model, wrap_tool_call, before_agent, and after_agent
  • Support command resume patterns and structured output formatting with Pydantic/Zod
  • Per-tool interrupt policies and thread_id tracking to ensure deterministic, auditable workflows

Quick Start

Configure an agent with HITL middleware and a MemorySaver checkpointer to require human approval before executing risky actions.

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-in-the-loop approval to LangChain agents?

Add human-in-the-loop approval to LangChain agents by configuring HumanInTheLoopMiddleware to pause execution before risky tool calls, requiring manual review before proceeding.

What are per-tool interrupt policies in LangChain human-in-the-loop workflows?

Per-tool interrupt policies allow you to specify which tools require human approval before execution. This ensures deterministic and auditable workflows by setting distinct approval rules for different actions.

Do I need a checkpointer to pause LangChain agents for human approval?

Yes, a checkpointer like MemorySaver is required to pause LangChain agents for human approval. It maintains thread_id tracking to save the agent state while waiting for manual decisions.

How to create custom middleware hooks for LangChain agents?

Create custom middleware hooks for LangChain agents using configurable lifecycle events like before_model, after_model, wrap_tool_call, before_agent, and after_agent to inject custom logic.

How do I resume a LangChain agent after a human-in-the-loop interrupt?

Resume a LangChain agent after a human-in-the-loop interrupt by using command resume patterns, which route the human's decision back into the agent to continue execution from the paused state.

When should I use human-in-the-loop middleware for LangChain?

Use human-in-the-loop middleware for LangChain when agents perform cautious executions like sending emails, reading sensitive data, or modifying external systems where unintended actions are unsafe or costly.