Strategy for clearing tool outputs when token limits are exceeded.
This strategy mirrors Anthropic's clear_tool_uses_20250919 behavior by
replacing older tool results with a placeholder text when the conversation
grows too large. It preserves the most recent tool results and can exclude
specific tools from being cleared.
Example
import { ClearToolUsesEdit } from"langchain";
constedit = newClearToolUsesEdit({ triggerTokens:100000, // Start clearing at 100K tokens clearAtLeast:0, // Clear as much as needed keep:3, // Always keep 3 most recent results excludeTools: ["important"], // Never clear "important" tool clearToolInputs:false, // Keep tool call arguments placeholder:"[cleared]", // Replacement text });
Strategy for clearing tool outputs when token limits are exceeded.
This strategy mirrors Anthropic's
clear_tool_uses_20250919behavior by replacing older tool results with a placeholder text when the conversation grows too large. It preserves the most recent tool results and can exclude specific tools from being cleared.Example