# FileSystem middleware

**URL:** <https://forum.langchain.com/t/filesystem-middleware/3672>\
**Category:** Deep Agents\
**Created:** [May 6, 2026, 1:08pm UTC](https://forum.langchain.com/t/filesystem-middleware/3672 "2026-05-06T13:08:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bassuniz](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/bassuniz/32/2718_2.png) [@bassuniz](https://forum.langchain.com/u/bassuniz)\
**Post date:** [May 6, 2026, 1:08pm UTC](https://forum.langchain.com/t/filesystem-middleware/3672/1 "2026-05-06T13:08:17Z")

</div>

I want to exclude file system middleware (system prompt file system prompt + registered tools)  
I know I can do this using profiles, but I want to do this for some subagent not all the agents that use the same provider  
I know about tool exclusion middleware but this just removes the tool not file system prompt added to the system prompt

---

<div class="post-metadata">

**Author:** ![pawel-twardziak](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/pawel-twardziak/32/960_2.png) [@pawel-twardziak](https://forum.langchain.com/u/pawel-twardziak)\
**Post date:** [May 6, 2026, 1:27pm UTC](https://forum.langchain.com/t/filesystem-middleware/3672/2 "2026-05-06T13:27:11Z")

</div>

hi @bassuniz

have you checked the doc there [Customize Deep Agents - Docs by LangChain](https://docs.langchain.com/oss/python/deepagents/customization) ?

from what I see in the source code:

- `FilesystemMiddleware` is in `_REQUIRED_MIDDLEWARE` (`deepagents/graph.py`), so `HarnessProfile.excluded_middleware` _cannot_ drop it - `_validate_excluded_middleware_config` raises `ValueError` on attempts
- Profiles are resolved by `provider:model` (`_harness_profile_for_model`), never by subagent name, so a profile-level change is global per provider
- `_ToolExclusionMiddleware` only filters `request.tools`; `FilesystemMiddleware.wrap_model_call` independently appends the file-system prose to `request.system_message` - they’re orthogonal.
- The `middleware` field on the declarative `SubAgent` is _appended_ to the hard-coded base stack, not a replacement

Swap the affected subagent from declarative `SubAgent` to `CompiledSubAgent`. In `graph.py`, the `if "runnable" in spec: inline_subagents.append(spec)` branch skips all base-stack injection, profile resolution, and permission inheritance - you get exactly the stack you build with `create_agent(...)`. Same model, no provider collision.

If the subagent still needs file tools but not the prompt, instantiate `FilesystemMiddleware(backend=..., system_prompt="")`. The `wrap_model_call` short-circuits on a falsy `system_prompt`, so the tools are still injected but the prose is suppressed.

---

<div class="post-metadata">

**Author:** ![bassuniz](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/bassuniz/32/2718_2.png) [@bassuniz](https://forum.langchain.com/u/bassuniz)\
**Post date:** [May 7, 2026, 12:27pm UTC](https://forum.langchain.com/t/filesystem-middleware/3672/3 "2026-05-07T12:27:54Z")

</div>

Great thanks for the reply
