Solution skill
Compose a middleware stack: PII redaction, summarization, human approval
Complete solution
The three prebuilt middlewares that cover most production agents: PIIMiddleware to keep sensitive data from the model, SummarizationMiddleware to bound history, HumanInTheLoopMiddleware to gate risky tool calls. Compose them in one list. Not the full reference manual.
TL;DR: The three prebuilt middlewares that cover most production agents: PIIMiddleware to keep sensitive data from the model, SummarizationMiddleware to bound history, HumanInTheLoopMiddleware to gate risky tool calls. Compose them in one list. Middleware stack Rules - Order matters: PII redaction belongs early so sensitive data never reaches the model or the trace. Set the token trigger with headroom below the context limit. - HumanInTheLoopMiddleware pauses execution with an interrupt; resuming needs a checkpointer and the approve/edit/reject decision.
The fix
TL;DR: The three prebuilt middlewares that cover most production agents: PIIMiddleware to keep sensitive data from the model, SummarizationMiddleware to bound history, HumanInTheLoopMiddleware to gate risky tool calls. Compose them in one list. Middleware stack Rules - Order matters: PII redaction belongs early so sensitive data never reaches the model or the trace. Set the token trigger with headroom below the context limit. - HumanInTheLoopMiddleware pauses execution with an interrupt; resuming needs a checkpointer and the approve/edit/reject decision.
The fix
- Order matters: PII redaction belongs early so sensitive data never reaches the model or the trace. Summarization sits in the middle. Approval gates wrap the tools they guard.
- SummarizationMiddleware needs its own model for the summary calls; it does not have to be the agent's main model. Set the token trigger with headroom below the context limit.
- HumanInTheLoopMiddleware pauses execution with an interrupt; resuming needs a checkpointer and the approve/edit/reject decision. Test the full interrupt-resume path, not just the happy path.
- Custom behavior goes in an AgentMiddleware subclass with hooks: beforeagent, beforemodel, wrapmodelcall, wraptoolcall, aftermodel, afteragent.
When to use this
- This covers exactly what the title says: Compose a middleware stack.
- You are setting this up for the first time, or auditing an existing setup.
- You want the key gotchas in one place before you start.
When not to use this
- You are doing a different workflow with Compose; these steps are specific to the title above.
- You need the full reference docs; this is the short path, not the manual.
Compatibility
- Not pinned to a specific version; follows current Compose behavior.
Evidence
Workflow grounded in the official v1 release notes and middleware docs, verified 2026-09-26. v1: https://docs.langchain.com/oss/python/releases/langchain-v1 ; middleware: https://docs.langchain.com/oss/python/langchain/middleware/built-in
By @issueatlas · Version 3 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_Q8HSqCaNgGbV73vO1MQ-sg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Compose a middleware stack: PII redaction, summarization, human approval <span>— Vectle</span></a>