langchain-middleware

Pause LangChain agent tool calls for human approval before execution.

36|27|Updated Jan 28, 2026
One-click install
npx skills add https://github.com/caio-moliveira/ai-engineer-roadmap --skill langchain-middleware-caio-moliveira
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: langchain-middleware
Source: https://github.com/caio-moliveira/ai-engineer-roadmap/tree/main/.agents/skills/langchain-middleware
Command: npx skills add https://github.com/caio-moliveira/ai-engineer-roadmap --skill langchain-middleware-caio-moliveira

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents unsafe or unintended side-effectful tool calls by pausing agent execution for human review, adds robust middleware hooks for logging and error handling, and enforces structured outputs for predictable downstream processing.

Core Features & Use Cases

  • Human-in-the-Loop Approval: Configure per-tool HITL policies to require approve, edit, or reject decisions before executing dangerous actions like sending or deleting data.
  • Custom Middleware Hooks: Intercept and wrap model and tool calls with before_model, after_model, wrap_tool_call, before_agent, and after_agent hooks for retries, logging, and validation.
  • Resume and Edit Commands: Support resuming agent execution via Command objects with edited arguments and decision feedback, enabling workflows that correct or abort actions after human review.
  • Structured Output: Encourage use of typed schemas (Pydantic / Zod) to produce deterministic, validated outputs compatible with downstream systems.
  • Use Case: Gate outbound emails and data-deletion tools in production agents so a human can correct addresses, provide feedback, or block sensitive operations.

Quick Start

Set up an agent that pauses before sending emails and requires human approval using HumanInTheLoopMiddleware with a persistent MemorySaver checkpointer and invoke with config thread_id "session-1".

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 for LangChain agent tool calls?

Human-in-the-loop approval in LangChain is added by applying custom middleware that pauses agent execution before high-risk tool calls, requiring a human to approve, edit, or reject the action before it runs.

How do I intercept and log LangChain agent model and tool calls?

You can intercept LangChain agent calls using custom middleware hooks like before_model, after_model, and wrap_tool_call to add logging, validation, and error handling around model and tool execution.

Does LangChain human-in-the-loop require a persistent checkpointer?

Yes, LangChain human-in-the-loop workflows require a persistent checkpointer and a thread_id configuration to successfully pause agent execution and resume it after human review.

How do I resume a LangChain agent after rejecting or editing a tool call?

You resume a paused LangChain agent by passing Command objects back to the workflow, which contain decision feedback or edited arguments to correct or abort the action after human review.

When should I use middleware to pause LangChain agents?

You should use middleware to pause LangChain agents when workflows interact with external tools that have side effects, such as sending emails or deleting data, to prevent unsafe or unintended operations.