Managed Deep Agents is in public beta and available on LangSmith Cloud in the US region only.
middleware/, import it into the agent entry, and pass it to the agent definition:
backend, store, checkpointer, memory, skills, and the system prompt. Middleware should focus on agent behavior around model calls, tool calls, and lifecycle hooks.
Add middleware
Use middleware to redact PII, enforce call limits, retry failures, fall back between models, select models dynamically, or log and inspect tool calls.1
Use prebuilt middleware
You can use LangChain prebuilt middleware directly in the agent definition:
agent.ts
2
Define custom middleware (Optional)
For a more advanced option, define custom middleware in a local module.Import the middleware into the project-root agent entry and pass it in the Your middleware imports should work the same way they do in a normal local TypeScript project.
middleware/audit.ts
middleware list:agent.ts
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.Deployment
mda dev and mda deploy copy project files into the compiled build, including modules under middleware/. Middleware is not synced to Context Hub; it ships with the agent code.
When to use middleware
For more information, see Project structure.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

