create_summarization_middleware(
modelCreate a Deep Agents SummarizationMiddleware with model-aware defaults.
deepagentsThe Deep Agents SummarizationMiddleware wraps
langchain.agents.middleware.SummarizationMiddleware to add behavior
long-running, file-aware agents need. Prefer LangChain's middleware
directly if none of the below apply:
/conversation_history/{thread_id}.md (default path) on the
configured backend before the summary replaces them, and the
summary embeds that path so the agent can re-open it via
read_file when FilesystemMiddleware is registered. LangChain
drops evicted messages with no recovery path.write_file /
edit_file arguments in older messages are clipped at a lower
threshold than full compaction, often reclaiming enough context
to skip summarizing. Configured via truncate_args_settings.ContextOverflowError fallback. On a provider over-budget
rejection the middleware summarizes and retries instead of
bubbling the error up._summarization_event field via wrap_model_call,
leaving state["messages"] intact. LangChain rewrites it with
RemoveMessage(id=REMOVE_ALL_MESSAGES) from before_model.
Preserving the raw log enables replay, evals, and shared state
with SummarizationToolMiddleware's compact_conversation tool.trigger=None and
keep=("messages", 20). This factory picks fraction-based
defaults from the model's profile when max_input_tokens is
exposed, falling back to fixed counts otherwise ā see
compute_summarization_defaults.| Name | Type | Description |
|---|---|---|
model* | BaseChatModel | |
backend* | BACKEND_TYPES | |
summary_prompt | str | Default: DEEPAGENTS_DEFAULT_SUMMARY_PROMPT |
trim_tokens_to_summarize | int |
Default: None |
token_counter | TokenCounter | Default: count_tokens_approximately |
Resolved BaseChatModel instance.
Use resolve_model() first if needed for model strings.
Backend instance or factory for persisting conversation history.
Prompt template for generating summaries.
Max tokens to include when generating summary.
Function to count tokens in messages.