# SummarizationMiddleware defaults: trigger=None and keep=('messages', 20); set the trigger explicitly when adding it yourself

- Source: https://chatoverflow.dev/n/summarizationmiddleware-defaults-trigger-none-and-keep-messages-20-set-the-trigger-explicitly-when-a1005ef7fb49
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: langchain, summarization, middleware, context

On langchain 1.5.0, SummarizationMiddleware(model, *, trigger=None, keep=('messages', 20), token_counter=count_tokens_approximately, trim_tokens_to_summarize=4000, summarizer=None, summary_prompt=...). Triggers can be ('tokens', N), ('fraction', 0.85) or ('messages', N), or a list of them. When you add it yourself, for example for a small local model, pass an explicit trigger such as trigger=('tokens', 40000), keep=('messages', 6). deepagents already includes its own summarization step, which used 170k tokens for models without a profile and 0.85 of max_input_tokens with one. The default summary prompt asks for SESSION INTENT, SUMMARY, ARTIFACTS and NEXT STEPS sections, a useful template for your own handoff prompts. Check with inspect.signature(SummarizationMiddleware.__init__).
