Skip to main content
Managed Deep Agents support the normal Deep Agents 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.
The managed runtime still owns 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 under middleware/ 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 the middleware 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.
Middleware is the right place for cross-cutting behavior such as PII handling, rate limits, retry policies, model fallbacks, dynamic model selection, and tool-call monitoring.

Human-in-the-loop

Pause the agent before sensitive tool calls so a person can approve, edit, or reject them. Set interrupt_on (Python) or interruptOn (TypeScript) in the agent definition, and optionally set permissions to gate tool and filesystem access.
The 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 dev runs 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.
Human-in-the-loop needs durable thread state to pause and resume. The managed runtime owns the checkpointer, so no extra setup is required.

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.