Create a SummarizationToolMiddleware with model-aware defaults.
Convenience factory that creates a SummarizationMiddleware via
create_summarization_middleware and wraps it in a
SummarizationToolMiddleware.
create_summarization_tool_middleware(
model: str | BaseChatModel,
backend: BACKEND_TYPES
) -> SummarizationToolMiddlewareExample:
Using the default StateBackend:
from deepagents import create_deep_agent
from deepagents.backends import StateBackend
from deepagents.middleware.summarization import (
create_summarization_tool_middleware,
)
model = "openai:gpt-5.4"
agent = create_deep_agent(
model=model,
middleware=[
create_summarization_tool_middleware(model, StateBackend),
],
)
Using a custom backend instance (e.g., Daytona Sandbox):
from daytona import Daytona
from deepagents import create_deep_agent
from deepagents.middleware.summarization import (
create_summarization_tool_middleware,
)
from langchain_daytona import DaytonaSandbox
sandbox = Daytona().create()
backend = DaytonaSandbox(sandbox=sandbox)
model = "openai:gpt-5.4"
agent = create_deep_agent(
model=model,
backend=backend,
middleware=[
create_summarization_tool_middleware(model, backend),
],
)| Name | Type | Description |
|---|---|---|
model* | str | BaseChatModel | Chat model instance or model string (e.g., |
backend* | BACKEND_TYPES | Backend instance or factory for persisting conversation history. |