middleware configuration surface. Add LangChain middleware to define_deep_agent or defineDeepAgent to monitor tool calls, add guardrails, redact data, retry transient failures, or customize model calls.
Managed Deep Agents is in public beta and available on LangSmith Cloud in the US region only.
backend, store, checkpointer, memory, skills, and the system prompt. Middleware should focus on agent behavior around model calls, tool calls, and lifecycle hooks.
For deeper hook, state, and context details, see Custom middleware.
Add a middleware module
Put middleware code undermiddleware/ in your project and import it from the agent entry. For the full project layout, see Project structure.
Attach middleware to the agent
Import the middleware into the project-root agent entry and pass it in themiddleware list.
mda dev and mda deploy copy the project files into the compiled build. Your middleware imports should work the same way they do in a normal local Python or TypeScript project.
Use prebuilt middleware
You can also pass LangChain prebuilt middleware directly in the agent definition.Human-in-the-loop
Pause the agent before sensitive tool calls so a person can approve, edit, or reject them. Setinterrupt_on (Python) or interruptOn (TypeScript) in the agent definition, and optionally set permissions to gate tool and filesystem access.
interrupt_on field applies the same interrupt behavior as LangChain’s human-in-the-loop middleware. For decision types (approve, edit, reject), conditional interrupts, and permission rules, see the Deep Agents Human-in-the-loop and Permissions guides.
Respond to an interrupt
When a run hits an interrupt, it pauses and waits for a human response before continuing.- During local development,
mda devruns the agent in LangSmith Studio, which surfaces the interrupt so you can inspect the pending tool call and resume the run. - On a deployed agent, resume the paused run through the LangGraph server API with a
Command(resume=...)payload. See Human-in-the-loop using server API.
During public beta, Managed Deep Agents is CLI-first and programmatic invocation is not yet documented. To resume runs programmatically from your own application, contact your LangChain team.
Use runtime context
Middleware can read per-run context through the normal LangChain runtime APIs. Use context for user IDs, organization IDs, feature flags, request metadata, or credentials that should not be part of the model prompt by default. For examples, see Custom middleware.Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

