deepagents icon indicating copy to clipboard operation
deepagents copied to clipboard

Config for middleware parameters

Open dmitrykruglov opened this issue 2 months ago • 4 comments

It'd be great to have a more flexible way to configure default middlewares.

For example, SummarizationMiddleware currently has hardcoded parameters max_tokens_before_summary=170000, messages_to_keep=6 and uses same model as the main agent. But use cases vary: some need cheaper models for summarization, different token thresholds, or more/fewer messages retained.

Related: #263

dmitrykruglov avatar Nov 06 '25 22:11 dmitrykruglov

+1. Please allow us to modify the parameters for default middlewares like SummarizationMiddleware.

arthurmf avatar Nov 07 '25 14:11 arthurmf

+1 - this is actually one of the limiting factors for adopting this framework. In production settings, modifying these default middleware parameters could help us balance cost/inference time with response quality in a more systematic way

mike-quan-ff avatar Nov 07 '25 15:11 mike-quan-ff

Here is a related PR https://github.com/langchain-ai/deepagents/pull/355/files , btw isn't override summarization middleware an option ?

jorgearturonh avatar Nov 13 '25 01:11 jorgearturonh

I would be very good to have the opportunity to ovverride SummarizationMiddleware settings, or maybe to create your own Instance.

We habe many cases where especially this middleware produces .. nonsense.

Sample:

[updates] {'SummarizationMiddleware.before_model': None} [updates] {'model': {'messages': [AIMessage(content='\blindtext\fbox\fbox', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 14, 'prompt_tokens': 7427, 'total_tokens': 7441, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_provider': 'openai', 'model_name': 'Venice', 'system_fingerprint': 'b6886-dcca0d3ab', 'id': 'chatcmpl-h3d8T2WY9yiIziJNndzIU332AqsVsNrT', 'finish_reason': 'stop', 'logprobs': None}, id='lc_run--c790b38e-7294-4e9a-9cb1-a326198d40d2-0', usage_metadata={'input_tokens': 7427, 'output_tokens': 14, 'total_tokens': 7441, 'input_token_details': {}, 'output_token_details': {}})]}}

"\blindtest\box\fbox" ???

hoschidude avatar Nov 17 '25 10:11 hoschidude

Ran into the same issue. Since create_deep_agent() is just a super thin wrapper around langchain.agents.create_agent(), I ended up rolling my own function.

RussellLuo avatar Dec 19 '25 13:12 RussellLuo

We ran into this exact issue in production. Since there's no way to customize SummarizationMiddleware parameters, we ended up building our own middleware with the following features:

  • Configurable thresholds per attribute (not just 170k tokens hardcoded)
  • Configurable messages_to_keep (not hardcoded 20)
  • Support for multiple state attributes (messages, tool_executions (custom field state), etc.)
  • S3 archival to preserve full history (native middleware deletes summarized content)
  • Ability to use a different/cheaper model for summarization

Our solution:

AttributeConfig(
    attribute_name="messages",
    threshold=15,              # Custom threshold
    messages_to_keep=6,        # Custom retention
    count_method="length",     # or "tokens"
    generate_summary=True,
)

middleware = CustomSummarizationMiddleware(
    model="gpt-4o-mini",  # Separate model for summarization
    attribute_configs=[...],
)

Would be great to have configurable parameters in the native middleware. Even just exposing max_tokens_before_summary, messages_to_keep, and model in the constructor would cover most use cases.

arthurmf avatar Dec 19 '25 14:12 arthurmf