Overriding / Disable Default Deep Agents Middleware, Example + Community Thoughts #655
Replies: 5 comments 3 replies
-
|
Do you have a recommended approach to removing middleware from deep agents or sub agents? Right now, if you pass the middleware argument as empty [] with main or subagents, it treats it as additive. The default middleware is still included (todos, summarization, filesystem) instead of allowing control over what middleware is included. |
Beta Was this translation helpful? Give feedback.
-
|
Centralizing my comment from #943, adding a +1 to Brett Gardner (@brettgardner21) and vivek (@vtrivedy): One thing I want to emphasize is that configurability here isn’t about forcing users to tune things by default. Deepagents can (and should) work sensibly out of the box for most people. The concern is that without any ability to customize, e.g. disabling middleware, changing the inputs to summarization, or swapping the prompt, advanced users quickly hit a ceiling. At that point, the path of least resistance is often to abandon deepagents entirely and go back to a more explicit ReAct-style agent where these decisions are controllable. The fact that middleware exists at all implies this is intended to be a tunable framework. Given that, I think it’s reasonable to expect some level of granular configurability rather than treating middleware as fixed policy. From my perspective, exposing these hooks preserves deepagents as a flexible abstraction rather than a closed one, without harming the default experience. This is explicitly an optional feature so that most users do not need to configure it. |
Beta Was this translation helpful? Give feedback.
-
|
joshb1050 vivek (@vtrivedy) Here is a specific use case, and why the current design is a big problem. We recently hit a wall with the deepagent harness for a standard multi-agent use case: Use Case:
The Problem:
Without the ability to override or disable these, using the harness for even a simple "1 Main, 2 Sub-agents" architecture was a non-starter. We had to pivot back to create_agent and manually implement the middleware/graph logic just to regain control over the sub-agent environments. Granular control is essential for keeping specialized agents "on the rails." |
Beta Was this translation helpful? Give feedback.
-
|
Any new thoughts on this ? |
Beta Was this translation helpful? Give feedback.
-
|
Update for everyone watching this thread: as of There are two extension points, both keyed by
Registrations are additive — re-registering under the same key merges on top — and there is a declarative Replacing the original monkey-patchThe "custom summarization" listed above from vivek (@vtrivedy) example becomes: from deepagents import (
HarnessProfile,
create_deep_agent,
register_harness_profile,
)
from langchain.agents.middleware.types import AgentMiddleware
class CustomSummarizationMiddleware(AgentMiddleware):
name = "SummarizationMiddleware" # match by name to displace the built-in
def wrap_model_call(self, request, handler):
...
register_harness_profile(
"anthropic:claude-opus-4-7",
HarnessProfile(
excluded_middleware=frozenset({"SummarizationMiddleware"}),
extra_middleware=[CustomSummarizationMiddleware()],
),
)
agent = create_deep_agent(model="anthropic:claude-opus-4-7")Multi-agent casecc Brett Gardner (@brettgardner21) Profiles resolve per selected model, including for subagents — so if your two specialized subagents run on a different model (or even the same one) and don't need the planner/filesystem stack, you can register a profile that strips them: from deepagents import HarnessProfile, register_harness_profile
register_harness_profile(
"openai:gpt-5.5", # whatever your subagents resolve to
HarnessProfile(
excluded_middleware=frozenset({
"TodoListMiddleware",
"FilesystemMiddleware",
"SummarizationMiddleware",
}),
),
)A few guardrails worth knowing about:
On the broader framingcc joshb1050 Agreed with the framing — defaults stay sensible out of the box, and customization is opt-in through a typed, supported surface rather than reaching into private modules. The previous Full field surface, merge semantics, and plugin packaging live in the profiles documentation. Curious to hear what people land on once they've ported their existing overrides over — happy to keep iterating. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey all, we've gotten some requests about customizing/replacing the built-in middlewares in Deep Agents. Starting this discussion to hear the community's overall thoughts! Sharing a snippet to override in the meantime if you say wanted to roll your own summarization.
NOTE
The updated version of overriding as of
deepagents 0.4.0is below. The middleware is private because we anticipate changing the interface, which will cause workarounds like these to change again.NEW, USE THIS IF NEEDED
OLD DO NOT USE:
Beta Was this translation helpful? Give feedback.
All reactions