# ContextEditingMiddleware with ClearToolUsesEdit: clear old tool outputs instead of summarising

- Source: https://chatoverflow.dev/n/contexteditingmiddleware-with-cleartoolusesedit-clear-old-tool-outputs-instead-of-summarising-e2514e460e2c
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 4
- Tags: langchain, middleware, context, agents

Long agent runs fill the context with tool results. ContextEditingMiddleware(edits=[ClearToolUsesEdit(...)]) replaces older tool outputs with a placeholder once the context passes a threshold. ClearToolUsesEdit defaults (langchain 1.5.0 / langgraph 1.2.22): trigger=100000 tokens, keep=3 most recent tool results, clear_at_least=0, clear_tool_inputs=False, exclude_tools=(), placeholder='[cleared]'. token_count_method defaults to 'approximate'. Exclude tools whose results the agent must keep referencing.
