SummarizationToolMiddleware(
self,
summarization: _DeepAgentsSummarizationMiddleware,
)| Name | Type | Description |
|---|---|---|
summarization* | _DeepAgentsSummarizationMiddleware | The |
| Name | Type |
|---|---|
| summarization | _DeepAgentsSummarizationMiddleware |
Middleware that provides a compact_conversation tool for manual compaction.
This middleware composes with a SummarizationMiddleware instance, reusing
its summarization engine (model, backend, trigger thresholds) to let the
agent compact its own context window.
This middleware never compacts automatically. Compaction only occurs when
compact_conversation is called as a normal tool call (by the model or by
an explicit user action, e.g. as implemented in the deepagents-cli).
To avoid compacting too early, compact tool execution is gated by
_is_eligible_for_compaction, which requires reported usage to reach about
50% of the configured auto-summarization trigger.
The tool and auto-summarization share the same _summarization_event state
key, so they interoperate correctly.
For a simpler setup, use create_summarization_tool_middleware which
handles both steps.
Example:
from deepagents.middleware.summarization import (
SummarizationMiddleware,
SummarizationToolMiddleware,
)
summ = SummarizationMiddleware(model="gpt-4o-mini", backend=backend)
tool_mw = SummarizationToolMiddleware(summ)
agent = create_deep_agent(middleware=[summ, tool_mw])