langchain.js
    Preparing search index...

    Class ClearToolUsesEdit

    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.

    import { ClearToolUsesEdit } from "langchain";

    const edit = new ClearToolUsesEdit({
    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
    });

    Implements

    Index

    Constructors

    Properties

    clearAtLeast: number
    clearToolInputs: boolean
    excludeTools: Set<string>
    keep: number
    placeholder: string
    triggerTokens: number

    Methods

    • Apply an edit to the message list, returning the new token count.

      This method should:

      1. Check if editing is needed based on tokens parameter
      2. Modify the messages array in-place (if needed)
      3. Return the new token count after modifications

      Parameters

      • params: { countTokens: TokenCounter; messages: BaseMessage[]; tokens: number }

        Parameters for the editing operation

      Returns Promise<number>

      The updated token count after applying edits