import type { BaseMessage } from '@langchain/core/messages'; /** * Deduplicates consecutive identical system messages in the context window. * * Problem: In long tool-use chains, the same system messages (e.g., post-prune notes, * conversation summaries) can accumulate when the context is rebuilt on each iteration. * These duplicates waste tokens without adding information. * * Strategy: Only deduplicate system messages that appear consecutively or are exact * duplicates of an earlier system message. The FIRST occurrence is always kept. * Non-system messages (human, ai, tool) are never touched. * * Important constraints: * - The first system message (index 0) is ALWAYS preserved (it's the main system prompt) * - Only system messages are candidates for deduplication * - Messages with content longer than DEDUP_MAX_CONTENT_LENGTH are skipped (too expensive to compare) * - Content comparison is by string equality (fast and deterministic) * * @param messages - The message array to deduplicate (not mutated) * @returns A new array with duplicate system messages removed, and the count of removed messages */ export declare function deduplicateSystemMessages(messages: BaseMessage[]): { messages: BaseMessage[]; removedCount: number; };