middleware configuration surface.
Add LangChain middleware to 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.
Project structure
Keep the agent entry point at the project root and custom middleware undermiddleware/:
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.ts
Add a custom middleware module
For a more advanced option, you can also define custom middleware.middleware/audit.ts
middleware list.
agent.ts
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 TypeScript 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.Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

