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 private beta, available on LangSmith Cloud in the US region only. Join the waitlist to request access.
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 the CLI project file reference.
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 private 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, tenant IDs, feature flags, request metadata, or credentials that should not be part of the model prompt by default. For examples, see Custom middleware.Test and deploy
Test the project locally withmda dev, then deploy it with mda deploy. Open deployment traces in LangSmith to inspect model calls, tool calls, errors, and latency.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

