create_summarization_middleware(
model: BaseChatModelCreate 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 |
Resolved BaseChatModel instance.
Use resolve_model() first if needed for model strings.
Backend instance or factory for persisting conversation history.