INVOKE THIS SKILL when you need human-in-the-loop approval, custom middleware, or structured output. Covers HumanInTheLoopMiddleware for human approval of dangerous tool calls, creating custom middleware with hooks, Command resume patterns, and structured output with Pydantic/Zod.
The langchain-middleware skill provides a set of middleware patterns to control and manage agent execution within LangChain applications. It solves the problem of needing human-in-the-loop approval for potentially dangerous tool calls, such as sending emails or performing critical actions. This skill allows developers to implement decision-making processes where an agent pauses execution, awaiting human input to approve, edit, or reject an action before it continues. It helps safeguard systems by ensuring that sensitive operations are verified by humans before being executed.
To set up HITL middleware, you need to create an agent with a 'HumanInTheLoopMiddleware' or 'humanInTheLoopMiddleware'. Specify the tools that require human approval, such as sending emails, and define the allowed decisions (approve, edit, reject) in the middleware configuration.
If an interrupt is triggered during agent execution (e.g., requiring human approval), the agent pauses and waits for human input. Once the human provides their decision (approve, edit, or reject), the agent can resume execution.
The compatibility requirements for HITL middleware include using a checkpointer (e.g., MemorySaver) and configuring a 'thread_id' for each HITL workflow. These ensure that the agent's state is properly managed and resumed after human intervention.
Quick Setup:
.claude/skills/Repository
langchain-ai/langchain-skills