Skip to content

create_deep_agent: Allow customizing built-in middleware settings (e.g. FilesystemMiddleware.tool_token_limit_before_evict) #2784

Description

Submission checklist

  • This is a feature request, not a bug report.
  • I searched existing issues and didn't find this feature.
  • I checked the docs and README for existing functionality.
  • This request applies to this repo (deepagents) and not an external package.

Area (Required)

  • deepagents (SDK)
  • cli
  • acp
  • evals
  • harbor
  • repl
  • daytona
  • modal
  • quickjs
  • runloop
  • langsmith-sandbox
  • Other / not sure / general

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    deepagentsRelated to the `deepagents` SDK / agent harnessexternalUser is not a member of the `langchain-ai` GitHub organization

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions