Skip to main content
Managed Deep Agents support the normal Deep Agents middleware configuration surface. Add LangChain middleware to define_deep_agent 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.

Project structure

Keep the agent entry point at the project root and custom middleware under middleware/:
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.

Use prebuilt middleware

You can use LangChain prebuilt middleware directly in the agent definition.
agent.py
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.

Add a custom middleware module

For a more advanced option, you can also define custom middleware.
middleware/audit.py
Import the middleware into the project-root agent entry and pass it in the middleware list.
agent.py
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 project.

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.