Submission checklist
Area (Required)
Feature description
Problem
create_deep_agent() internally constructs FilesystemMiddleware(backend=backend) with the default tool_token_limit_before_evict=20000. There's no way for consumers to change this without:
- Monkey-patching the class
- Swapping module namespace references
- Bypassing
create_deep_agent entirely and using create_agent directly (losing automatic middleware parity on upgrades)
The same problem applies to any parameter on any built-in middleware — the defaults are hardcoded in graph.py (3 separate FilesystemMiddleware(backend=backend) instantiations for main agent, general-purpose subagent, and user subagents).
Use case
When building agents that use tools returning large results (e.g. database queries, API responses), the default 20K token eviction threshold (~80K chars) is too high. Lowering it to 5K tokens keeps context lean and reduces token costs significantly. Currently the only options are hacky workarounds that couple to internal module structure.
Proposed solution (optional)
Proposed solution
A middleware_config dict that lets consumers override parameters on built-in middleware without replacing the entire stack:
graph = create_deep_agent(
model=model,
tools=tools,
system_prompt="...",
middleware_config={
"FilesystemMiddleware": {"tool_token_limit_before_evict": 5000},
"SummarizationMiddleware": {"trigger": ("tokens", 100000)},
},
)
Merge semantics — only specified keys override; everything else keeps its default. Similar to Pydantic's model_config pattern.
Additionally, False could disable a middleware entirely:
middleware_config={
"TodoListMiddleware": False, # disable
}
Submission checklist
Area (Required)
Feature description
Problem
create_deep_agent()internally constructsFilesystemMiddleware(backend=backend)with the defaulttool_token_limit_before_evict=20000. There's no way for consumers to change this without:create_deep_agententirely and usingcreate_agentdirectly (losing automatic middleware parity on upgrades)The same problem applies to any parameter on any built-in middleware — the defaults are hardcoded in
graph.py(3 separateFilesystemMiddleware(backend=backend)instantiations for main agent, general-purpose subagent, and user subagents).Use case
When building agents that use tools returning large results (e.g. database queries, API responses), the default 20K token eviction threshold (~80K chars) is too high. Lowering it to 5K tokens keeps context lean and reduces token costs significantly. Currently the only options are hacky workarounds that couple to internal module structure.
Proposed solution (optional)
Proposed solution
A
middleware_configdict that lets consumers override parameters on built-in middleware without replacing the entire stack:Merge semantics — only specified keys override; everything else keeps its default. Similar to Pydantic's model_config pattern.
Additionally, False could disable a middleware entirely: