LangChain introduces AgentMiddleware — composable hooks that let developers inject custom logic at every stage of an agent's execution loop.
LangChain released AgentMiddleware, a system that exposes six lifecycle hooks (before_agent, before_model, wrap_model_call, wrap_tool_call, after_model, after_agent) for customizing agent behavior without rewriting core harness logic. The feature ships with prebuilt middleware for common patterns like PII redaction, summarization, and retries. It works across both create_agent and the more advanced create_deep_agent abstractions. Middleware are composable, meaning multiple can be stacked and mixed for complex pipelines.
AgentMiddleware solves a real pain point: customizing agent behavior (PII scrubbing, caching, human-in-the-loop) without forking or hacking LangChain internals. The six lifecycle hooks map cleanly to real production concerns — before_model for input sanitization, wrap_tool_call for access control, after_agent for result persistence. Middleware are composable and subclassable, so team-level abstractions can be built once and reused across projects.
If you're running a LangChain agent in production this week, add the prebuilt PII redaction middleware to your before_model hook and measure whether it catches any sensitive tokens in your logs — takes 15 minutes and validates whether your current setup is leaking data.
Open your existing LangChain agent script or create a new one with `from langchain import create_agent`
Tags
Also today
Signals by role
Also today
Tools mentioned