TomTom Maps for JavaScript
    Preparing search index...

    Variable compactMessagesConst

    compactMessages: (
        options: CompactMessagesOptions,
    ) => Promise<CompactMessagesResult>

    Folds the older turns of a conversation into a running summary, with one model call.

    Type Declaration

    Call it every few turns from an agent whose history grows without bound, such as one woken by events. It merges the previous summary and every turn but the latest keepTurns into a new summary. Send that summary in the system prompt or the next user message, with the kept messages after it.

    It cuts only where a user message starts a turn, so tool calls keep their results. With no more than keepTurns turns, it makes no call and returns the previous summary and every message.

    An Error when the model replies with no text, such as after a content filter stopped it, so you keep your summary and messages as they were. A RangeError when keepTurns is not a whole number, 0 or more.

    The AI SDK's pruneMessages, which removes reasoning, tool calls and tool results from older messages with no model call, for when you need no summary of them.

    const compacted = await compactMessages({ model, messages: history, summary, keepTurns: 2 });
    summary = compacted.summary;
    history = compacted.messages;